private boolean onPlayerPlaceBlock( PlayerControllerMP controller, EntityPlayer player, ItemStack offhand, BlockPos pos, EnumFacing l, Vec3 hitVec) { final World worldObj = player.worldObj; if (!worldObj.getWorldBorder().contains(pos)) { return false; } float f = (float) hitVec.xCoord - (float) pos.getX(); float f1 = (float) hitVec.yCoord - (float) pos.getY(); float f2 = (float) hitVec.zCoord - (float) pos.getZ(); boolean flag = false; if (!controller.isSpectatorMode()) { if (offhand.getItem().onItemUseFirst(offhand, player, worldObj, pos, l, f, f1, f2)) { return true; } if (!player.isSneaking() || player.getCurrentEquippedItem() == null || player.getCurrentEquippedItem().getItem().doesSneakBypassUse(worldObj, pos, player)) { IBlockState b = worldObj.getBlockState(pos); if (!b.getBlock().isAir(worldObj, pos) && b.getBlock().onBlockActivated(worldObj, pos, b, player, l, f, f1, f2)) { flag = true; } } if (!flag && offhand.getItem() instanceof ItemBlock) { ItemBlock itemblock = (ItemBlock) offhand.getItem(); if (!itemblock.canPlaceBlockOnSide(worldObj, pos, l, player, offhand)) { return false; } } } Battlegear.packetHandler.sendPacketToServer( new OffhandPlaceBlockPacket(pos, l, offhand, f, f1, f2).generatePacket()); if (flag || controller.isSpectatorMode()) { return true; } else if (offhand == null) { return false; } else { if (controller.isInCreativeMode()) { int i1 = offhand.getMetadata(); int j1 = offhand.stackSize; boolean flag1 = offhand.onItemUse(player, worldObj, pos, l, f, f1, f2); offhand.setItemDamage(i1); offhand.stackSize = j1; return flag1; } else { if (!offhand.onItemUse(player, worldObj, pos, l, f, f1, f2)) { return false; } if (offhand.stackSize <= 0) { ForgeEventFactory.onPlayerDestroyItem(player, offhand); } return true; } } }
@SubscribeEvent public void renderExtraBlockBreak(RenderWorldLastEvent event) { PlayerControllerMP controllerMP = Minecraft.getMinecraft().playerController; EntityPlayer player = Minecraft.getMinecraft().thePlayer; World world = player.worldObj; // AOE preview if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof IAoeTool) { MovingObjectPosition mop = player.rayTrace(controllerMP.getBlockReachDistance(), event.partialTicks); if (mop != null) { ItemStack stack = player.getCurrentEquippedItem(); ImmutableList<BlockPos> extraBlocks = ((IAoeTool) stack.getItem()).getAOEBlocks(stack, world, player, mop.getBlockPos()); for (BlockPos pos : extraBlocks) { event.context.drawSelectionBox( player, new MovingObjectPosition(new Vec3(0, 0, 0), null, pos), 0, event.partialTicks); } } } // extra-blockbreak animation if (controllerMP.isHittingBlock) { if (controllerMP.currentItemHittingBlock != null && controllerMP.currentItemHittingBlock.getItem() instanceof IAoeTool && ((IAoeTool) controllerMP.currentItemHittingBlock.getItem()).isAoeHarvestTool()) { ItemStack stack = controllerMP.currentItemHittingBlock; BlockPos pos = controllerMP.currentBlock; drawBlockDamageTexture( Tessellator.getInstance(), Tessellator.getInstance().getWorldRenderer(), player, event.partialTicks, world, ((IAoeTool) stack.getItem()).getAOEBlocks(stack, world, player, pos)); } } }