Search in sources :

Example 1 with SweetBerryBushBlock

use of net.minecraft.world.level.block.SweetBerryBushBlock in project Create by Creators-of-Create.

the class HarvesterMovementBehaviour method isValidCrop.

public boolean isValidCrop(Level world, BlockPos pos, BlockState state) {
    boolean harvestPartial = AllConfigs.SERVER.kinetics.harvestPartiallyGrown.get();
    boolean replant = AllConfigs.SERVER.kinetics.harvesterReplants.get();
    if (state.getBlock() instanceof CropBlock) {
        CropBlock crop = (CropBlock) state.getBlock();
        if (harvestPartial)
            return state.getValue(crop.getAgeProperty()) != 0 || !replant;
        return crop.isMaxAge(state);
    }
    if (state.getCollisionShape(world, pos).isEmpty() || state.getBlock() instanceof CocoaBlock) {
        for (Property<?> property : state.getProperties()) {
            if (!(property instanceof IntegerProperty))
                continue;
            IntegerProperty ageProperty = (IntegerProperty) property;
            if (!property.getName().equals(BlockStateProperties.AGE_1.getName()))
                continue;
            int age = state.getValue(ageProperty).intValue();
            if (state.getBlock() instanceof SweetBerryBushBlock && age <= 1 && replant)
                continue;
            if (age == 0 && replant || !harvestPartial && (ageProperty.getPossibleValues().size() - 1 != age))
                continue;
            return true;
        }
    }
    return false;
}
Also used : IntegerProperty(net.minecraft.world.level.block.state.properties.IntegerProperty) CocoaBlock(net.minecraft.world.level.block.CocoaBlock) SweetBerryBushBlock(net.minecraft.world.level.block.SweetBerryBushBlock) CropBlock(net.minecraft.world.level.block.CropBlock)

Example 2 with SweetBerryBushBlock

use of net.minecraft.world.level.block.SweetBerryBushBlock in project Shelve by Mssstream.

the class HarvesterBlock method harvest.

public void harvest(Level lev, BlockState state, BlockPos pos) {
    if (state.getBlock() instanceof CropBlock) {
        if (state.getValue(CropBlock.AGE) == 7) {
            lev.destroyBlock(pos, true);
            lev.playSound(null, pos, SoundEvents.CROP_BREAK, SoundSource.BLOCKS, 0.8f, 1.0f);
            lev.setBlockAndUpdate(pos, state.setValue(CropBlock.AGE, 1));
        }
    } else if (state.getBlock() instanceof NetherWartBlock) {
        if (state.getValue(NetherWartBlock.AGE) == 3) {
            lev.destroyBlock(pos, true);
            lev.playSound(null, pos, SoundEvents.NETHER_WART_BREAK, SoundSource.BLOCKS, 0.8f, 1.0f);
            lev.setBlockAndUpdate(pos, state.setValue(NetherWartBlock.AGE, 0));
        }
    } else if (state.getBlock() instanceof SweetBerryBushBlock) {
        if (state.getValue(SweetBerryBushBlock.AGE) == 3) {
            int j = 1 + lev.random.nextInt(2);
            popResource(lev, pos, new ItemStack(Items.SWEET_BERRIES, j + 1));
            lev.playSound((Player) null, pos, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, 0.8F + lev.random.nextFloat() * 0.4F);
            lev.setBlock(pos, state.setValue(SweetBerryBushBlock.AGE, Integer.valueOf(1)), 2);
        }
    } else {
    }
}
Also used : SweetBerryBushBlock(net.minecraft.world.level.block.SweetBerryBushBlock) CropBlock(net.minecraft.world.level.block.CropBlock) NetherWartBlock(net.minecraft.world.level.block.NetherWartBlock) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

CropBlock (net.minecraft.world.level.block.CropBlock)2 SweetBerryBushBlock (net.minecraft.world.level.block.SweetBerryBushBlock)2 ItemStack (net.minecraft.world.item.ItemStack)1 CocoaBlock (net.minecraft.world.level.block.CocoaBlock)1 NetherWartBlock (net.minecraft.world.level.block.NetherWartBlock)1 IntegerProperty (net.minecraft.world.level.block.state.properties.IntegerProperty)1