Search in sources :

Example 1 with ITool

use of crazypants.enderio.api.tool.ITool in project EnderIO by SleepyTrousers.

the class ToolUtil method breakBlockWithTool.

public static boolean breakBlockWithTool(@Nonnull Block block, @Nonnull World world, @Nonnull BlockPos pos, @Nullable EnumFacing side, @Nonnull EntityPlayer entityPlayer, @Nonnull EnumHand hand, @Nonnull String permissionNode) {
    ItemStack heldItem = entityPlayer.getHeldItem(hand);
    ITool tool = ToolUtil.getToolFromStack(heldItem);
    if (tool != null && entityPlayer.isSneaking() && tool.canUse(hand, entityPlayer, pos)) {
        IBlockState bs = world.getBlockState(pos);
        if (!PermissionAPI.hasPermission(entityPlayer.getGameProfile(), permissionNode, new BlockPosContext(entityPlayer, pos, bs, side))) {
            entityPlayer.sendMessage(Lang.WRENCH_DENIED.toChatServer());
            return false;
        }
        BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, bs, entityPlayer);
        event.setExpToDrop(0);
        if (MinecraftForge.EVENT_BUS.post(event)) {
            return false;
        }
        if (block.removedByPlayer(bs, world, pos, entityPlayer, true)) {
            block.harvestBlock(world, entityPlayer, pos, world.getBlockState(pos), world.getTileEntity(pos), heldItem);
        }
        tool.used(hand, entityPlayer, pos);
        return true;
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPosContext(net.minecraftforge.server.permission.context.BlockPosContext) ItemStack(net.minecraft.item.ItemStack) ITool(crazypants.enderio.api.tool.ITool) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Example 2 with ITool

use of crazypants.enderio.api.tool.ITool in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method handleWrenchClick.

private boolean handleWrenchClick(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
    ITool tool = ToolUtil.getEquippedTool(player, hand);
    if (tool != null) {
        if (tool.canUse(hand, player, pos)) {
            if (!world.isRemote) {
                IBlockState bs = world.getBlockState(pos);
                if (!PermissionAPI.hasPermission(player.getGameProfile(), permissionNodeWrenching, new BlockPosContext(player, pos, bs, null))) {
                    player.sendMessage(new TextComponentString(EnderIO.lang.localize("wrench.permission.denied")));
                    return false;
                }
                BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, bs, player);
                event.setExpToDrop(0);
                if (MinecraftForge.EVENT_BUS.post(event)) {
                    return false;
                }
                removedByPlayer(bs, world, pos, player, true);
                tool.used(hand, player, pos);
            }
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPosContext(net.minecraftforge.server.permission.context.BlockPosContext) ITool(crazypants.enderio.api.tool.ITool) BlockEvent(net.minecraftforge.event.world.BlockEvent) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

ITool (crazypants.enderio.api.tool.ITool)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockEvent (net.minecraftforge.event.world.BlockEvent)2 BlockPosContext (net.minecraftforge.server.permission.context.BlockPosContext)2 ItemStack (net.minecraft.item.ItemStack)1 TextComponentString (net.minecraft.util.text.TextComponentString)1