2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: chase <chasewhip20@gmail.com>
Date: Wed, 2 Dec 2020 22:43:39 -0800
Subject: [PATCH] add per world spawn limits
Taken from #2982. Credit to Chasewhip8
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2022-06-06 00:17:27 +00:00
index b68c2f46c7b595fe860f609b5681524ba310003e..1ae2e1599cb5b8612ca5b45c37367377d7f26dbf 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2022-05-07 16:47:28 +00:00
@@ -58,6 +58,11 @@ public class PaperWorldConfig {
2021-11-09 07:59:15 +00:00
set("despawn-ranges.soft", null);
set("despawn-ranges.hard", null);
+
+ set("spawn-limits.monsters", null);
+ set("spawn-limits.animals", null);
+ set("spawn-limits.water-animals", null);
+ set("spawn-limits.water-ambient", null);
}
2022-06-06 00:17:27 +00:00
if (this.config.isSet("world-settings.default.treasure-maps-return-already-discovered") || this.config.isSet("world-settings." + worldName + ".treasure-maps-return-already-discovered")) {
@@ -735,6 +740,21 @@ public class PaperWorldConfig {
2021-06-11 12:02:28 +00:00
zombieVillagerInfectionChance = getDouble("zombie-villager-infection-chance", zombieVillagerInfectionChance);
}
2021-11-29 11:55:13 +00:00
+ public Reference2IntMap<MobCategory> perWorldSpawnLimits = new Reference2IntOpenHashMap<>(net.minecraft.world.level.NaturalSpawner.SPAWNING_CATEGORIES.length);
2021-06-11 12:02:28 +00:00
+ private void perWorldSpawnLimits() {
2021-11-09 07:59:15 +00:00
+ perWorldSpawnLimits.defaultReturnValue(-1);
+ if (PaperConfig.version < 24) {
+ // ambient category already had correct name
+ perWorldSpawnLimits.put(MobCategory.MONSTER, getInt("spawn-limits.monsters", -1, false));
+ perWorldSpawnLimits.put(MobCategory.CREATURE, getInt("spawn-limits.animals", -1, false));
+ perWorldSpawnLimits.put(MobCategory.WATER_CREATURE, getInt("spawn-limits.water-animals", -1, false));
+ perWorldSpawnLimits.put(MobCategory.WATER_AMBIENT, getInt("spawn-limits.water-ambient", -1, false));
+ }
2021-11-29 11:55:13 +00:00
+ for (MobCategory value : net.minecraft.world.level.NaturalSpawner.SPAWNING_CATEGORIES) {
2021-11-09 07:59:15 +00:00
+ perWorldSpawnLimits.put(value, getInt("spawn-limits." + value.getName(), perWorldSpawnLimits.getInt(value)));
+ }
2021-06-11 12:02:28 +00:00
+ }
+
public int lightQueueSize = 20;
private void lightQueueSize() {
lightQueueSize = getInt("light-queue-size", lightQueueSize);
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2022-06-08 09:31:06 +00:00
index 792d660b10c841876a87625f8da1910a86542ec3..1274bc5324f8cbf1ae8d37190eafeb8cb9b6e233 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2022-06-05 20:51:44 +00:00
@@ -205,6 +205,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2021-08-25 07:59:26 +00:00
this.biomeProvider = biomeProvider;
2021-06-11 12:02:28 +00:00
2021-06-15 04:55:46 +00:00
this.environment = env;
2021-06-11 12:02:28 +00:00
+ // Paper start - per world spawn limits
2022-02-12 13:20:33 +00:00
+ for (SpawnCategory spawnCategory : SpawnCategory.values()) {
+ if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
+ setSpawnLimit(spawnCategory, this.world.paperConfig.perWorldSpawnLimits.getInt(CraftSpawnCategory.toNMS(spawnCategory)));
+ }
+ }
2021-06-11 12:02:28 +00:00
+ // Paper end
}
@Override