Search in sources :

Example 1 with BlockCommandBlock

use of net.minecraft.block.BlockCommandBlock in project Overloaded by CJ-MC-Mods.

the class PlayerInteractionUtil method tryHarvestBlock.

public static boolean tryHarvestBlock(EntityPlayerMP player, World world, BlockPos pos) {
    int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, player.interactionManager.getGameType(), player, pos);
    if (exp == -1) {
        return false;
    } else {
        IBlockState iblockstate = world.getBlockState(pos);
        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 {
            world.playEvent(null, 2001, pos, Block.getStateId(iblockstate));
            boolean flag1;
            if (player.capabilities.isCreativeMode) {
                flag1 = 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 flag = iblockstate.getBlock().canHarvestBlock(world, pos, player);
                itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
                flag1 = removeBlock(world, pos, player, flag);
                if (flag1 && flag) {
                    iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
                }
            }
            // Drop experience
            if (!player.isCreative() && flag1 && exp > 0) {
                iblockstate.getBlock().dropXpOnBlockBreak(world, player.getPosition(), exp);
            }
            return flag1;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) BlockStructure(net.minecraft.block.BlockStructure) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange)

Aggregations

Block (net.minecraft.block.Block)1 BlockCommandBlock (net.minecraft.block.BlockCommandBlock)1 BlockStructure (net.minecraft.block.BlockStructure)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 SPacketBlockChange (net.minecraft.network.play.server.SPacketBlockChange)1 TileEntity (net.minecraft.tileentity.TileEntity)1