Skip to content

Commit

Permalink
Merge pull request #70 from rosebudmods/orifu/fix-growing-berry-bush
Browse files Browse the repository at this point in the history
fix growing berry bush
  • Loading branch information
ix0rai committed Sep 26, 2024
2 parents 00728b6 + 978a3f8 commit b04a092
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class BodaciousConfig {

public BodaciousConfig() {
this.config = CommentedFileConfig.builder(CONFIG_FILE_PATH)
.concurrent()
.autosave()
.preserveInsertionOrder()
.build();
Expand Down

0 comments on commit b04a092

Please sign in to comment.