use of net.minecraft.network.play.client.CPacketPlayerDigging in project BaseMetals by MinecraftModDevelopmentMods.
the class ItemMMDSickle method breakBlock.
private void breakBlock(final ItemStack tool, final World world, final EntityPlayer player, final BlockPos centralPosition, final BlockPos actualPosition) {
if (world.isAirBlock(actualPosition)) {
return;
}
final IBlockState bsatapos = world.getBlockState(actualPosition);
final Block block = bsatapos.getBlock();
// fire off this event
tool.onBlockDestroyed(world, bsatapos, centralPosition, player);
if (!world.isRemote) {
// send the blockbreak event
final int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, actualPosition);
if (xp == -1) {
return;
}
// serverside we reproduce ItemInWorldManager.tryHarvestBlock
final TileEntity tileEntity = world.getTileEntity(actualPosition);
if (block.removedByPlayer(bsatapos, world, actualPosition, player, true)) {
// boolean is if block can be
// harvested, checked above
block.onBlockDestroyedByPlayer(world, actualPosition, bsatapos);
block.harvestBlock(world, player, actualPosition, bsatapos, tileEntity, tool);
block.dropXpOnBlockBreak(world, actualPosition, xp);
}
sendPacket(player, new SPacketBlockChange(world, actualPosition));
} else {
world.playBroadcastSound(2001, actualPosition, Block.getStateId(bsatapos));
if (block.removedByPlayer(bsatapos, world, actualPosition, player, true)) {
block.onBlockDestroyedByPlayer(world, actualPosition, bsatapos);
}
tool.onBlockDestroyed(world, bsatapos, actualPosition, player);
// equality is needed, dunno
if (tool.getCount() == 0 && tool.equals(player.getHeldItemMainhand())) {
ForgeEventFactory.onPlayerDestroyItem(player, tool, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
}
// send an update to the server, so we get an update back
final NetHandlerPlayClient netHandlerPlayClient = Minecraft.getMinecraft().getConnection();
assert netHandlerPlayClient != null;
netHandlerPlayClient.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, actualPosition, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
}
Aggregations