9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-28 19:29:07 +00:00

Add option to use random chance for crop growth instead of age

This commit is contained in:
Samsuik
2024-05-16 21:25:33 +01:00
parent be0689c7f0
commit e6a141c680
2 changed files with 75 additions and 2 deletions

View File

@@ -647,10 +647,10 @@ index 0000000000000000000000000000000000000000..f8770f97e3ad6c2746bc436b2b2c895c
+}
diff --git a/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java b/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..0d015331a5143a0e45c4576e1ba51e50b2d46d87
index 0000000000000000000000000000000000000000..12cbf3e424a0d3218d7e8c5ea37c32ff3bad4e98
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java
@@ -0,0 +1,199 @@
@@ -0,0 +1,204 @@
+package me.samsuik.sakura.configuration;
+
+import com.mojang.logging.LogUtils;
@@ -841,6 +841,11 @@ index 0000000000000000000000000000000000000000..0d015331a5143a0e45c4576e1ba51e50
+ public boolean legacyBlockFormation = false;
+ }
+
+ public Crops crops = new Crops();
+ public class Crops extends ConfigurationPart {
+ public boolean useRandomChanceToGrow = false;
+ }
+
+ public MobSpawner mobSpawner = new MobSpawner();
+ public class MobSpawner extends ConfigurationPart {
+ public boolean checkSpawnConditions = true;

View File

@@ -0,0 +1,68 @@
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..41f5f1c0d262fd9905d006b7dbdc0cb05a8ec010 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,18 @@ 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;
+ }
+ world.setBlock(pos, state.setValue(CactusBlock.AGE, AGE.max), 16);
+ }
+ 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)) {
@@ -71,6 +83,7 @@ public class CactusBlock extends Block {
world.setBlock(pos, iblockdata1, 4);
world.neighborChanged(iblockdata1, blockposition1, this, pos, false);
+ // 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(CactusBlock.AGE, j + 1), 4);
}
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..b6cd8d19aee81d0248413cab7ac91e00544b9ccb 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,18 @@ 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;
+ }
+ world.setBlock(pos, state.setValue(SugarCaneBlock.AGE, AGE.max), 16);
+ }
+ 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 +78,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);
}