/** * ブロックを破壊します * * @param world world * @param x x座標 * @param y y座標 * @param z z座標 * @param player プレイヤー * @param centerBlock 中心のブロック * @param cX 中心のブロックのx座標 * @param cY 中心のブロックのy座標 * @param cZ 中心のブロックのz座標 * @param toolStack 破壊に使用したツールのItemStack */ private void blockDestroy(World world, int x, int y, int z, EntityPlayerMP player, Block centerBlock, int cX, int cY, int cZ, ItemStack toolStack) { if (!world.isAirBlock(x, y, z)) { Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); if (canDestroyBlock(toolStack, block, meta) && (centerBlock.getBlockHardness(world, cX, cY, cZ) - block.getBlockHardness(world, x, y, z)) <= 3F) { BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x, y, z); if (!event.isCanceled()) { block.onBlockHarvested(world, x, y, z, meta, player); if (block.removedByPlayer(world, player, x, y, z, false)) { block.onBlockDestroyedByPlayer(world, x, y, z, meta); block.harvestBlock(world, player, x, y, z, meta); } if (!world.isRemote) { player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); } } } } }
public void send(BlockPos center, EntityPlayerMP player, ForgeDirection face) { World world = MinecraftServer.getServer().worldServerForDimension(center.getDim()); int x, y, z; Volume updateVolume = relativeCoords.translate(face); for (int i = updateVolume.getMinX(); i <= updateVolume.getMaxX(); i++) { for (int j = updateVolume.getMinY(); j <= updateVolume.getMaxY(); j++) { for (int k = updateVolume.getMinZ(); k <= updateVolume.getMaxZ(); k++) { x = center.getX() + i; y = center.getY() + j; z = center.getZ() + k; S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world); FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().sendPacketToAllPlayers(packet); } } } }
@Override public void sendBlockChange(Location loc, int material, byte data) { if (getHandle().playerNetServerHandler == null) return; S23PacketBlockChange packet = new S23PacketBlockChange(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), ((CraftWorld) loc.getWorld()).getHandle()); packet.field_148883_d = CraftMagicNumbers.getBlock(material); packet.field_148884_e = data; getHandle().playerNetServerHandler.sendPacket(packet); }
/** * Processes block placement and block activation (anvil, furnace, etc.) */ public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer()); WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); ItemStack itemstack = this.playerEntity.inventory.getCurrentItem(); boolean flag = false; BlockPos blockpos = packetIn.getPosition(); EnumFacing enumfacing = EnumFacing.getFront(packetIn.getPlacedBlockDirection()); this.playerEntity.markPlayerActive(); if (packetIn.getPlacedBlockDirection() == 255) { if (itemstack == null) { return; } this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack); } else if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit()) { if (this.hasMoved && this.playerEntity.getDistanceSq((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D) < 64.0D && !this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos)) { this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, worldserver, itemstack, blockpos, enumfacing, packetIn.getPlacedBlockOffsetX(), packetIn.getPlacedBlockOffsetY(), packetIn.getPlacedBlockOffsetZ()); } flag = true; } else { ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())}); chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED); this.playerEntity.playerNetServerHandler.sendPacket(new S02PacketChat(chatcomponenttranslation)); flag = true; } if (flag) { this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos)); this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos.offset(enumfacing))); } itemstack = this.playerEntity.inventory.getCurrentItem(); if (itemstack != null && itemstack.stackSize == 0) { this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null; itemstack = null; } if (itemstack == null || itemstack.getMaxItemUseDuration() == 0) { this.playerEntity.isChangingQuantityOnly = true; this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]); Slot slot = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem); this.playerEntity.openContainer.detectAndSendChanges(); this.playerEntity.isChangingQuantityOnly = false; if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), packetIn.getStack())) { this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem())); } } }
public void onUpdate() { if (this.numBlocksToUpdate != 0) { if (this.numBlocksToUpdate == 1) { int i = (this.locationOfBlockChange[0] >> 12 & 15) + this.chunkCoords.chunkXPos * 16; int j = this.locationOfBlockChange[0] & 255; int k = (this.locationOfBlockChange[0] >> 8 & 15) + this.chunkCoords.chunkZPos * 16; BlockPos blockpos = new BlockPos(i, j, k); this.sendToAllPlayersWatchingChunk(new S23PacketBlockChange(PlayerManager.this.theWorldServer, blockpos)); if (PlayerManager.this.theWorldServer.getBlockState(blockpos).getBlock().hasTileEntity()) { this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(blockpos)); } } else if (this.numBlocksToUpdate == 64) { int i1 = this.chunkCoords.chunkXPos * 16; int k1 = this.chunkCoords.chunkZPos * 16; this.sendToAllPlayersWatchingChunk(new S21PacketChunkData(PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkCoords.chunkXPos, this.chunkCoords.chunkZPos), false, this.flagsYAreasToUpdate)); for (int i2 = 0; i2 < 16; ++i2) { if ((this.flagsYAreasToUpdate & 1 << i2) != 0) { int k2 = i2 << 4; List<TileEntity> list = PlayerManager.this.theWorldServer.getTileEntitiesIn(i1, k2, k1, i1 + 16, k2 + 16, k1 + 16); for (int l = 0; l < list.size(); ++l) { this.sendTileToAllPlayersWatchingChunk((TileEntity)list.get(l)); } } } } else { this.sendToAllPlayersWatchingChunk(new S22PacketMultiBlockChange(this.numBlocksToUpdate, this.locationOfBlockChange, PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkCoords.chunkXPos, this.chunkCoords.chunkZPos))); for (int j1 = 0; j1 < this.numBlocksToUpdate; ++j1) { int l1 = (this.locationOfBlockChange[j1] >> 12 & 15) + this.chunkCoords.chunkXPos * 16; int j2 = this.locationOfBlockChange[j1] & 255; int l2 = (this.locationOfBlockChange[j1] >> 8 & 15) + this.chunkCoords.chunkZPos * 16; BlockPos blockpos1 = new BlockPos(l1, j2, l2); if (PlayerManager.this.theWorldServer.getBlockState(blockpos1).getBlock().hasTileEntity()) { this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(blockpos1)); } } } this.numBlocksToUpdate = 0; this.flagsYAreasToUpdate = 0; } }
/** * Attempts to harvest a block */ public boolean tryHarvestBlock(BlockPos pos) { if (this.gameType.isCreative() && this.thisPlayerMP.getHeldItem() != null && this.thisPlayerMP.getHeldItem().getItem() instanceof ItemSword) { return false; } else { IBlockState iblockstate = this.theWorld.getBlockState(pos); TileEntity tileentity = this.theWorld.getTileEntity(pos); if (this.gameType.isAdventure()) { if (this.gameType == WorldSettings.GameType.SPECTATOR) { return false; } if (!this.thisPlayerMP.isAllowEdit()) { ItemStack itemstack = this.thisPlayerMP.getCurrentEquippedItem(); if (itemstack == null) { return false; } if (!itemstack.canDestroy(iblockstate.getBlock())) { return false; } } } this.theWorld.playAuxSFXAtEntity(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate)); boolean flag1 = this.removeBlock(pos); if (this.isCreative()) { this.thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(this.theWorld, pos)); } else { ItemStack itemstack1 = this.thisPlayerMP.getCurrentEquippedItem(); boolean flag = this.thisPlayerMP.canHarvestBlock(iblockstate.getBlock()); if (itemstack1 != null) { itemstack1.onBlockDestroyed(this.theWorld, iblockstate.getBlock(), pos, this.thisPlayerMP); if (itemstack1.stackSize == 0) { this.thisPlayerMP.destroyCurrentEquippedItem(); } } if (flag1 && flag) { iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity); } } return flag1; } }
/** * Updates the block and metadata and generates a blockupdate (and notify the clients) */ public void handleBlockChange(S23PacketBlockChange packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); this.clientWorldController.invalidateRegionAndSetBlock(packetIn.getBlockPosition(), packetIn.getBlockState()); }
/** * Updates the block and metadata and generates a blockupdate (and notify the * clients) */ public void handleBlockChange(S23PacketBlockChange packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); this.clientWorldController.invalidateRegionAndSetBlock(packetIn.getBlockPosition(), packetIn.getBlockState()); }
@SubscribeEvent public void attack(final PlayerInteractEvent event) { if (event.action != PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) { return; } final EntityPlayer player = event.entityPlayer; if (event.world == null || event.world.isRemote) { return; } if (player == null || !(player instanceof EntityPlayerMP)) { return; } final ItemStack heldItem = player.getHeldItem(); if (heldItem == null || heldItem.getItem() != this) { return; } if (heldItem.getItemDamage() == 32767) { heldItem.stackSize = 0; return; } final int i = player.inventory.currentItem; if (i >= 9 || i < 0) { return; } event.setCanceled(true); final ItemStack item = heldItem.copy(); heldItem.setItemDamage(32767); player.inventory.setInventorySlotContents(i, (ItemStack)null); final int x = event.x; final int y = event.y; final int z = event.z; final int side = event.face; try { final PlayerInteractEvent e = ForgeEventFactory.onPlayerInteract(player, PlayerInteractEvent.Action.LEFT_CLICK_BLOCK, x, y, z, side, player.worldObj); final boolean result = !e.isCanceled() && event.useBlock != Event.Result.DENY; if (result) { final Block block = event.world.getBlock(x, y, z); block.onBlockClicked(event.world, x, y, z, player); } } catch (Exception err) { for (int j = 0; j < player.inventory.getSizeInventory(); ++j) { final ItemStack stackInSlot = player.inventory.getStackInSlot(i); if (stackInSlot != null) { if (stackInSlot.getItem() == this) { if (stackInSlot.getItemDamage() == 32767) { player.inventory.setInventorySlotContents(j, (ItemStack)null); } } } } if (player.inventory.getStackInSlot(i) == null) { player.inventory.setInventorySlotContents(i, item); } else if (!player.inventory.addItemStackToInventory(item)) { player.dropPlayerItemWithRandomChoice(item, false); } throw Throwables.propagate((Throwable)err); } ((EntityPlayerMP)player).playerNetServerHandler.sendPacket((Packet)new S23PacketBlockChange(x, y, z, event.world)); final ItemStack newItem = player.inventory.getStackInSlot(i); player.inventory.setInventorySlotContents(i, item); if (newItem != null && !player.inventory.addItemStackToInventory(newItem.copy())) { player.dropPlayerItemWithRandomChoice(newItem.copy(), false); } ((EntityPlayerMP)player).mcServer.getConfigurationManager().syncPlayerInventory((EntityPlayerMP)player); }
public static BlockEvent.BreakEvent onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z) { // Logic from tryHarvestBlock for pre-canceling the event boolean preCancelEvent = false; if (gameType.func_82752_c() && !entityPlayer.func_82246_f(x, y, z)) { preCancelEvent = true; } else if (gameType.func_77145_d() && entityPlayer.func_70694_bm() != null && entityPlayer.func_70694_bm().func_77973_b() instanceof ItemSword) { preCancelEvent = true; } // Tell client the block is gone immediately then process events if (world.func_147438_o(x, y, z) == null) { S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world); packet.field_148883_d = Blocks.field_150350_a; packet.field_148884_e = 0; entityPlayer.field_71135_a.func_147359_a(packet); } // Post the block break event Block block = world.func_147439_a(x, y, z); int blockMetadata = world.func_72805_g(x, y, z); BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, blockMetadata, entityPlayer); event.setCanceled(preCancelEvent); MinecraftForge.EVENT_BUS.post(event); // Handle if the event is canceled if (event.isCanceled()) { // Let the client know the block still exists entityPlayer.field_71135_a.func_147359_a(new S23PacketBlockChange(x, y, z, world)); // Update any tile entity data for this block TileEntity tileentity = world.func_147438_o(x, y, z); if (tileentity != null) { Packet pkt = tileentity.func_145844_m(); if (pkt != null) { entityPlayer.field_71135_a.func_147359_a(pkt); } } } return event; }
private void breaking(ItemStack stack, BlockPos pos, EntityPlayerMP playermp) { World world = playermp.worldObj; IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if (!world.isRemote) { if (!world.isAirBlock(pos)) { block.onBlockHarvested(world, pos, state, playermp); if (block.removedByPlayer(world, pos, playermp, true)) { block.onBlockDestroyedByPlayer(world, pos, state); if (!playermp.capabilities.isCreativeMode) { block.harvestBlock(world, playermp, pos, state, world.getTileEntity(pos)); block.dropXpOnBlockBreak(world, pos, block.getExpDrop(world, pos, 0)); stack.damageItem(1, playermp); } } playermp.playerNetServerHandler.sendPacket(new S23PacketBlockChange(world, pos)); } } if (block instanceof BlockRedstoneOre || block instanceof BlockOre || blocks.contains(block)) { if (playermp.worldObj.getBlockState(pos.up()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.up()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.up()).getBlock())) { this.breaking(stack, pos.up(), playermp); } if (playermp.worldObj.getBlockState(pos.down()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.down()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.down()).getBlock())) { this.breaking(stack, pos.down(), playermp); } if (playermp.worldObj.getBlockState(pos.north()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.north()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.north()).getBlock())) { this.breaking(stack, pos.north(), playermp); } if (playermp.worldObj.getBlockState(pos.south()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.south()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.south()).getBlock())) { this.breaking(stack, pos.south(), playermp); } if (playermp.worldObj.getBlockState(pos.west()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.west()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.west()).getBlock())) { this.breaking(stack, pos.west(), playermp); } if (playermp.worldObj.getBlockState(pos.east()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.east()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.east()).getBlock())) { this.breaking(stack, pos.east(), playermp); } } }
public static BlockEvent.BreakEvent onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z) { // Logic from tryHarvestBlock for pre-canceling the event boolean preCancelEvent = false; if (gameType.isAdventure() && !entityPlayer.isCurrentToolAdventureModeExempt(x, y, z)) { preCancelEvent = true; } else if (gameType.isCreative() && entityPlayer.getHeldItem() != null && entityPlayer.getHeldItem().getItem() instanceof ItemSword) { preCancelEvent = true; } // Tell client the block is gone immediately then process events if (world.getTileEntity(x, y, z) == null) { S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world); packet.field_148883_d = Blocks.air; packet.field_148884_e = 0; entityPlayer.playerNetServerHandler.sendPacket(packet); } // Post the block break event Block block = world.getBlock(x, y, z); int blockMetadata = world.getBlockMetadata(x, y, z); BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, blockMetadata, entityPlayer); event.setCanceled(preCancelEvent); MinecraftForge.EVENT_BUS.post(event); // Handle if the event is canceled if (event.isCanceled()) { // Let the client know the block still exists entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); // Update any tile entity data for this block TileEntity tileentity = world.getTileEntity(x, y, z); if (tileentity != null) { Packet pkt = tileentity.getDescriptionPacket(); if (pkt != null) { entityPlayer.playerNetServerHandler.sendPacket(pkt); } } } return event; }
protected boolean harvestBlock(World world, int x, int y, int z, EntityPlayer player) { if (world.isAirBlock(x, y, z)) { return false; } EntityPlayerMP playerMP = null; if (player instanceof EntityPlayerMP) { playerMP = (EntityPlayerMP) player; } Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); if (!(toolClasses.contains(block.getHarvestTool(meta)) || canHarvestBlock(block, player.getCurrentEquippedItem()))) { return false; } if (!ForgeHooks.canHarvestBlock(block, player, meta)) { return false; } BreakEvent event = null; if (playerMP != null) { event = ForgeHooks.onBlockBreakEvent(world, playerMP.theItemInWorldManager.getGameType(), playerMP, x, y, z); if (event.isCanceled()) { return false; } } if (player.capabilities.isCreativeMode) { if (!world.isRemote) { block.onBlockHarvested(world, x, y, z, meta, player); } else { world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) | (meta << 12)); } if (block.removedByPlayer(world, player, x, y, z, false)) { block.onBlockDestroyedByPlayer(world, x, y, z, meta); } if (!world.isRemote) { playerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); } else { Minecraft.getMinecraft().getNetHandler() .addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit)); } return true; } world.playAuxSFXAtEntity(player, 2001, x, y, z, Block.getIdFromBlock(block) | (meta << 12)); if (!world.isRemote) { block.onBlockHarvested(world, x, y, z, meta, player); if (block.removedByPlayer(world, player, x, y, z, true)) { block.onBlockDestroyedByPlayer(world, x, y, z, meta); block.harvestBlock(world, player, x, y, z, meta); if (event != null) { block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop()); } } playerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); } else { if (block.removedByPlayer(world, player, x, y, z, true)) { block.onBlockDestroyedByPlayer(world, x, y, z, meta); } Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit)); } return true; }
public NeptuneBlockChangePacket(S23PacketBlockChange handle) { super(handle); }
@Override public S23PacketBlockChange getHandle() { return (S23PacketBlockChange) super.getHandle(); }
/** * Updates the block and metadata and generates a blockupdate (and notify the clients) */ public void handleBlockChange(S23PacketBlockChange p_147234_1_) { this.clientWorldController.func_147492_c(p_147234_1_.func_148879_d(), p_147234_1_.func_148878_e(), p_147234_1_.func_148877_f(), p_147234_1_.func_148880_c(), p_147234_1_.func_148881_g()); }
public void sendChunkUpdate() { if (this.numberOfTilesToUpdate != 0) { int var1; int var2; int var3; if (this.numberOfTilesToUpdate == 1) { var1 = this.chunkLocation.chunkXPos * 16 + (this.field_151254_d[0] >> 12 & 15); var2 = this.field_151254_d[0] & 255; var3 = this.chunkLocation.chunkZPos * 16 + (this.field_151254_d[0] >> 8 & 15); this.func_151251_a(new S23PacketBlockChange(var1, var2, var3, PlayerManager.this.theWorldServer)); if (PlayerManager.this.theWorldServer.getBlock(var1, var2, var3).hasTileEntity()) { this.func_151252_a(PlayerManager.this.theWorldServer.getTileEntity(var1, var2, var3)); } } else { int var4; if (this.numberOfTilesToUpdate == 64) { var1 = this.chunkLocation.chunkXPos * 16; var2 = this.chunkLocation.chunkZPos * 16; this.func_151251_a(new S21PacketChunkData(PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos), false, this.flagsYAreasToUpdate)); for (var3 = 0; var3 < 16; ++var3) { if ((this.flagsYAreasToUpdate & 1 << var3) != 0) { var4 = var3 << 4; List var5 = PlayerManager.this.theWorldServer.func_147486_a(var1, var4, var2, var1 + 16, var4 + 16, var2 + 16); for (int var6 = 0; var6 < var5.size(); ++var6) { this.func_151252_a((TileEntity)var5.get(var6)); } } } } else { this.func_151251_a(new S22PacketMultiBlockChange(this.numberOfTilesToUpdate, this.field_151254_d, PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos))); for (var1 = 0; var1 < this.numberOfTilesToUpdate; ++var1) { var2 = this.chunkLocation.chunkXPos * 16 + (this.field_151254_d[var1] >> 12 & 15); var3 = this.field_151254_d[var1] & 255; var4 = this.chunkLocation.chunkZPos * 16 + (this.field_151254_d[var1] >> 8 & 15); if (PlayerManager.this.theWorldServer.getBlock(var2, var3, var4).hasTileEntity()) { this.func_151252_a(PlayerManager.this.theWorldServer.getTileEntity(var2, var3, var4)); } } } } this.numberOfTilesToUpdate = 0; this.flagsYAreasToUpdate = 0; } }
/** * Attempts to harvest a block at the given coordinate */ public boolean tryHarvestBlock(int par1, int par2, int par3) { if (this.gameType.isAdventure() && !this.thisPlayerMP.isCurrentToolAdventureModeExempt(par1, par2, par3)) { return false; } else if (this.gameType.isCreative() && this.thisPlayerMP.getHeldItem() != null && this.thisPlayerMP.getHeldItem().getItem() instanceof ItemSword) { return false; } else { Block var4 = this.theWorld.getBlock(par1, par2, par3); int var5 = this.theWorld.getBlockMetadata(par1, par2, par3); this.theWorld.playAuxSFXAtEntity(this.thisPlayerMP, 2001, par1, par2, par3, Block.getIdFromBlock(var4) + (this.theWorld.getBlockMetadata(par1, par2, par3) << 12)); boolean var6 = this.removeBlock(par1, par2, par3); if (this.isCreative()) { this.thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(par1, par2, par3, this.theWorld)); } else { ItemStack var7 = this.thisPlayerMP.getCurrentEquippedItem(); boolean var8 = this.thisPlayerMP.canHarvestBlock(var4); if (var7 != null) { var7.func_150999_a(this.theWorld, var4, par1, par2, par3, this.thisPlayerMP); if (var7.stackSize == 0) { this.thisPlayerMP.destroyCurrentEquippedItem(); } } if (var6 && var8) { var4.harvestBlock(this.theWorld, this.thisPlayerMP, par1, par2, par3, var5); } } return var6; } }
public static BlockEvent.BreakEvent onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, int x, int y, int z) { // Cauldron - pre-cancel handled in BreakEvent /* // Logic from tryHarvestBlock for pre-canceling the event boolean preCancelEvent = false; if (gameType.isAdventure() && !entityPlayer.isCurrentToolAdventureModeExempt(x, y, z)) { preCancelEvent = true; } else if (gameType.isCreative() && entityPlayer.getHeldItem() != null && entityPlayer.getHeldItem().getItem() instanceof ItemSword) { preCancelEvent = true; } */ // Tell client the block is gone immediately then process events if (world.getTileEntity(x, y, z) == null && !(entityPlayer instanceof FakePlayer)) // Cauldron - don't send packets to fakeplayers { S23PacketBlockChange packet = new S23PacketBlockChange(x, y, z, world); packet.field_148883_d = Blocks.air; packet.field_148884_e = 0; entityPlayer.playerNetServerHandler.sendPacket(packet); } // Post the block break event Block block = world.getBlock(x, y, z); int blockMetadata = world.getBlockMetadata(x, y, z); BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, blockMetadata, entityPlayer); //event.setCanceled(preCancelEvent); // Cauldron MinecraftForge.EVENT_BUS.post(event); // Handle if the event is canceled if (event.isCanceled() && !(entityPlayer instanceof FakePlayer)) // Cauldron - don't send packets to fakeplayers { // Let the client know the block still exists entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); // Update any tile entity data for this block TileEntity tileentity = world.getTileEntity(x, y, z); if (tileentity != null) { Packet pkt = tileentity.getDescriptionPacket(); if (pkt != null) { entityPlayer.playerNetServerHandler.sendPacket(pkt); } } } return event; }
public void handleBlockChange(S23PacketBlockChange p_147234_1_) { this.clientWorldController.func_147492_c(p_147234_1_.func_148879_d(), p_147234_1_.func_148878_e(), p_147234_1_.func_148877_f(), p_147234_1_.func_148880_c(), p_147234_1_.func_148881_g()); }
@SuppressWarnings("unused") public void sendChunkUpdate() { if (this.numberOfTilesToUpdate != 0) { int i; int j; int k; if (this.numberOfTilesToUpdate == 1) { i = this.chunkLocation.chunkXPos * 16 + (this.locationOfBlockChange[0] >> 12 & 15); j = this.locationOfBlockChange[0] & 255; k = this.chunkLocation.chunkZPos * 16 + (this.locationOfBlockChange[0] >> 8 & 15); this.sendToAllPlayersWatchingChunk(new S23PacketBlockChange(i, j, k, PlayerManager.this.theWorldServer)); if (PlayerManager.this.theWorldServer.getBlock(i, j, k).hasTileEntity(PlayerManager.this.theWorldServer.getBlockMetadata(i, j, k))) { this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(i, j, k)); } } else { int l; if (this.numberOfTilesToUpdate == net.minecraftforge.common.ForgeModContainer.clumpingThreshold) { i = this.chunkLocation.chunkXPos * 16; j = this.chunkLocation.chunkZPos * 16; this.sendToAllPlayersWatchingChunk(new S21PacketChunkData(PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos), (this.flagsYAreasToUpdate == 0xFFFF), this.flagsYAreasToUpdate)); // CraftBukkit - send everything (including biome) if all sections flagged // Forge: Grabs ALL tile entities is costly on a modded server, only send needed ones for (k = 0; false && k < 16; ++k) { if ((this.flagsYAreasToUpdate & 1 << k) != 0) { l = k << 4; List list = PlayerManager.this.theWorldServer.func_147486_a(i, l, j, i + 16, l + 16, j + 16); for (int i1 = 0; i1 < list.size(); ++i1) { this.sendTileToAllPlayersWatchingChunk((TileEntity)list.get(i1)); } } } } else { this.sendToAllPlayersWatchingChunk(new S22PacketMultiBlockChange(this.numberOfTilesToUpdate, this.locationOfBlockChange, PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos))); } { //Forge: Send only the tile entities that are updated, Adding this brace lets us keep the indent and the patch small WorldServer world = PlayerManager.this.theWorldServer; for (i = 0; i < this.numberOfTilesToUpdate; ++i) { j = this.chunkLocation.chunkXPos * 16 + (this.locationOfBlockChange[i] >> 12 & 15); k = this.locationOfBlockChange[i] & 255; l = this.chunkLocation.chunkZPos * 16 + (this.locationOfBlockChange[i] >> 8 & 15); if (world.getBlock(j, k, l).hasTileEntity(world.getBlockMetadata(j, k, l))) { this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(j, k, l)); } } } } this.numberOfTilesToUpdate = 0; this.flagsYAreasToUpdate = 0; } }