Skip to content

Commit

Permalink
BWGFruitLeavesBlock Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JT122406 committed Aug 6, 2024
1 parent 642dd96 commit 7a44257
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 1.0.6-Beta
- Fix Skyris Hanging Sign Textures being swapped
- Fix Blue Enchanted Sapling Crashing on place
- Changes to Fruit Leaves
- Pass Supplier of BWGFruitBlock to BWGFruitLeavesBlock instead of supplier of blockstate
- Prevent Bonemealing when leaves are placed by players/decayable/Persistence Value
- Reason for this is fruit should only really be growing when the leaves are attached to a tree

# 1.0.5-Beta
- Workaround for a crash involving fruit leaves decay (No Drops)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import java.util.function.Supplier;

public class BWGFruitLeavesBlock extends LeavesBlock implements BonemealableBlock {
private final Supplier<BlockState> fruitBlock;
private final Supplier<BWGFruitBlock> fruitBlock;
private final float tickSpawnChance;

public BWGFruitLeavesBlock(Properties properties, Supplier<BWGFruitBlock> fruitBlock, float tickSpawnChance) {
super(properties);
this.fruitBlock = () -> fruitBlock.get().defaultBlockState().setValue(BWGFruitBlock.AGE, 0);
this.fruitBlock = fruitBlock;
this.tickSpawnChance = tickSpawnChance;
}

Expand All @@ -29,34 +29,33 @@ public void randomTick(@NotNull BlockState state, @NotNull ServerLevel level, @N
BlockPos fruitPos = pos.below();
if (this.decaying(state)) {
BlockState below = level.getBlockState(fruitPos);
if (below.is(fruitBlock.get().getBlock()))
if (below.is(fruitBlock.get()))
level.destroyBlock(fruitPos, below.getValue(BWGFruitBlock.AGE) == BWGFruitBlock.MAX_AGE || random.nextBoolean());
} else if (level.getBlockState(fruitPos).isAir() && random.nextFloat() < this.tickSpawnChance)
placeFruit(level, fruitPos);
}

private void placeFruit(Level level, BlockPos pos) {
level.setBlock(pos, fruitBlock.get(), 2);
private void placeFruit(@NotNull Level level, @NotNull BlockPos pos) {
level.setBlock(pos, fruitBlock.get().defaultBlockState().setValue(BWGFruitBlock.AGE, 0), 2);
}

@Override
public boolean isValidBonemealTarget(@NotNull LevelReader level, @NotNull BlockPos pos, @NotNull BlockState state, boolean isClient) {
return true;
return !state.getValue(PERSISTENT);
}

@Override
public boolean isBonemealSuccess(Level level, @NotNull RandomSource random, BlockPos pos, @NotNull BlockState state) {
public boolean isBonemealSuccess(@NotNull Level level, @NotNull RandomSource random, @NotNull BlockPos pos, @NotNull BlockState state) {
BlockState below = level.getBlockState(pos.below());
if (below.isAir() || below.getBlock() instanceof BWGFruitBlock && below.getValue(BWGFruitBlock.AGE) < 3)
if (below.isAir() || below.is(fruitBlock.get()) && below.getValue(BWGFruitBlock.AGE) < 3)
return random.nextBoolean();
return false;
}

@Override
public void performBonemeal(ServerLevel level, @NotNull RandomSource random, BlockPos pos, @NotNull BlockState state) {
public void performBonemeal(@NotNull ServerLevel level, @NotNull RandomSource random, BlockPos pos, @NotNull BlockState state) {
BlockState below = level.getBlockState(pos.below());
if (below.isAir()) placeFruit(level, pos.below());
else if (below.is(fruitBlock.get().getBlock()))
level.setBlock(pos.below(), below.cycle(BWGFruitBlock.AGE), 2);
else if (below.is(fruitBlock.get())) level.setBlock(pos.below(), below.cycle(BWGFruitBlock.AGE), 2);
}
}

0 comments on commit 7a44257

Please sign in to comment.