From 7a44257ed95bd837e6a66befcd50a422f03e4a54 Mon Sep 17 00:00:00 2001 From: "Joseph T. McQuigg" Date: Mon, 5 Aug 2024 23:21:26 -0400 Subject: [PATCH] BWGFruitLeavesBlock Changes --- CHANGELOG.md | 4 ++++ .../tree/leaves/BWGFruitLeavesBlock.java | 21 +++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e095d6bc2..bad16c06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/plants/tree/leaves/BWGFruitLeavesBlock.java b/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/plants/tree/leaves/BWGFruitLeavesBlock.java index b60447f0a..1a1e0d730 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/plants/tree/leaves/BWGFruitLeavesBlock.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/world/level/block/plants/tree/leaves/BWGFruitLeavesBlock.java @@ -14,12 +14,12 @@ import java.util.function.Supplier; public class BWGFruitLeavesBlock extends LeavesBlock implements BonemealableBlock { - private final Supplier fruitBlock; + private final Supplier fruitBlock; private final float tickSpawnChance; public BWGFruitLeavesBlock(Properties properties, Supplier fruitBlock, float tickSpawnChance) { super(properties); - this.fruitBlock = () -> fruitBlock.get().defaultBlockState().setValue(BWGFruitBlock.AGE, 0); + this.fruitBlock = fruitBlock; this.tickSpawnChance = tickSpawnChance; } @@ -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); } }