Search in sources :

Example 1 with CommandBlock

use of net.minecraft.block.CommandBlock in project VeinMining by TheIllusiveC4.

the class VeinMiningLogic method harvest.

public static boolean harvest(ServerPlayerEntity player, BlockPos pos, BlockPos originPos) {
    ServerWorld world = player.getWorld();
    BlockState blockState = world.getBlockState(pos);
    GameMode gameMode = player.interactionManager.getGameMode();
    if (!player.getMainHandStack().getItem().canMine(blockState, world, pos, player)) {
        return false;
    } else {
        BlockEntity blockEntity = world.getBlockEntity(pos);
        Block block = blockState.getBlock();
        if ((block instanceof CommandBlock || block instanceof StructureBlock || block instanceof JigsawBlock) && !player.isCreativeLevelTwoOp()) {
            world.updateListeners(pos, blockState, blockState, 3);
            return false;
        } else if (player.isBlockBreakingRestricted(world, pos, gameMode)) {
            return false;
        } else {
            block.onBreak(world, pos, blockState, player);
            boolean bl = world.removeBlock(pos, false);
            if (bl) {
                block.onBroken(world, pos, blockState);
            }
            if (gameMode != GameMode.CREATIVE) {
                ItemStack itemStack = player.getMainHandStack();
                ItemStack itemStack2 = itemStack.copy();
                boolean bl2 = player.canHarvest(blockState);
                if (VeinMiningConfig.VeinMining.addToolDamage) {
                    postMine(itemStack, world, blockState, pos, player);
                }
                BlockPos spawnPos = VeinMiningConfig.VeinMining.relocateDrops ? originPos : pos;
                if (bl && bl2) {
                    afterBreak(block, world, player, pos, spawnPos, blockState, blockEntity, itemStack2);
                }
            }
            return true;
        }
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) JigsawBlock(net.minecraft.block.JigsawBlock) GameMode(net.minecraft.world.GameMode) BlockState(net.minecraft.block.BlockState) StructureBlock(net.minecraft.block.StructureBlock) CommandBlock(net.minecraft.block.CommandBlock) Block(net.minecraft.block.Block) JigsawBlock(net.minecraft.block.JigsawBlock) StructureBlock(net.minecraft.block.StructureBlock) BlockPos(net.minecraft.util.math.BlockPos) CommandBlock(net.minecraft.block.CommandBlock) ItemStack(net.minecraft.item.ItemStack) BlockEntity(net.minecraft.block.entity.BlockEntity)

Aggregations

Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 CommandBlock (net.minecraft.block.CommandBlock)1 JigsawBlock (net.minecraft.block.JigsawBlock)1 StructureBlock (net.minecraft.block.StructureBlock)1 BlockEntity (net.minecraft.block.entity.BlockEntity)1 ItemStack (net.minecraft.item.ItemStack)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 BlockPos (net.minecraft.util.math.BlockPos)1 GameMode (net.minecraft.world.GameMode)1