Skip to content

Commit

Permalink
Add option to change crops to go from first age to last age directly,…
Browse files Browse the repository at this point in the history
… to avoid useless block updates
  • Loading branch information
MrPowerGamerBR committed Nov 21, 2023
1 parent d80994b commit 96c5de6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SparklyPaper's config file is `sparklypaper.yml`, the file is, by default, place
* If a farm land is moisturised, the farm land won't check if there's water nearby to avoid intensive block checks. Now, instead of the farm land checking for moisture, the crops themselves will check when attempting to grow, this way, farms with fully grown crops won't cause lag.
* The growth speed of crops and stems are now fixed based on if the block below them is moist or not, instead of doing vanilla's behavior of "check all blocks nearby to see if at least one of them is moist" and "if the blocks nearby are of the same time, make them grow slower".
* In my opinion: Who cares about the vanilla behavior lol, most players only care about farm land + crop = crop go brrrr
* Another optimization is that crop behavior can be changed to skip from age zero to the last age directly, while still keeping the original growth duration of the crop. This way, useless block updates due to crop growth can be avoided!
* Lazily create `LootContext` for criterions
* For each player on each tick, enter block triggers are invoked, and these create loot contexts that are promptly thrown away since the trigger doesn't pass the predicate.
* To avoid this, we now lazily create the LootContext if the criterion passes the predicate AND if any of the listener triggers require a loot context instance.
Expand Down
19 changes: 11 additions & 8 deletions patches/server/0002-SparklyPaper-config-files.patch
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ index 0000000000000000000000000000000000000000..6398c7b40ba82ffc8588eca458ce92c2
\ No newline at end of file
diff --git a/src/main/kotlin/net/sparklypower/sparklypaper/configs/SparklyPaperConfigUtils.kt b/src/main/kotlin/net/sparklypower/sparklypaper/configs/SparklyPaperConfigUtils.kt
new file mode 100644
index 0000000000000000000000000000000000000000..250b19027db75b1ba44383621215fd2c3370c967
index 0000000000000000000000000000000000000000..155ef71c119ebeb95fdfae9e681520b91874ba8e
--- /dev/null
+++ b/src/main/kotlin/net/sparklypower/sparklypaper/configs/SparklyPaperConfigUtils.kt
@@ -0,0 +1,55 @@
@@ -0,0 +1,56 @@
+package net.sparklypower.sparklypaper.configs
+
+import com.charleskorn.kaml.Yaml
Expand Down Expand Up @@ -257,9 +257,10 @@ index 0000000000000000000000000000000000000000..250b19027db75b1ba44383621215fd2c
+ "default" to SparklyPaperWorldConfig(
+ skipMapItemDataUpdatesIfMapDoesNotHaveCraftMapRenderer = true,
+ blazinglySimpleFarmChecks = SparklyPaperWorldConfig.BlazinglySimpleFarmChecks(
+ false,
+ 1.0f,
+ 5.0f,
+ enabled = false,
+ defaultGrowthSpeed = 1.0f,
+ moistGrowthSpeed = 5.0f,
+ skipMiddleAgingStagesForCrops = true
+ ),
+ SparklyPaperWorldConfig.TickRates(
+ farmWhenMoisturised = 1
Expand Down Expand Up @@ -287,10 +288,10 @@ index 0000000000000000000000000000000000000000..250b19027db75b1ba44383621215fd2c
\ No newline at end of file
diff --git a/src/main/kotlin/net/sparklypower/sparklypaper/configs/SparklyPaperWorldConfig.kt b/src/main/kotlin/net/sparklypower/sparklypaper/configs/SparklyPaperWorldConfig.kt
new file mode 100644
index 0000000000000000000000000000000000000000..41f2482097d7b835dcec85bb33ab0ce5f6f48eec
index 0000000000000000000000000000000000000000..d2c53262581710d2ca4b588331fe54458015bfe8
--- /dev/null
+++ b/src/main/kotlin/net/sparklypower/sparklypaper/configs/SparklyPaperWorldConfig.kt
@@ -0,0 +1,29 @@
@@ -0,0 +1,31 @@
+package net.sparklypower.sparklypaper.configs
+
+import kotlinx.serialization.SerialName
Expand All @@ -311,7 +312,9 @@ index 0000000000000000000000000000000000000000..41f2482097d7b835dcec85bb33ab0ce5
+ @SerialName("default-growth-speed")
+ val defaultGrowthSpeed: Float,
+ @SerialName("moist-growth-speed")
+ val moistGrowthSpeed: Float
+ val moistGrowthSpeed: Float,
+ @SerialName("skip-middle-aging-stages-for-crops")
+ val skipMiddleAgingStagesForCrops: Boolean
+ )
+
+ @Serializable
Expand Down
13 changes: 9 additions & 4 deletions patches/server/0011-Blazingly-Simple-Farm-Checks.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Blazingly Simple Farm Checks


diff --git a/src/main/java/net/minecraft/world/level/block/CropBlock.java b/src/main/java/net/minecraft/world/level/block/CropBlock.java
index 6365ddea0c23bc5d4009d98915f2b39aed2a0328..0c210c7788a45c672abed20175dfc05bfea89d34 100644
index 6365ddea0c23bc5d4009d98915f2b39aed2a0328..41a0a22bf28eec79bc6dd96622789a2fd2ec646d 100644
--- a/src/main/java/net/minecraft/world/level/block/CropBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/CropBlock.java
@@ -74,6 +74,52 @@ public class CropBlock extends BushBlock implements BonemealableBlock {
@@ -74,6 +74,57 @@ public class CropBlock extends BushBlock implements BonemealableBlock {
int i = this.getAge(state);

if (i < this.getMaxAge()) {
Expand All @@ -27,7 +27,12 @@ index 6365ddea0c23bc5d4009d98915f2b39aed2a0328..0c210c7788a45c672abed20175dfc05b
+ isCurrentFarmlandStateMoist = true;
+ }
+ }
+
+ // If we are skipping the middle aging stages, we need to change the growth speed and the next stage accordingly
+ if (world.sparklyPaperConfig.getBlazinglySimpleFarmChecks().getSkipMiddleAgingStagesForCrops()) {
+ f = f / getMaxAge();
+ i = getMaxAge() - 1;
+ }
+
+ // Spigot start
+ int modifier;
+ if (this == Blocks.BEETROOTS) {
Expand Down Expand Up @@ -61,7 +66,7 @@ index 6365ddea0c23bc5d4009d98915f2b39aed2a0328..0c210c7788a45c672abed20175dfc05b
float f = CropBlock.getGrowthSpeed(this, world, pos);

// Spigot start
@@ -96,6 +142,8 @@ public class CropBlock extends BushBlock implements BonemealableBlock {
@@ -96,6 +147,8 @@ public class CropBlock extends BushBlock implements BonemealableBlock {
// Spigot end
CraftEventFactory.handleBlockGrowEvent(world, pos, this.getStateForAge(i + 1), 2); // CraftBukkit
}
Expand Down

0 comments on commit 96c5de6

Please sign in to comment.