aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0338-Only-count-Natural-Spawned-mobs-towards-natural-spaw.patch
blob: 0d526cc3fc6d54ca5e66013796c38e002b85b07d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 3816623fa85db14a89bd165221695de1a39e70c0..9d52060319e6a0403c9979766c761e2f5324f6aa 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -406,4 +406,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 c8b9877135aebf1f500ab9b00d94dde0e846d247..eeefd5b5d1cd4c1b38e706210fd0e56b17969b18 100644
--- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java
+++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java
@@ -85,6 +85,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();
                 long j = ChunkPos.asLong(SectionPos.blockToSectionCoord(blockposition.getX()), SectionPos.blockToSectionCoord(blockposition.getZ()));