Skip to content

Commit

Permalink
it may or may not work perfectly
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed May 19, 2024
1 parent 808829b commit 240e5a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,12 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)

@Override
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) {
// hasRandomTicks checks the same thing as this method
return state.hasRandomTicks();
return state.get(getAge()) < getMaxAge();
}

@Override
public boolean canFertilize(World world, RandomGenerator random, BlockPos pos, BlockState state) {
// hasRandomTicks checks the same thing as this method
return state.hasRandomTicks();
return isFertilizable(world, pos, state);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
builder.add(AGE, UP, NORTH, EAST, SOUTH, WEST);
}

// @Override
// public boolean hasRandomTicks(BlockState state) {
// return state.get(AGE) < MAX_AGE;
// }

@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, RandomGenerator random) {
super.randomTick(state, world, pos, random);
Expand Down Expand Up @@ -103,12 +98,12 @@ public int getMaxBerryAmount() {

@Override
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) {
return state.hasRandomTicks();
return state.get(getAge()) < MAX_AGE;
}

@Override
public boolean canFertilize(World world, RandomGenerator random, BlockPos pos, BlockState state) {
return state.hasRandomTicks();
return isFertilizable(world, pos, state);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
builder.add(getAge()).add(HALF);
}

// @Override
// public boolean hasRandomTicks(BlockState state) {
// return state.get(getAge()) < MAX_AGE;
// }

@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, RandomGenerator random) {
int age = state.get(getAge());
Expand All @@ -71,12 +66,12 @@ public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random

@Override
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) {
return state.hasRandomTicks();
return state.get(getAge()) < MAX_AGE;
}

@Override
public boolean canFertilize(World world, RandomGenerator random, BlockPos pos, BlockState state) {
return state.hasRandomTicks();
return isFertilizable(world, pos, state);
}

@Override
Expand All @@ -100,13 +95,11 @@ protected ItemInteractionResult onInteract(ItemStack stack, BlockState state, Wo

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hitResult) {
// if (hasRandomTicks(state) && player.getStackInHand(hand).isOf(Items.BONE_MEAL)) {
// return ActionResult.PASS;
// } else if (state.get(getAge()) == MAX_AGE) {
// return BasicBerryBush.pickBerries(pos, world, state, this.getBerryItem());
// } else {
if (state.get(getAge()) == MAX_AGE) {
return BasicBerryBush.pickBerries(pos, world, state, this.getBerryItem());
} else {
return super.onUse(state, world, pos, player, hitResult);
// }
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemInteractionResult;
import net.minecraft.util.hit.BlockHitResult;
Expand Down Expand Up @@ -48,26 +47,18 @@ 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 == 3;
return !isMaxAge && stack.isOf(Items.BONE_MEAL)
? ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION
: super.onInteract(stack, state, world, pos, entity, hand, hitResult);
}
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);
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity entity, BlockHitResult hitResult) {
// // a GrowingBerryBush cannot produce berries until it grows to its double bush state
// if (state.hasRandomTicks() && player.getStackInHand(hand).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 ActionResult.PASS;
// }
return ItemInteractionResult.CONSUME;
}

return ActionResult.FAIL;
return super.onInteract(stack, state, world, pos, entity, hand, hitResult);
}

@Override
Expand Down

0 comments on commit 240e5a5

Please sign in to comment.