Search in sources :

Example 1 with IToolWrench

use of buildcraft.api.tools.IToolWrench in project BuildCraft by BuildCraft.

the class BlockQuarry method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityplayer, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (super.onBlockActivated(world, pos, state, entityplayer, facing, hitX, hitY, hitZ)) {
        return true;
    }
    TileQuarry tile = (TileQuarry) world.getTileEntity(pos);
    // Drop through if the player is sneaking
    if (entityplayer.isSneaking()) {
        return false;
    }
    // Restart the quarry if its a wrench
    Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
    if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, pos)) {
        tile.reinitalize();
        ((IToolWrench) equipped).wrenchUsed(entityplayer, pos);
        return true;
    }
    return false;
}
Also used : Item(net.minecraft.item.Item) IToolWrench(buildcraft.api.tools.IToolWrench)

Example 2 with IToolWrench

use of buildcraft.api.tools.IToolWrench in project BuildCraft by BuildCraft.

the class BlockPump method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityplayer, EnumFacing face, float par7, float par8, float par9) {
    if (super.onBlockActivated(world, pos, state, entityplayer, face, par7, par8, par9)) {
        return true;
    }
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof TilePump) {
        TilePump pump = (TilePump) tile;
        // Drop through if the player is sneaking
        if (entityplayer.isSneaking()) {
            return false;
        }
        // Restart the pump if its a wrench
        Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
        if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, pos)) {
            pump.tank.reset();
            pump.rebuildQueue();
            ((IToolWrench) equipped).wrenchUsed(entityplayer, pos);
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) IToolWrench(buildcraft.api.tools.IToolWrench)

Example 3 with IToolWrench

use of buildcraft.api.tools.IToolWrench in project BuildCraft by BuildCraft.

the class BlockFloodGate method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = player.getHeldItem(hand);
    if (heldItem.getItem() instanceof IToolWrench) {
        if (!world.isRemote) {
            if (side != EnumFacing.UP) {
                TileEntity tile = world.getTileEntity(pos);
                if (tile instanceof TileFloodGate) {
                    if (CONNECTED_MAP.containsKey(side)) {
                        TileFloodGate floodGate = (TileFloodGate) tile;
                        if (!floodGate.openSides.remove(side)) {
                            floodGate.openSides.add(side);
                        }
                        floodGate.queue.clear();
                        floodGate.sendNetworkUpdate(TileBC_Neptune.NET_RENDER_DATA);
                        return true;
                    }
                }
            }
        }
        return false;
    }
    return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IToolWrench(buildcraft.api.tools.IToolWrench) ItemStack(net.minecraft.item.ItemStack) TileFloodGate(buildcraft.factory.tile.TileFloodGate)

Example 4 with IToolWrench

use of buildcraft.api.tools.IToolWrench in project BuildCraft by BuildCraft.

the class EntityUtil method activateWrench.

public static void activateWrench(EntityPlayer player) {
    ItemStack stack = player.getHeldItemMainhand();
    if (!stack.isEmpty() && stack.getItem() instanceof IToolWrench) {
        IToolWrench wrench = (IToolWrench) stack.getItem();
        wrench.wrenchUsed(player, EnumHand.MAIN_HAND, stack, null);
        return;
    }
    stack = player.getHeldItemOffhand();
    if (!stack.isEmpty() && stack.getItem() instanceof IToolWrench) {
        IToolWrench wrench = (IToolWrench) stack.getItem();
        wrench.wrenchUsed(player, EnumHand.OFF_HAND, stack, null);
    }
}
Also used : IToolWrench(buildcraft.api.tools.IToolWrench) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IToolWrench

use of buildcraft.api.tools.IToolWrench in project BuildCraft by BuildCraft.

the class EntityRobot method interact.

@Override
protected boolean interact(EntityPlayer player) {
    ItemStack stack = player.getCurrentEquippedItem();
    if (stack == null || stack.getItem() == null) {
        return false;
    }
    RobotEvent.Interact robotInteractEvent = new RobotEvent.Interact(this, player, stack);
    MinecraftForge.EVENT_BUS.post(robotInteractEvent);
    if (robotInteractEvent.isCanceled()) {
        return false;
    }
    if (player.isSneaking() && stack.getItem() instanceof IToolWrench) {
        RobotEvent.Dismantle robotDismantleEvent = new RobotEvent.Dismantle(this, player);
        MinecraftForge.EVENT_BUS.post(robotDismantleEvent);
        if (robotDismantleEvent.isCanceled()) {
            return false;
        }
        onRobotHit(false);
        if (worldObj.isRemote) {
            ((IToolWrench) stack.getItem()).wrenchUsed(player, this);
        }
        return true;
    } else if (wearables.size() < MAX_WEARABLES && stack.getItem().isValidArmor(stack, 0, this)) {
        if (!worldObj.isRemote) {
            wearables.add(stack.splitStack(1));
            syncWearablesToClient();
        } else {
            player.swingItem();
        }
        return true;
    } else if (wearables.size() < MAX_WEARABLES && stack.getItem() instanceof IRobotOverlayItem && ((IRobotOverlayItem) stack.getItem()).isValidRobotOverlay(stack)) {
        if (!worldObj.isRemote) {
            wearables.add(stack.splitStack(1));
            syncWearablesToClient();
        } else {
            player.swingItem();
        }
        return true;
    } else if (wearables.size() < MAX_WEARABLES && stack.getItem() instanceof ItemSkull) {
        if (!worldObj.isRemote) {
            ItemStack skullStack = stack.splitStack(1);
            initSkullItem(skullStack);
            wearables.add(skullStack);
            syncWearablesToClient();
        } else {
            player.swingItem();
        }
        return true;
    } else {
        return super.interact(player);
    }
}
Also used : IToolWrench(buildcraft.api.tools.IToolWrench) IRobotOverlayItem(buildcraft.api.robots.IRobotOverlayItem) ItemStack(net.minecraft.item.ItemStack) RobotEvent(buildcraft.api.events.RobotEvent) ItemSkull(net.minecraft.item.ItemSkull)

Aggregations

IToolWrench (buildcraft.api.tools.IToolWrench)15 Item (net.minecraft.item.Item)8 ItemStack (net.minecraft.item.ItemStack)7 TileEntity (net.minecraft.tileentity.TileEntity)4 RobotEvent (buildcraft.api.events.RobotEvent)1 IMapLocation (buildcraft.api.items.IMapLocation)1 IRobotOverlayItem (buildcraft.api.robots.IRobotOverlayItem)1 IPipePluggableItem (buildcraft.api.transport.pluggable.IPipePluggableItem)1 TileFloodGate (buildcraft.factory.tile.TileFloodGate)1 GatePluggable (buildcraft.transport.gates.GatePluggable)1 PipeEventItem (buildcraft.transport.pipes.events.PipeEventItem)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 ItemSkull (net.minecraft.item.ItemSkull)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1 EnumFacing (net.minecraft.util.EnumFacing)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1