From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 24 Mar 2019 01:01:32 -0400 Subject: [PATCH] Only count Natural Spawned mobs towards natural spawn mob limit This resolves the super common complaint about mobs not spawning. This was ultimately a flaw in the vanilla count algorithim that allows spawners and other misc mobs to count against the mob limit, which are not bounded, and can prevent the entire world from spawning new. I believe Bukkits changes around persistence may of actually made it worse than vanilla. This should fully solve all of the issues around it so that only natural influences natural spawns. diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java index 5589ee42959e3665dd5df9049fe108b6f6629608..e5365453655c0f394dea3d3b388afc24f7724b26 100644 --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java @@ -442,4 +442,15 @@ public class PaperWorldConfig { private void preventMovingIntoUnloadedChunks() { preventMovingIntoUnloadedChunks = getBoolean("prevent-moving-into-unloaded-chunks", false); } + + public boolean countAllMobsForSpawning = false; + private void countAllMobsForSpawning() { + countAllMobsForSpawning = getBoolean("count-all-mobs-for-spawning", false); + if (countAllMobsForSpawning) { + log("Counting all mobs for spawning. Mob farms may reduce natural spawns elsewhere in world."); + } else { + log("Using improved mob spawn limits (Only Natural Spawns impact spawn limits for more natural spawns)"); + } + } } + diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java index 41f13b52fdaba3c07aeafa17628861dcd7786556..474dc6302d2b0f8c629b2e1f6de9d4ba6faf398b 100644 --- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java +++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java @@ -87,6 +87,13 @@ public final class NaturalSpawner { MobCategory enumcreaturetype = entity.getType().getCategory(); if (enumcreaturetype != MobCategory.MISC) { + // Paper start - Only count natural spawns + if (!entity.level.paperConfig.countAllMobsForSpawning && + !(entity.spawnReason == org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL || + entity.spawnReason == org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CHUNK_GEN)) { + continue; + } + // Paper end BlockPos blockposition = entity.blockPosition(); chunkSource.query(ChunkPos.asLong(blockposition), (chunk) -> {