Search in sources :

Example 1 with BushBlock

use of net.minecraft.block.BushBlock in project BluePower by Qmunity.

the class ItemSickle method mineBlock.

@Override
public boolean mineBlock(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity entityLiving) {
    boolean used = false;
    if (!(entityLiving instanceof PlayerEntity))
        return false;
    PlayerEntity player = (PlayerEntity) entityLiving;
    if (state.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || state.getBlock() instanceof LeavesBlock) {
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                for (int k = -1; k <= 1; k++) {
                    BlockState blockToCheck = world.getBlockState(pos.offset(i, j, k));
                    if (blockToCheck.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || blockToCheck.getBlock() instanceof LeavesBlock) {
                        if (blockToCheck.canHarvestBlock(world, pos.offset(i, j, k), player)) {
                            world.destroyBlock(pos.offset(i, j, k), true);
                        }
                        used = true;
                    }
                }
            }
        }
        if (used) {
            stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
        }
        return used;
    }
    if ((state.getBlock() instanceof LilyPadBlock)) {
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
                BlockState meta = world.getBlockState(pos.offset(i, 0, j));
                if (blockToCheck instanceof LilyPadBlock) {
                    if (blockToCheck.canHarvestBlock(meta, world, pos.offset(i, 0, j), player)) {
                        world.destroyBlock(pos.offset(i, 0, j), true);
                    }
                    used = true;
                }
            }
        }
    }
    if (!(state.getBlock() instanceof LilyPadBlock)) {
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
                if (blockToCheck instanceof BushBlock && !(blockToCheck instanceof LilyPadBlock)) {
                    if (blockToCheck.canHarvestBlock(world.getBlockState(pos.offset(i, 0, j)), world, pos.offset(i, 0, j), player)) {
                        world.destroyBlock(pos.offset(i, 0, j), true);
                    }
                    used = true;
                }
            }
        }
    }
    if (used) {
        stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
    }
    return used;
}
Also used : BushBlock(net.minecraft.block.BushBlock) BlockState(net.minecraft.block.BlockState) LilyPadBlock(net.minecraft.block.LilyPadBlock) ResourceLocation(net.minecraft.util.ResourceLocation) BushBlock(net.minecraft.block.BushBlock) LilyPadBlock(net.minecraft.block.LilyPadBlock) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

BlockState (net.minecraft.block.BlockState)1 BushBlock (net.minecraft.block.BushBlock)1 LilyPadBlock (net.minecraft.block.LilyPadBlock)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ResourceLocation (net.minecraft.util.ResourceLocation)1