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;
}
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;
}
Aggregations