From 577ed2650eb2ca36af5c06a0a3f6c58c0965869f Mon Sep 17 00:00:00 2001 From: Taiyou06 Date: Fri, 23 May 2025 15:16:39 +0200 Subject: [PATCH] add ignoreSpawnRules to SpawnerSettings --- .../0133-Spawner-Configurations.patch | 44 +++++++++++++------ .../modules/gameplay/SpawnerSettings.java | 11 ++++- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/leaf-server/minecraft-patches/features/0133-Spawner-Configurations.patch b/leaf-server/minecraft-patches/features/0133-Spawner-Configurations.patch index e28ecea2..540bfe40 100644 --- a/leaf-server/minecraft-patches/features/0133-Spawner-Configurations.patch +++ b/leaf-server/minecraft-patches/features/0133-Spawner-Configurations.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Spawner Configurations diff --git a/net/minecraft/world/level/BaseSpawner.java b/net/minecraft/world/level/BaseSpawner.java -index 8c6f8cb08b247dcf497822ae991aa3afbcb784f1..9df9f4308c717db523d3c58e4d8dab7437984d02 100644 +index 8c6f8cb08b247dcf497822ae991aa3afbcb784f1..fd1c151958ec2535e56d2d04938803d586eeca8e 100644 --- a/net/minecraft/world/level/BaseSpawner.java +++ b/net/minecraft/world/level/BaseSpawner.java @@ -53,6 +53,12 @@ public abstract class BaseSpawner { @@ -58,7 +58,7 @@ index 8c6f8cb08b247dcf497822ae991aa3afbcb784f1..9df9f4308c717db523d3c58e4d8dab74 if (this.isNearPlayer(serverLevel, pos)) { if (this.spawnDelay < -tickDelay) { // Paper - Configurable mob spawner tick rate this.delay(serverLevel, pos); -@@ -107,18 +136,43 @@ public abstract class BaseSpawner { +@@ -107,18 +136,49 @@ public abstract class BaseSpawner { double d = size >= 1 ? list.getDouble(0) : pos.getX() + (random.nextDouble() - random.nextDouble()) * this.spawnRange + 0.5; double d1 = size >= 2 ? list.getDouble(1) : pos.getY() + random.nextInt(3) - 1; double d2 = size >= 3 ? list.getDouble(2) : pos.getZ() + (random.nextDouble() - random.nextDouble()) * this.spawnRange + 0.5; @@ -69,8 +69,11 @@ index 8c6f8cb08b247dcf497822ae991aa3afbcb784f1..9df9f4308c717db523d3c58e4d8dab74 + boolean skipBlockChecks = org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled && + !org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.spawnerBlockChecks; + if (skipBlockChecks || serverLevel.noCollision(optional.get().getSpawnAABB(d, d1, d2))) { - BlockPos blockPos = BlockPos.containing(d, d1, d2); ++ // 'skipBlockChecks' is true if SpawnerSettings.spawnerBlockChecks is false. ++ // It means we skip physical block checks like collision and custom rule isValidPosition. + + BlockPos blockPos = BlockPos.containing(d, d1, d2); ++ + // Add light level check if enabled + if (org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled && + org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.lightLevelCheck) { @@ -87,8 +90,9 @@ index 8c6f8cb08b247dcf497822ae991aa3afbcb784f1..9df9f4308c717db523d3c58e4d8dab74 + continue; + } + -+ // Handle spawn rules checks -+ boolean skipSpawnRules = false; ++ // Determine if mob-specific spawn rules (like block types, biome requirements) should be skipped ++ boolean skipMobSpecificRules = org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.enabled && ++ org.dreeam.leaf.config.modules.gameplay.SpawnerSettings.ignoreSpawnRules; + // Leaf end - Spawner Configurations if (nextSpawnData.getCustomSpawnRules().isPresent()) { if (!optional.get().getCategory().isFriendly() && serverLevel.getDifficulty() == Difficulty.PEACEFUL) { @@ -97,15 +101,17 @@ index 8c6f8cb08b247dcf497822ae991aa3afbcb784f1..9df9f4308c717db523d3c58e4d8dab74 SpawnData.CustomSpawnRules customSpawnRules = nextSpawnData.getCustomSpawnRules().get(); - if (!customSpawnRules.isValidPosition(blockPos, serverLevel)) { ++ // customSpawnRules.isValidPosition is controlled by spawnerBlockChecks (via !skipBlockChecks) + if (!skipBlockChecks && !customSpawnRules.isValidPosition(blockPos, serverLevel)) { // Leaf - Spawner Configurations continue; } - } else if (!SpawnPlacements.checkSpawnRules(optional.get(), serverLevel, EntitySpawnReason.SPAWNER, blockPos, serverLevel.getRandom())) { -+ } else if (!skipBlockChecks && !SpawnPlacements.checkSpawnRules(optional.get(), serverLevel, EntitySpawnReason.SPAWNER, blockPos, serverLevel.getRandom())) { // Leaf - Spawner Configurations ++ } else if (!skipMobSpecificRules && !SpawnPlacements.checkSpawnRules(optional.get(), serverLevel, EntitySpawnReason.SPAWNER, blockPos, serverLevel.getRandom())) { ++ // If not skipping mob-specific rules AND standard spawn rules fail, continue. continue; } -@@ -146,6 +200,7 @@ public abstract class BaseSpawner { +@@ -146,6 +206,7 @@ public abstract class BaseSpawner { return; } @@ -113,7 +119,7 @@ index 8c6f8cb08b247dcf497822ae991aa3afbcb784f1..9df9f4308c717db523d3c58e4d8dab74 int size1 = serverLevel.getEntities( EntityTypeTest.forExactClass(entity.getClass()), new AABB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1).inflate(this.spawnRange), -@@ -156,12 +211,16 @@ public abstract class BaseSpawner { +@@ -156,12 +217,28 @@ public abstract class BaseSpawner { this.delay(serverLevel, pos); return; } @@ -125,14 +131,26 @@ index 8c6f8cb08b247dcf497822ae991aa3afbcb784f1..9df9f4308c717db523d3c58e4d8dab74 - if (nextSpawnData.getCustomSpawnRules().isEmpty() && !mob.checkSpawnRules(serverLevel, EntitySpawnReason.SPAWNER) - || !mob.checkSpawnObstruction(serverLevel)) { + // Leaf start - Spawner Configurations -+ // Skip spawn rule and obstruction checks if block checks are disabled -+ if (!skipBlockChecks && (nextSpawnData.getCustomSpawnRules().isEmpty() && !mob.checkSpawnRules(serverLevel, EntitySpawnReason.SPAWNER) -+ || !mob.checkSpawnObstruction(serverLevel))) { -+ // Leaf end - Spawner Configurations ++ // mob.checkSpawnRules is controlled by ignoreSpawnRules (via !skipMobSpecificRules) ++ // mob.checkSpawnObstruction is controlled by spawnerBlockChecks (via !skipBlockChecks) ++ ++ boolean mobSpecificRulesFailed = false; ++ if (nextSpawnData.getCustomSpawnRules().isEmpty() && !skipMobSpecificRules) { ++ if (!mob.checkSpawnRules(serverLevel, EntitySpawnReason.SPAWNER)) { ++ mobSpecificRulesFailed = true; ++ } ++ } ++ ++ boolean obstructionFailed = false; ++ if (!skipBlockChecks && !mob.checkSpawnObstruction(serverLevel)) { // If not skipping physical checks and obstruction fails ++ obstructionFailed = true; ++ } ++ ++ if (mobSpecificRulesFailed || obstructionFailed) { continue; } -@@ -249,6 +308,13 @@ public abstract class BaseSpawner { +@@ -249,6 +326,13 @@ public abstract class BaseSpawner { this.spawnPotentials = SimpleWeightedRandomList.single(this.nextSpawnData != null ? this.nextSpawnData : new SpawnData()); } diff --git a/leaf-server/src/main/java/org/dreeam/leaf/config/modules/gameplay/SpawnerSettings.java b/leaf-server/src/main/java/org/dreeam/leaf/config/modules/gameplay/SpawnerSettings.java index 31e81d18..7a9c0aa9 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/config/modules/gameplay/SpawnerSettings.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/config/modules/gameplay/SpawnerSettings.java @@ -18,6 +18,7 @@ public class SpawnerSettings extends ConfigModules { public static boolean checkForNearbyPlayers = true; public static boolean spawnerBlockChecks = false; public static boolean waterPreventSpawnCheck = false; + public static boolean ignoreSpawnRules = false; public static int minSpawnDelay = 200; public static int maxSpawnDelay = 800; @@ -60,8 +61,8 @@ public class SpawnerSettings extends ConfigModules { spawnerBlockChecks = config.getBoolean(getBasePath() + ".checks.spawner-block-checks", spawnerBlockChecks, config.pickStringRegionBased( - "Check if there are blocks blocking the spawner to spawn the mob", - "检查是否有方块阻挡刷怪笼生成怪物" + "Check if there are physical blocks obstructing the spawn location, or if custom spawn rules (isValidPosition) fail due to block conditions.", + "检查是否有物理方块阻挡生成位置, 或自定义生成规则(isValidPosition)因方块条件失败." )); waterPreventSpawnCheck = config.getBoolean(getBasePath() + ".checks.water-prevent-spawn-check", waterPreventSpawnCheck, @@ -70,6 +71,12 @@ public class SpawnerSettings extends ConfigModules { "检查周围是否有水阻止生成" )); + ignoreSpawnRules = config.getBoolean(getBasePath() + ".checks.ignore-spawn-rules", ignoreSpawnRules, + config.pickStringRegionBased( + "Ignore mob-specific spawn rules, like animals needing grass or specific biomes/blocks (does not affect light level or physical obstruction checks).", + "忽略特定于生物的生成规则, 例如动物需要草方块或特定的生物群系/方块 (不影响光照等级或物理障碍物检查)." + )); + // Delay settings minSpawnDelay = config.getInt(getBasePath() + ".min-spawn-delay", minSpawnDelay,