From 96c5de6f94ac7fd03410dd3ed5baff30fbb0e021 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Tue, 21 Nov 2023 16:14:45 -0300 Subject: [PATCH] Add option to change crops to go from first age to last age directly, to avoid useless block updates --- README.md | 1 + .../0002-SparklyPaper-config-files.patch | 19 +++++++++++-------- .../0011-Blazingly-Simple-Farm-Checks.patch | 13 +++++++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 46f82d6..65238fc 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/patches/server/0002-SparklyPaper-config-files.patch b/patches/server/0002-SparklyPaper-config-files.patch index c71e69b..e773edd 100644 --- a/patches/server/0002-SparklyPaper-config-files.patch +++ b/patches/server/0002-SparklyPaper-config-files.patch @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/patches/server/0011-Blazingly-Simple-Farm-Checks.patch b/patches/server/0011-Blazingly-Simple-Farm-Checks.patch index d86c46b..d77c86b 100644 --- a/patches/server/0011-Blazingly-Simple-Farm-Checks.patch +++ b/patches/server/0011-Blazingly-Simple-Farm-Checks.patch @@ -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()) { @@ -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) { @@ -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 }