From cf6852fe3c8b05724a0aae9c4990f1236b29a788 Mon Sep 17 00:00:00 2001 From: orifu Date: Wed, 25 Sep 2024 19:29:49 +0100 Subject: [PATCH 1/3] fix missing growing berry bush stage & make non-harvestable --- .../block/BasicBerryBush.java | 7 ++--- .../bodacious_berries/block/BerryBush.java | 7 +++++ .../block/GrowingBerryBush.java | 31 ++++++++----------- 3 files changed, 23 insertions(+), 22 deletions(-) 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..3685dc6 100644 --- a/src/main/java/io/ix0rai/bodacious_berries/block/BasicBerryBush.java +++ b/src/main/java/io/ix0rai/bodacious_berries/block/BasicBerryBush.java @@ -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); } 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; + } } From ee8788931e2450996d363e7f0dc56fb364d2c24d Mon Sep 17 00:00:00 2001 From: orifu Date: Wed, 25 Sep 2024 19:30:09 +0100 Subject: [PATCH 2/3] discover the concept of "abstract class" --- .../io/ix0rai/bodacious_berries/block/BasicBerryBush.java | 7 +------ .../io/ix0rai/bodacious_berries/block/SpikedBerryBush.java | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) 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 3685dc6..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; @@ -183,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/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; From 978a3f84f44e7dacd7b8f1884ca2b85b78e8dd7b Mon Sep 17 00:00:00 2001 From: orifu Date: Wed, 25 Sep 2024 19:30:23 +0100 Subject: [PATCH 3/3] fix deprecation warning (concurrent() is now a no-op) --- .../java/io/ix0rai/bodacious_berries/config/BodaciousConfig.java | 1 - 1 file changed, 1 deletion(-) 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();