2021-06-11 14:02:28 +02: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-05-07 07:57:41 +02:00
index 5015a49861bf6dfe32ba86415f22a7b3fd13aa9b..bf0ee7904c6c58a2bc44279be03fdf28abbabbc2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2021-11-29 12:55:13 +01:00
@@ -53,6 +53,11 @@ public class PaperWorldConfig {
2021-11-09 08:59:15 +01: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);
}
if (needsSave) {
2022-05-07 07:57:41 +02:00
@@ -685,6 +690,21 @@ public class PaperWorldConfig {
2021-06-11 14:02:28 +02:00
zombieVillagerInfectionChance = getDouble("zombie-villager-infection-chance", zombieVillagerInfectionChance);
}
2021-11-29 12:55:13 +01:00
+ public Reference2IntMap<MobCategory> perWorldSpawnLimits = new Reference2IntOpenHashMap<>(net.minecraft.world.level.NaturalSpawner.SPAWNING_CATEGORIES.length);
2021-06-11 14:02:28 +02:00
+ private void perWorldSpawnLimits() {
2021-11-09 08:59:15 +01: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 12:55:13 +01:00
+ for (MobCategory value : net.minecraft.world.level.NaturalSpawner.SPAWNING_CATEGORIES) {
2021-11-09 08:59:15 +01:00
+ perWorldSpawnLimits.put(value, getInt("spawn-limits." + value.getName(), perWorldSpawnLimits.getInt(value)));
+ }
2021-06-11 14:02:28 +02: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-05-06 17:52:14 +02:00
index 3dac97ce8f744dc289f4a0555db1a95204287a4a..e84f352280fbdbda194f5b151f942d6d6718dc40 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2022-03-01 06:43:03 +01:00
@@ -221,6 +221,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2021-08-25 09:59:26 +02:00
this.biomeProvider = biomeProvider;
2021-06-11 14:02:28 +02:00
2021-06-15 06:55:46 +02:00
this.environment = env;
2021-06-11 14:02:28 +02:00
+ // Paper start - per world spawn limits
2022-02-12 14:20:33 +01:00
+ for (SpawnCategory spawnCategory : SpawnCategory.values()) {
+ if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
+ setSpawnLimit(spawnCategory, this.world.paperConfig.perWorldSpawnLimits.getInt(CraftSpawnCategory.toNMS(spawnCategory)));
+ }
+ }
2021-06-11 14:02:28 +02:00
+ // Paper end
}
@Override