diff --git a/src/main/java/io/ix0rai/bodacious_berries/block/BasicBerryBush.java b/src/main/java/io/ix0rai/bodacious_berries/block/BasicBerryBush.java index 72c6b9d..44bfc94 100644 --- a/src/main/java/io/ix0rai/bodacious_berries/block/BasicBerryBush.java +++ b/src/main/java/io/ix0rai/bodacious_berries/block/BasicBerryBush.java @@ -30,7 +30,7 @@ import net.minecraft.world.World; import net.minecraft.world.WorldView; -public class BasicBerryBush extends PlantBlock implements BerryBush { +public abstract class BasicBerryBush extends PlantBlock implements BerryBush { protected static final Vec3d BERRY_BUSH_SLOWING_VECTOR = new Vec3d(0.5D, 0.25D, 0.5D); protected static final int GROW_CHANCE = 5; protected static final int MAX_BERRY_AMOUNT = 3; @@ -121,7 +121,7 @@ protected ItemInteractionResult onInteract( public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity entity, BlockHitResult hitResult) { final int currentAge = state.get(getAge()); // if bone meal is allowed to be used, pass action - if (currentAge == maxAge) { + if (currentAge == maxAge && canBeHarvested()) { // otherwise, give berries/unripe berries return pickBerries(pos, world, state, this.getBerryItem()); } else { @@ -166,11 +166,10 @@ public boolean canFertilize(World world, RandomGenerator random, BlockPos pos, B @Override public void fertilize(ServerWorld world, RandomGenerator random, BlockPos pos, BlockState state) { - int newAge = Math.min(maxAge, state.get(getAge()) + 1); - grow(world, pos, state, newAge); + grow(world, pos, state, state.get(getAge()) + 1); } - public void grow(ServerWorld world, BlockPos pos, BlockState state, int newAge) { + public void grow(World world, BlockPos pos, BlockState state, int newAge) { world.setBlockState(pos, state.with(getAge(), newAge), Block.NOTIFY_LISTENERS); } @@ -184,11 +183,6 @@ public int getSizeChangeAge() { return sizeChangeAge; } - @Override - public IntProperty getAge() { - throw new AssertionError("getAge() should always be overridden"); - } - @Override public Berry getBerry() { return berry; diff --git a/src/main/java/io/ix0rai/bodacious_berries/block/BerryBush.java b/src/main/java/io/ix0rai/bodacious_berries/block/BerryBush.java index 413f688..67a47ad 100644 --- a/src/main/java/io/ix0rai/bodacious_berries/block/BerryBush.java +++ b/src/main/java/io/ix0rai/bodacious_berries/block/BerryBush.java @@ -59,6 +59,13 @@ default boolean isFullyGrown(BlockState state) { return state.get(getAge()) == getMaxAge(); } + /** + * @return whether the bush can be harvested when at max age. + */ + default boolean canBeHarvested() { + return true; + } + /** * sets the age of the bush its minimum possible age while preserving its size * @param world the world in which the bush is growing diff --git a/src/main/java/io/ix0rai/bodacious_berries/block/GrowingBerryBush.java b/src/main/java/io/ix0rai/bodacious_berries/block/GrowingBerryBush.java index 3e5e79d..35855d3 100644 --- a/src/main/java/io/ix0rai/bodacious_berries/block/GrowingBerryBush.java +++ b/src/main/java/io/ix0rai/bodacious_berries/block/GrowingBerryBush.java @@ -16,6 +16,7 @@ import net.minecraft.util.random.RandomGenerator; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.World; +import net.minecraft.world.WorldView; public class GrowingBerryBush extends BasicBerryBush { private final DoubleBerryBush futureBush; @@ -26,8 +27,8 @@ public GrowingBerryBush(VoxelShape smallShape, VoxelShape largeShape, DoubleBerr } @Override - public void grow(ServerWorld world, BlockPos pos, BlockState state, int newAge) { - if (newAge < maxAge) { + public void grow(World world, BlockPos pos, BlockState state, int newAge) { + if (newAge <= maxAge) { world.setBlockState(pos, state.with(getAge(), newAge), Block.NOTIFY_LISTENERS); } else { TallPlantBlock.placeAt(world, futureBush.getDefaultState(), pos, Block.NOTIFY_LISTENERS); @@ -43,26 +44,20 @@ public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random } @Override - protected ItemInteractionResult onInteract( - ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity entity, Hand hand, BlockHitResult hitResult - ) { - int i = state.get(getAge()); - boolean isMaxAge = i == getMaxAge(); - if (isMaxAge && stack.isOf(Items.BONE_MEAL)) { - final int newAge = Math.min(maxAge, state.get(getAge()) + 1); - // grow to a double bush if new age exceeds maximum - if (newAge > maxAge) { - TallPlantBlock.placeAt(world, futureBush.getDefaultState(), pos, Block.NOTIFY_LISTENERS); - } - - return ItemInteractionResult.CONSUME; - } - - return super.onInteract(stack, state, world, pos, entity, hand, hitResult); + public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) { + // this bush can be fertilised when at max age, at which point + // it will grow into the futureBush form. + return true; } @Override public IntProperty getAge() { return Properties.AGE_2; } + + @Override + public boolean canBeHarvested() { + // this bush can't be harvested while it hasn't grown to the futureBush. + return false; + } } diff --git a/src/main/java/io/ix0rai/bodacious_berries/block/SpikedBerryBush.java b/src/main/java/io/ix0rai/bodacious_berries/block/SpikedBerryBush.java index bb29ae1..065047a 100644 --- a/src/main/java/io/ix0rai/bodacious_berries/block/SpikedBerryBush.java +++ b/src/main/java/io/ix0rai/bodacious_berries/block/SpikedBerryBush.java @@ -11,7 +11,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.World; -public class SpikedBerryBush extends BasicBerryBush { +public abstract class SpikedBerryBush extends BasicBerryBush { private static final float MINIMUM_DAMAGE_DISTANCE = 0.003f; private final float damage; diff --git a/src/main/java/io/ix0rai/bodacious_berries/config/BodaciousConfig.java b/src/main/java/io/ix0rai/bodacious_berries/config/BodaciousConfig.java index 45374c5..85b3b02 100644 --- a/src/main/java/io/ix0rai/bodacious_berries/config/BodaciousConfig.java +++ b/src/main/java/io/ix0rai/bodacious_berries/config/BodaciousConfig.java @@ -17,7 +17,6 @@ public class BodaciousConfig { public BodaciousConfig() { this.config = CommentedFileConfig.builder(CONFIG_FILE_PATH) - .concurrent() .autosave() .preserveInsertionOrder() .build();