private void removeBlock(BlockPos pos) { if(pos.getY() < 0 || pos.getY() >= 256)return; Chunk chunk = getChunk(pos); IBlockState oldState = chunk.getBlockState(pos); if (oldState.getBlock().hasTileEntity(oldState)) { serverWorld.setBlockToAir(pos); PlayerChunkMap playerChunkMap = serverWorld.getPlayerChunkMap(); if (playerChunkMap != null) { PlayerChunkMapEntry watcher = playerChunkMap.getEntry(pos.getX() >> 4, pos.getZ() >> 4); if (watcher != null) { watcher.sendPacket(new SPacketBlockChange(serverWorld, pos)); } } } ExtendedBlockStorage storage = getBlockStorage(pos); if(storage !=null){ storage.set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15, AIR); } setChunkModified(pos); }
public void processRightClickBlock(CPacketPlayerTryUseItemOnBlock packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld()); WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); EnumHand enumhand = packetIn.getHand(); ItemStack itemstack = this.playerEntity.getHeldItem(enumhand); BlockPos blockpos = packetIn.getPos(); EnumFacing enumfacing = packetIn.getDirection(); this.playerEntity.markPlayerActive(); if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit()) { if (this.targetPos == null && 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.interactionManager.processRightClickBlock(this.playerEntity, worldserver, itemstack, enumhand, blockpos, enumfacing, packetIn.getFacingX(), packetIn.getFacingY(), packetIn.getFacingZ()); } } else { TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())}); textcomponenttranslation.getStyle().setColor(TextFormatting.RED); this.playerEntity.connection.sendPacket(new SPacketChat(textcomponenttranslation, (byte)2)); } this.playerEntity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos)); this.playerEntity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos.offset(enumfacing))); }
public void processRightClickBlock(CPacketPlayerTryUseItemOnBlock packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld()); WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); EnumHand enumhand = packetIn.getHand(); ItemStack itemstack = this.playerEntity.getHeldItem(enumhand); BlockPos blockpos = packetIn.getPos(); EnumFacing enumfacing = packetIn.getDirection(); this.playerEntity.markPlayerActive(); if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit()) { double dist = playerEntity.interactionManager.getBlockReachDistance() + 3; dist *= dist; if (this.targetPos == null && this.playerEntity.getDistanceSq((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D) < dist && !this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos)) { this.playerEntity.interactionManager.processRightClickBlock(this.playerEntity, worldserver, itemstack, enumhand, blockpos, enumfacing, packetIn.getFacingX(), packetIn.getFacingY(), packetIn.getFacingZ()); } } else { TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())}); textcomponenttranslation.getStyle().setColor(TextFormatting.RED); this.playerEntity.connection.sendPacket(new SPacketChat(textcomponenttranslation)); } this.playerEntity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos)); this.playerEntity.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos.offset(enumfacing))); itemstack = this.playerEntity.getHeldItem(enumhand); if (itemstack != null && itemstack.stackSize == 0) { this.playerEntity.setHeldItem(enumhand, (ItemStack)null); net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.playerEntity, itemstack, enumhand); } }
@Override public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) { World world = player.getEntityWorld(); if (!world.isRemote && player instanceof EntityPlayerMP) { RayTraceResult rt = this.rayTrace(world, player, false); if (rt.typeOfHit == RayTraceResult.Type.BLOCK) { EnumFacing side = rt.sideHit; List<BlockPos> extraBlocks = getExtraBlocks(world, rt, player); for (BlockPos pos2 : extraBlocks) { IBlockState state = world.getBlockState(pos2); if (!world.isBlockLoaded(pos2) || !player.canPlayerEdit(pos2, side, itemstack) || !(state.getBlock().canHarvestBlock(world, pos2, player))) { continue; } if (player.capabilities.isCreativeMode) { state.getBlock().onBlockHarvested(world, pos2, state, player); if (state.getBlock().removedByPlayer(state, world, pos2, player, false)) { state.getBlock().onBlockDestroyedByPlayer(world, pos2, state); } } else { int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos2); state.getBlock().onBlockHarvested(world, pos2, state, player); this.onBlockDestroyed(itemstack, world, state, pos2, player); if (state.getBlock().removedByPlayer(state, world, pos2, player, true)) { state.getBlock().onBlockDestroyedByPlayer(world, pos2, state); state.getBlock().harvestBlock(world, player, pos2, state, world.getTileEntity(pos2), itemstack); state.getBlock().dropXpOnBlockBreak(world, pos2, xp); } } world.playEvent(2001, pos, Block.getStateId(state)); ((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos)); } } } return false; }
/** * Updates the block and metadata and generates a blockupdate (and notify the clients) */ public void handleBlockChange(SPacketBlockChange packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); this.clientWorldController.invalidateRegionAndSetBlock(packetIn.getBlockPosition(), packetIn.getBlockState()); }
/** * Destroys and tries to harvest a block with the currently active tool, except that instead of calling * onBlockDestroyed, it calls onBlockAuxDestroyed on the tool, preventing infinite loops. */ public static boolean auxHarvestBlock(World world, BlockPos pos, EntityPlayerMP player) { if (world.isRemote) return false; //Shouldn't even be possible if we have an EntityPlayerMP! GameType gameType = player.interactionManager.getGameType(); int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos); if (exp == -1) { return false; } else { IBlockState iblockstate = world.getBlockState(pos); if (iblockstate.getBlockHardness(world, pos)<0) return false; TileEntity tileentity = world.getTileEntity(pos); Block block = iblockstate.getBlock(); if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) { world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3); return false; } else { ItemStack stack = player.getHeldItemMainhand(); if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false; world.playEvent(player, 2001, pos, Block.getStateId(iblockstate)); boolean removed = false; if (gameType==GameType.CREATIVE) { removed = removeBlock(world, pos, player, false); player.connection.sendPacket(new SPacketBlockChange(world, pos)); } else { ItemStack itemstack1 = player.getHeldItemMainhand(); ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy(); boolean canHarvest = iblockstate.getBlock().canHarvestBlock(world, pos, player); if (!itemstack1.isEmpty()) { // itemstack1.onBlockDestroyed(world, iblockstate, pos, player); if (itemstack1.getItem() instanceof IAuxDestroyBlock) { ((IAuxDestroyBlock)itemstack1.getItem()).onBlockAuxDestroyed(world, iblockstate, pos, player); } } removed = removeBlock(world, pos, player, canHarvest); if (removed && canHarvest) { iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2); } } // Drop experience if (gameType!=GameType.CREATIVE && removed && exp > 0) { iblockstate.getBlock().dropXpOnBlockBreak(world, pos, exp); } return removed; } } }
public void update() { if (this.sentToPlayers && this.chunk != null) { if (this.changes != 0) { if (this.changes == 1) { int i = (this.changedBlocks[0] >> 12 & 15) + this.pos.chunkXPos * 16; int j = this.changedBlocks[0] & 255; int k = (this.changedBlocks[0] >> 8 & 15) + this.pos.chunkZPos * 16; BlockPos blockpos = new BlockPos(i, j, k); this.sendPacket(new SPacketBlockChange(this.playerChunkMap.getWorldServer(), blockpos)); if (this.playerChunkMap.getWorldServer().getBlockState(blockpos).getBlock().hasTileEntity()) { this.sendBlockEntity(this.playerChunkMap.getWorldServer().getTileEntity(blockpos)); } } else if (this.changes == 64) { this.sendPacket(new SPacketChunkData(this.chunk, this.changedSectionFilter)); } else { this.sendPacket(new SPacketMultiBlockChange(this.changes, this.changedBlocks, this.chunk)); for (int l = 0; l < this.changes; ++l) { int i1 = (this.changedBlocks[l] >> 12 & 15) + this.pos.chunkXPos * 16; int j1 = this.changedBlocks[l] & 255; int k1 = (this.changedBlocks[l] >> 8 & 15) + this.pos.chunkZPos * 16; BlockPos blockpos1 = new BlockPos(i1, j1, k1); if (this.playerChunkMap.getWorldServer().getBlockState(blockpos1).getBlock().hasTileEntity()) { this.sendBlockEntity(this.playerChunkMap.getWorldServer().getTileEntity(blockpos1)); } } } this.changes = 0; this.changedSectionFilter = 0; } } }
/** * Attempts to harvest a block */ public boolean tryHarvestBlock(BlockPos pos) { if (this.gameType.isCreative() && !this.thisPlayerMP.getHeldItemMainhand().func_190926_b() && this.thisPlayerMP.getHeldItemMainhand().getItem() instanceof ItemSword) { return false; } else { IBlockState iblockstate = this.theWorld.getBlockState(pos); TileEntity tileentity = this.theWorld.getTileEntity(pos); Block block = iblockstate.getBlock(); if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.thisPlayerMP.canUseCommandBlock()) { this.theWorld.notifyBlockUpdate(pos, iblockstate, iblockstate, 3); return false; } else { if (this.gameType.isAdventure()) { if (this.gameType == GameType.SPECTATOR) { return false; } if (!this.thisPlayerMP.isAllowEdit()) { ItemStack itemstack = this.thisPlayerMP.getHeldItemMainhand(); if (itemstack.func_190926_b()) { return false; } if (!itemstack.canDestroy(block)) { return false; } } } this.theWorld.playEvent(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate)); boolean flag1 = this.removeBlock(pos); if (this.isCreative()) { this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos)); } else { ItemStack itemstack1 = this.thisPlayerMP.getHeldItemMainhand(); ItemStack itemstack2 = itemstack1.func_190926_b() ? ItemStack.field_190927_a : itemstack1.copy(); boolean flag = this.thisPlayerMP.canHarvestBlock(iblockstate); if (!itemstack1.func_190926_b()) { itemstack1.onBlockDestroyed(this.theWorld, iblockstate, pos, this.thisPlayerMP); } if (flag1 && flag) { iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity, itemstack2); } } return flag1; } } }
public static int onBlockBreakEvent(World world, GameType gameType, EntityPlayerMP entityPlayer, BlockPos pos) { // Logic from tryHarvestBlock for pre-canceling the event boolean preCancelEvent = false; if (gameType.isCreative() && entityPlayer.getHeldItemMainhand() != null && entityPlayer.getHeldItemMainhand().getItem() instanceof ItemSword) preCancelEvent = true; if (gameType.isAdventure()) { if (gameType == GameType.SPECTATOR) preCancelEvent = true; if (!entityPlayer.isAllowEdit()) { ItemStack itemstack = entityPlayer.getHeldItemMainhand(); if (itemstack == null || !itemstack.canDestroy(world.getBlockState(pos).getBlock())) preCancelEvent = true; } } // Tell client the block is gone immediately then process events if (world.getTileEntity(pos) == null) { SPacketBlockChange packet = new SPacketBlockChange(world, pos); packet.blockState = Blocks.AIR.getDefaultState(); entityPlayer.connection.sendPacket(packet); } // Post the block break event IBlockState state = world.getBlockState(pos); BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, 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.connection.sendPacket(new SPacketBlockChange(world, pos)); // Update any tile entity data for this block TileEntity tileentity = world.getTileEntity(pos); if (tileentity != null) { Packet<?> pkt = tileentity.getUpdatePacket(); if (pkt != null) { entityPlayer.connection.sendPacket(pkt); } } } return event.isCanceled() ? -1 : event.getExpToDrop(); }
/** * Attempts to harvest a block */ public boolean tryHarvestBlock(BlockPos pos) { int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(theWorld, gameType, thisPlayerMP, pos); if (exp == -1) { return false; } else { IBlockState iblockstate = this.theWorld.getBlockState(pos); TileEntity tileentity = this.theWorld.getTileEntity(pos); Block block = iblockstate.getBlock(); if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.thisPlayerMP.canUseCommandBlock()) { this.theWorld.notifyBlockUpdate(pos, iblockstate, iblockstate, 3); return false; } else { ItemStack stack = thisPlayerMP.getHeldItemMainhand(); if (stack != null && stack.getItem().onBlockStartBreak(stack, pos, thisPlayerMP)) return false; this.theWorld.playEvent(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate)); boolean flag1 = false; if (this.isCreative()) { flag1 = this.removeBlock(pos); this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos)); } else { ItemStack itemstack1 = this.thisPlayerMP.getHeldItemMainhand(); ItemStack itemstack2 = itemstack1 == null ? null : itemstack1.copy(); boolean flag = iblockstate.getBlock().canHarvestBlock(theWorld, pos, thisPlayerMP); if (itemstack1 != null) { itemstack1.onBlockDestroyed(this.theWorld, iblockstate, pos, this.thisPlayerMP); if (itemstack1.stackSize <= 0) { net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.thisPlayerMP, itemstack1, EnumHand.MAIN_HAND); this.thisPlayerMP.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null); } } flag1 = this.removeBlock(pos, flag); if (flag1 && flag) { iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity, itemstack2); } } // Drop experience if (!this.isCreative() && flag1 && exp > 0) { iblockstate.getBlock().dropXpOnBlockBreak(theWorld, pos, exp); } return flag1; } } }
public static void breakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos, BlockPos refPos) { if(world.isAirBlock(pos)) { return; } IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(!ToolUtil.isToolEffective(stack, state)) { return; } IBlockState refState = world.getBlockState(refPos); float refStrength = ForgeHooks.blockStrength(refState, player, world, refPos); float strength = ForgeHooks.blockStrength(state, player, world, pos); if(!ForgeHooks.canHarvestBlock(block, player, world, pos) || refStrength / strength > 10f) { return; } if(player.capabilities.isCreativeMode) { block.onBlockHarvested(world, pos, state, player); if(block.removedByPlayer(state, world, pos, player, false)) { block.onBlockDestroyedByPlayer(world, pos, state); } if(!world.isRemote) { CrystalModNetwork.sendMCPacket(player, new SPacketBlockChange(world, pos)); } return; } stack.onBlockDestroyed(world, state, pos, player); if(!world.isRemote) { int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos); if(xp == -1) { return; } TileEntity tileEntity = world.getTileEntity(pos); if(block.removedByPlayer(state, world, pos, player, true)) { block.onBlockDestroyedByPlayer(world, pos, state); block.harvestBlock(world, player, pos, state, tileEntity, stack); block.dropXpOnBlockBreak(world, pos, xp); } CrystalModNetwork.sendMCPacket(player, new SPacketBlockChange(world, pos)); } else { Minecraft.getMinecraft(); world.playBroadcastSound(2001, pos, Block.getStateId(state)); if(block.removedByPlayer(state, world, pos, player, true)) { block.onBlockDestroyedByPlayer(world, pos, state); } stack.onBlockDestroyed(world, state, pos, player); if(ItemStackTools.getStackSize(stack) == 0 && stack == player.getHeldItemMainhand()) { ForgeEventFactory.onPlayerDestroyItem(player, stack, EnumHand.MAIN_HAND); player.setHeldItem(EnumHand.MAIN_HAND, ItemStackTools.getEmptyStack()); } Minecraft.getMinecraft().getConnection().sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, Minecraft .getMinecraft().objectMouseOver.sideHit)); } }
/** * <<<< made with some help from Tinkers Construct and Spark's Hammers * https://github.com/thebrightspark/SparksHammers/blob/b84bd178fe2bbe47b13a89ef9435b20f09e429a4/src/main/java/com/brightspark/sparkshammers/util/CommonUtils.java and * https://github.com/SlimeKnights/TinkersConstruct */ @Override public boolean onBlockStartBreak(ItemStack stack, BlockPos posHit, EntityPlayer player) { RayTraceResult ray = rayTrace(player.getEntityWorld(), player, false); if (ray == null) { return super.onBlockStartBreak(stack, posHit, player); } EnumFacing sideHit = ray.sideHit; World world = player.getEntityWorld(); //use the shape builder to get region List<BlockPos> shape; if (sideHit == EnumFacing.UP || sideHit == EnumFacing.DOWN) { shape = UtilShape.squareHorizontalHollow(posHit, RADIUS); } else if (sideHit == EnumFacing.EAST || sideHit == EnumFacing.WEST) { shape = UtilShape.squareVerticalZ(posHit, RADIUS); } else {//has to be NORTHSOUTH shape = UtilShape.squareVerticalX(posHit, RADIUS); } for (BlockPos posCurrent : shape) { //first we validate if (posHit.equals(posCurrent)) { continue; } if (super.onBlockStartBreak(stack, new BlockPos(posCurrent), player)) { continue; } IBlockState bsCurrent = world.getBlockState(posCurrent); if (world.isAirBlock(posCurrent)) { continue; } if (!mats.contains(bsCurrent.getMaterial())) { continue; } Block blockCurrent = bsCurrent.getBlock(); if (!ForgeHooks.canHarvestBlock(blockCurrent, player, world, posCurrent) || bsCurrent.getBlock().canEntityDestroy(bsCurrent, world, posCurrent, player) == false || bsCurrent.getBlock().getBlockHardness(bsCurrent, world, posCurrent) < 0) { continue; } //then we destroy stack.onBlockDestroyed(world, bsCurrent, posCurrent, player); if (world.isRemote) {//C world.playEvent(2001, posCurrent, Block.getStateId(bsCurrent)); if (blockCurrent.removedByPlayer(bsCurrent, world, posCurrent, player, true)) { blockCurrent.onBlockDestroyedByPlayer(world, posCurrent, bsCurrent); } stack.onBlockDestroyed(world, bsCurrent, posCurrent, player);//update tool damage if (stack.getCount() == 0 && stack == player.getHeldItemMainhand()) { ForgeEventFactory.onPlayerDestroyItem(player, stack, EnumHand.MAIN_HAND); player.setHeldItem(EnumHand.MAIN_HAND, null); } Minecraft.getMinecraft().getConnection().sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, posCurrent, Minecraft.getMinecraft().objectMouseOver.sideHit)); } else if (player instanceof EntityPlayerMP) {//Server side, so this works EntityPlayerMP mp = (EntityPlayerMP) player; int xpGivenOnDrop = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, posCurrent); if (xpGivenOnDrop >= 0) { if (blockCurrent.removedByPlayer(bsCurrent, world, posCurrent, player, true)) { TileEntity tile = world.getTileEntity(posCurrent); blockCurrent.onBlockDestroyedByPlayer(world, posCurrent, bsCurrent); blockCurrent.harvestBlock(world, player, posCurrent, bsCurrent, tile, stack); blockCurrent.dropXpOnBlockBreak(world, posCurrent, xpGivenOnDrop); } mp.connection.sendPacket(new SPacketBlockChange(world, posCurrent)); } } } return super.onBlockStartBreak(stack, posHit, player); }
private void aoeBlockBreak(ItemStack stack, World world, BlockPos pos, EntityPlayer player) { if(world.isAirBlock(pos)) return; if(!(player instanceof EntityPlayerMP)) return; EntityPlayerMP playerMP = (EntityPlayerMP) player; IBlockState state = world.getBlockState(pos); if(!isEffective(state) || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos)) return; int event = ForgeHooks.onBlockBreakEvent(world, playerMP.interactionManager.getGameType(), playerMP, pos); if(event == -1) return; stack.onBlockDestroyed(world, state, pos, player); if(!world.isRemote) { state.getBlock().onBlockHarvested(world, pos, state, player); if(state.getBlock().removedByPlayer(state, world, pos, player, true)) { state.getBlock().onBlockDestroyedByPlayer(world, pos, state); state.getBlock().harvestBlock(world, player, pos, state, world.getTileEntity(pos), stack); state.getBlock().dropXpOnBlockBreak(world, pos, event); } playerMP.connection.sendPacket(new SPacketBlockChange(world, pos)); } else //CLIENT { if(state.getBlock().removedByPlayer(state, world, pos, player, true)) state.getBlock().onBlockDestroyedByPlayer(world, pos, state); ItemStack itemstack = player.getActiveItemStack(); if(itemstack != null) { itemstack.onBlockDestroyed(world, state, pos, player); } ClockworkPhase2.proxy.sendBlockDestroyPacket(pos); } }
private void aoeBlockBreak(ItemStack stack, World world, BlockPos pos, EntityPlayer player) { if(world.isAirBlock(pos)) return; if(!(player instanceof EntityPlayerMP)) return; EntityPlayerMP playerMP = (EntityPlayerMP) player; IBlockState state = world.getBlockState(pos); if(!isEffective(stack, state) || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos)) return; int event = ForgeHooks.onBlockBreakEvent(world, playerMP.interactionManager.getGameType(), playerMP, pos); if(event == -1) return; stack.onBlockDestroyed(world, state, pos, player); if(!world.isRemote) { state.getBlock().onBlockHarvested(world, pos, state, player); if(state.getBlock().removedByPlayer(state, world, pos, player, true)) { state.getBlock().onBlockDestroyedByPlayer(world, pos, state); state.getBlock().harvestBlock(world, player, pos, state, world.getTileEntity(pos), stack); state.getBlock().dropXpOnBlockBreak(world, pos, event); } playerMP.connection.sendPacket(new SPacketBlockChange(world, pos)); } else //CLIENT { if(state.getBlock().removedByPlayer(state, world, pos, player, true)) state.getBlock().onBlockDestroyedByPlayer(world, pos, state); ItemStack itemstack = player.getActiveItemStack(); if(!itemstack.isEmpty()) { itemstack.onBlockDestroyed(world, state, pos, player); } ClockworkPhase2.proxy.sendBlockDestroyPacket(pos); } }
/** * Updates the block and metadata and generates a blockupdate (and notify the clients) */ void handleBlockChange(SPacketBlockChange packetIn);