Search in sources :

Example 6 with CPacketPlayerDigging

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));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CPacketPlayerDigging(net.minecraft.network.play.client.CPacketPlayerDigging) IBlockState(net.minecraft.block.state.IBlockState) NetHandlerPlayClient(net.minecraft.client.network.NetHandlerPlayClient) Block(net.minecraft.block.Block) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange)

Aggregations

CPacketPlayerDigging (net.minecraft.network.play.client.CPacketPlayerDigging)6 EnumFacing (net.minecraft.util.EnumFacing)3 BlockPos (net.minecraft.util.math.BlockPos)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 CPacketClickWindow (net.minecraft.network.play.client.CPacketClickWindow)2 CPacketPlayerTryUseItemOnBlock (net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)2 SPacketBlockChange (net.minecraft.network.play.server.SPacketBlockChange)2 Vec3d (net.minecraft.util.math.Vec3d)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 NetHandlerPlayClient (net.minecraft.client.network.NetHandlerPlayClient)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 CPacketAnimation (net.minecraft.network.play.client.CPacketAnimation)1 CPacketClientStatus (net.minecraft.network.play.client.CPacketClientStatus)1 CPacketEntityAction (net.minecraft.network.play.client.CPacketEntityAction)1 CPacketPlayer (net.minecraft.network.play.client.CPacketPlayer)1 CPacketPlayerTryUseItem (net.minecraft.network.play.client.CPacketPlayerTryUseItem)1