mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 07:49:29 +00:00
76 lines
4.6 KiB
Diff
76 lines
4.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
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 ba4aaf850af36a84517c70581e141157c4f15b99..1505a828ab9b3f39cab0ce15fb5a682d4d907a01 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/CactusBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/CactusBlock.java
|
|
@@ -52,6 +52,19 @@ public class CactusBlock extends Block {
|
|
|
|
@Override
|
|
public 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)) {
|
|
@@ -68,7 +81,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, state, blockposition1, pos, 4, 1);
|
|
+ }
|
|
+ // Sakura end - use random chance for crop growth
|
|
world.setBlock(pos, iblockdata1, 4);
|
|
world.neighborChanged(iblockdata1, blockposition1, this, pos, 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 04957d461d0e968d443737068aaeec1d0bce78b2..8c086ee66921d79768daeecd9dec4047fbcba5ef 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
|
|
public 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);
|
|
}
|