Paper/Spigot-Server-Patches/0385-Only-count-Natural-Spawned-mobs-towards-natural-spaw.patch
Aikar a054aa6f02
Properly remove Entities from current chunk
We store a reference to the chunk the entity is currently in, so use it
to more accurately unregister it in chunkCheck

Should maybe fix some entity loss issues.
2020-05-10 05:52:31 -04:00

58 lines
2.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
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 ca2ac17747d4f2acf1df056759c5c182be050125..a3fc76b512244ed6ca6b4d8f4babcb81f3cce226 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -505,6 +505,16 @@ public class PaperWorldConfig {
maxAutoSaveChunksPerTick = getInt("max-auto-save-chunks-per-tick", 24);
}
+ 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)");
+ }
+ }
+
public boolean antiXray;
public boolean asynchronous;
public EngineMode engineMode;
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 46ad4612a1bd5ab005450645f69b0cb9f6f18aa7..6af8aeae5d1312c526622bc7e74e977dcb29a5b0 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -960,6 +960,13 @@ public class WorldServer extends World {
EnumCreatureType enumcreaturetype = entity.getEntityType().e();
if (enumcreaturetype != EnumCreatureType.MISC && this.getChunkProvider().b(entity)) {
+ // Paper start - Only count natural spawns
+ if (!this.paperConfig.countAllMobsForSpawning &&
+ !(entity.spawnReason == CreatureSpawnEvent.SpawnReason.NATURAL ||
+ entity.spawnReason == CreatureSpawnEvent.SpawnReason.CHUNK_GEN)) {
+ continue;
+ }
+ // Paper end
object2intmap.mergeInt(enumcreaturetype, 1, Integer::sum);
}
}