Search in sources :

Example 1 with IPneumaticWrenchable

use of pneumaticCraft.api.block.IPneumaticWrenchable in project PneumaticCraft by MineMaarten.

the class EventHandlerPneumaticCraft method onPlayerClick.

@SubscribeEvent
public void onPlayerClick(PlayerInteractEvent event) {
    Block interactedBlock = event.world.getBlock(event.x, event.y, event.z);
    if (!event.entityPlayer.capabilities.isCreativeMode || !event.entityPlayer.canCommandSenderUseCommand(2, "securityStation")) {
        if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_AIR && event.world != null && !event.world.isRemote) {
            if (interactedBlock != Blockss.securityStation || event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
                ItemStack heldItem = event.entityPlayer.getCurrentEquippedItem();
                boolean tryingToPlaceSecurityStation = heldItem != null && heldItem.getItem() instanceof ItemBlock && ((ItemBlock) heldItem.getItem()).field_150939_a == Blockss.securityStation;
                int blockingStations = PneumaticCraftUtils.getProtectingSecurityStations(event.entity.worldObj, event.x, event.y, event.z, event.entityPlayer, true, tryingToPlaceSecurityStation);
                if (blockingStations > 0) {
                    event.setCanceled(true);
                    event.entityPlayer.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocalFormatted(tryingToPlaceSecurityStation ? "message.securityStation.stationPlacementPrevented" : "message.securityStation.accessPrevented", blockingStations)));
                }
            }
        }
    }
    /**
     * Due to some weird quirk that causes Block#onBlockActivated not getting called on the server when the player is sneaking, this is a workaround.
     */
    if (!event.isCanceled() && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && !event.world.isRemote) {
        if (event.entityPlayer.isSneaking() && (interactedBlock == Blockss.elevatorCaller || interactedBlock == Blockss.chargingStation)) {
            event.setCanceled(interactedBlock.onBlockActivated(event.world, event.x, event.y, event.z, event.entityPlayer, event.face, 0, 0, 0));
        } else if (event.entityPlayer.getCurrentEquippedItem() != null && ModInteractionUtilImplementation.getInstance().isModdedWrench(event.entityPlayer.getCurrentEquippedItem().getItem())) {
            if (interactedBlock instanceof IPneumaticWrenchable) {
                ((IPneumaticWrenchable) interactedBlock).rotateBlock(event.world, event.entityPlayer, event.x, event.y, event.z, ForgeDirection.getOrientation(event.face));
            }
        }
    }
    if (!event.isCanceled() && interactedBlock == Blocks.cobblestone) {
        AchievementHandler.checkFor9x9(event.entityPlayer, event.x, event.y, event.z);
    }
}
Also used : Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) IPneumaticWrenchable(pneumaticCraft.api.block.IPneumaticWrenchable) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) ChatComponentText(net.minecraft.util.ChatComponentText) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 2 with IPneumaticWrenchable

use of pneumaticCraft.api.block.IPneumaticWrenchable in project PneumaticCraft by MineMaarten.

the class ItemPneumaticWrench method onItemUseFirst.

/**
 * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
 * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
 */
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitVecX, float hitVecY, float hitVecZ) {
    if (!world.isRemote) {
        Block block = world.getBlock(x, y, z);
        IPneumaticWrenchable wrenchable = null;
        if (block instanceof IPneumaticWrenchable) {
            wrenchable = (IPneumaticWrenchable) block;
        } else {
            wrenchable = ModInteractionUtils.getInstance().getWrenchable(world.getTileEntity(x, y, z));
        }
        if (wrenchable != null && ((ItemPneumaticWrench) Itemss.pneumaticWrench).getPressure(stack) > 0) {
            if (wrenchable.rotateBlock(world, player, x, y, z, ForgeDirection.getOrientation(side))) {
                if (!player.capabilities.isCreativeMode)
                    ((ItemPneumaticWrench) Itemss.pneumaticWrench).addAir(stack, -PneumaticValues.USAGE_PNEUMATIC_WRENCH);
                NetworkHandler.sendToAllAround(new PacketPlaySound(Sounds.PNEUMATIC_WRENCH, x, y, z, 1.0F, 1.0F, false), world);
                return true;
            }
        } else if (block != null) {
            // rotating normal blocks doesn't cost energy.
            if (block.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side))) {
                NetworkHandler.sendToAllAround(new PacketPlaySound(Sounds.PNEUMATIC_WRENCH, x, y, z, 1.0F, 1.0F, false), world);
                return true;
            }
        }
        return false;
    } else {
        return false;
    }
}
Also used : PacketPlaySound(pneumaticCraft.common.network.PacketPlaySound) Block(net.minecraft.block.Block) IPneumaticWrenchable(pneumaticCraft.api.block.IPneumaticWrenchable)

Aggregations

Block (net.minecraft.block.Block)2 IPneumaticWrenchable (pneumaticCraft.api.block.IPneumaticWrenchable)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 ChatComponentText (net.minecraft.util.ChatComponentText)1 PacketPlaySound (pneumaticCraft.common.network.PacketPlaySound)1