From 38658070f5c82b4310e6abb682c2caccac33201d Mon Sep 17 00:00:00 2001 From: hayanesuru Date: Thu, 3 Jul 2025 17:23:50 +0900 Subject: [PATCH] add comment throttle mob spawning --- .../features/0263-throttle-mob-spawning.patch | 4 ++-- .../modules/opt/ThrottleNaturalMobSpawning.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/leaf-server/minecraft-patches/features/0263-throttle-mob-spawning.patch b/leaf-server/minecraft-patches/features/0263-throttle-mob-spawning.patch index de72975d..12a677b8 100644 --- a/leaf-server/minecraft-patches/features/0263-throttle-mob-spawning.patch +++ b/leaf-server/minecraft-patches/features/0263-throttle-mob-spawning.patch @@ -5,7 +5,7 @@ Subject: [PATCH] throttle mob spawning diff --git a/net/minecraft/world/level/NaturalSpawner.java b/net/minecraft/world/level/NaturalSpawner.java -index ab6fa7ed111ef16a0b6774c21988589ee2110c66..f3bed4b372f858656dbf51fb0140260bad4a41be 100644 +index ab6fa7ed111ef16a0b6774c21988589ee2110c66..b1220364424db2e0dce58c5a0f6334e2e9f06dec 100644 --- a/net/minecraft/world/level/NaturalSpawner.java +++ b/net/minecraft/world/level/NaturalSpawner.java @@ -215,6 +215,17 @@ public final class NaturalSpawner { @@ -18,7 +18,7 @@ index ab6fa7ed111ef16a0b6774c21988589ee2110c66..f3bed4b372f858656dbf51fb0140260b + long failedAttempt = org.dreeam.leaf.config.modules.opt.ThrottleNaturalMobSpawning.failedAttempts[mobCategory.ordinal()]; + if (failedAttempt >= 0L + && chunk.failedSpawnAttempts[mobCategory.ordinal()] >= failedAttempt -+ && (level.random.nextInt() & 1023) > spawnChance) { ++ && (level.random.nextInt() & Integer.MAX_VALUE) >= spawnChance) { + continue; + } + } diff --git a/leaf-server/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleNaturalMobSpawning.java b/leaf-server/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleNaturalMobSpawning.java index 8dbcff11..6b4fae1a 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleNaturalMobSpawning.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleNaturalMobSpawning.java @@ -15,6 +15,14 @@ public class ThrottleNaturalMobSpawning extends ConfigModules { @Override public void onLoaded() { + config.addCommentRegionBased(getBasePath(), """ + Skip mob spawning for chunks with repeated failures exceeding `min-failed`. + Randomly skip 1-`spawn-chance`% of these chunks from spawning attempts. + Failure counter does not increment when spawn limits are reached.""", + """ + 跳过区块中重复失败次数超过 `min-failed` 的生物生成. + 随机跳过这些区块中 1-`spawn-chance`% 的生物生成尝试. + 达到生成限制时, 失败计数器不会增加."""); enabled = config.getBoolean(getBasePath() + ".enabled", enabled); MobCategory[] categories = MobCategory.values(); failedAttempts = new long[categories.length]; @@ -25,7 +33,8 @@ public class ThrottleNaturalMobSpawning extends ConfigModules { double chance = config.getDouble(category + ".spawn-chance", 25.0); failedAttempts[i] = Math.max(-1, attempts); - spawnChance[i] = Math.clamp(0, (int) Math.round(chance * 10.24), 1024); + chance = Math.clamp(chance, 0.0, 100.0) / 100.0; + spawnChance[i] = Math.toIntExact(Math.round((chance * Integer.MAX_VALUE))); } } }