From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Samsuik Date: Thu, 16 May 2024 21:20:52 +0100 Subject: [PATCH] Use random chance for crop growth instead of age diff --git a/src/main/java/net/minecraft/world/level/block/CactusBlock.java b/src/main/java/net/minecraft/world/level/block/CactusBlock.java index c045b1cccf0047dbef8c04d5a28d31d53389054f..02da342fa002af134a75a9d2046e43808b76fbcc 100644 --- a/src/main/java/net/minecraft/world/level/block/CactusBlock.java +++ b/src/main/java/net/minecraft/world/level/block/CactusBlock.java @@ -53,6 +53,19 @@ public class CactusBlock extends Block { @Override protected void randomTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) { + // Sakura start - use random chance for crop growth + if (world.sakuraConfig().environment.crops.useRandomChanceToGrow) { + int modifier = world.spigotConfig.cactusModifier; + if (random.nextFloat() >= modifier / (100.0f * 16)) { + return; + } + // set crop age to max so it grows right away + state = state.setValue(CactusBlock.AGE, AGE.max); + } + this.ageAndGrow(state, world, pos, random); + } + private void ageAndGrow(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) { + // Sakura end - use random chance for crop growth BlockPos blockposition1 = pos.above(); if (world.isEmptyBlock(blockposition1)) { @@ -69,7 +82,11 @@ public class CactusBlock extends Block { if (j >= 15 || (modifier != 100 && random.nextFloat() < (modifier / (100.0f * 16)))) { // Spigot - SPIGOT-7159: Better modifier resolution CraftEventFactory.handleBlockGrowEvent(world, blockposition1, this.defaultBlockState()); // CraftBukkit BlockState iblockdata1 = (BlockState) state.setValue(CactusBlock.AGE, 0); - + // Sakura start - use random chance for crop growth + if (world.sakuraConfig().environment.crops.useRandomChanceToGrow) { + world.neighborShapeChanged(Direction.UP, blockposition1, pos, state, 4, 1); + } + // Sakura end - use random chance for crop growth world.setBlock(pos, iblockdata1, 4); world.neighborChanged(iblockdata1, blockposition1, this, (Orientation) null, false); } else if (modifier == 100 || random.nextFloat() < (modifier / (100.0f * 16))) { // Spigot - SPIGOT-7159: Better modifier resolution diff --git a/src/main/java/net/minecraft/world/level/block/SugarCaneBlock.java b/src/main/java/net/minecraft/world/level/block/SugarCaneBlock.java index 547ea09ed84595286c97c128b3b96f6d387ae25f..3db03582e710f87c176ec47d9cab901d27db2e5e 100644 --- a/src/main/java/net/minecraft/world/level/block/SugarCaneBlock.java +++ b/src/main/java/net/minecraft/world/level/block/SugarCaneBlock.java @@ -52,6 +52,19 @@ public class SugarCaneBlock extends Block { @Override protected void randomTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) { + // Sakura start - use random chance for crop growth + if (world.sakuraConfig().environment.crops.useRandomChanceToGrow) { + int modifier = world.spigotConfig.caneModifier; + if (random.nextFloat() >= modifier / (100.0f * 16)) { + return; + } + // set crop age to max so it grows right away + state = state.setValue(SugarCaneBlock.AGE, AGE.max); + } + this.ageAndGrow(state, world, pos, random); + } + private void ageAndGrow(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) { + // Sakura end - use random chance for crop growth if (world.isEmptyBlock(pos.above())) { int i; @@ -66,6 +79,7 @@ public class SugarCaneBlock extends Block { if (j >= 15 || (modifier != 100 && random.nextFloat() < (modifier / (100.0f * 16)))) { // Spigot - SPIGOT-7159: Better modifier resolution org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, pos.above(), this.defaultBlockState()); // CraftBukkit world.setBlock(pos, (BlockState) state.setValue(SugarCaneBlock.AGE, 0), 4); + // Sakura - conflict on change } else if (modifier == 100 || random.nextFloat() < (modifier / (100.0f * 16))) { // Spigot - SPIGOT-7159: Better modifier resolution world.setBlock(pos, (BlockState) state.setValue(SugarCaneBlock.AGE, j + 1), 4); }