feat: configurable mob spawn caps via server.properties

This commit is contained in:
itsRevela 2026-04-18 09:31:45 -05:00
parent c297b26f36
commit ffdad03aca
5 changed files with 40 additions and 2 deletions

View file

@ -888,6 +888,14 @@ ServerPropertiesConfig LoadServerPropertiesConfig()
config.hardcore = ReadNormalizedBoolProperty(&merged, "hardcore", false, &shouldWrite);
config.hardcoreBanIp = ReadNormalizedBoolProperty(&merged, "hardcore-ban-ip", false, &shouldWrite);
config.maxMonsters = ReadNormalizedIntProperty(&merged, "max-monsters", 50, 0, 1000, &shouldWrite);
config.maxAnimals = ReadNormalizedIntProperty(&merged, "max-animals", 50, 0, 1000, &shouldWrite);
config.maxAmbient = ReadNormalizedIntProperty(&merged, "max-ambient", 20, 0, 1000, &shouldWrite);
config.maxWaterAnimals = ReadNormalizedIntProperty(&merged, "max-water-animals", 5, 0, 1000, &shouldWrite);
config.maxWolves = ReadNormalizedIntProperty(&merged, "max-wolves", 8, 0, 1000, &shouldWrite);
config.maxChickens = ReadNormalizedIntProperty(&merged, "max-chickens", 8, 0, 1000, &shouldWrite);
config.maxMushroomCows = ReadNormalizedIntProperty(&merged, "max-mushroom-cows", 2, 0, 1000, &shouldWrite);
config.maxBuildHeight = ReadNormalizedIntProperty(&merged, "max-build-height", 256, 64, 256, &shouldWrite);
config.motd = ReadNormalizedStringProperty(&merged, "motd", "A Minecraft Server", 255, &shouldWrite);

View file

@ -80,6 +80,21 @@ namespace ServerRuntime
/** `hardcore-ban-ip` — whether hardcore death bans include IP bans */
bool hardcoreBanIp;
/** `max-monsters` natural spawn cap for monsters (zombies, skeletons, creepers, etc.) */
int maxMonsters;
/** `max-animals` natural spawn cap for animals (cows, sheep, pigs) */
int maxAnimals;
/** `max-ambient` natural spawn cap for ambient mobs (bats) */
int maxAmbient;
/** `max-water-animals` natural spawn cap for water mobs (squid) */
int maxWaterAnimals;
/** `max-wolves` natural spawn cap for wolves */
int maxWolves;
/** `max-chickens` natural spawn cap for chickens */
int maxChickens;
/** `max-mushroom-cows` natural spawn cap for mooshrooms */
int maxMushroomCows;
/** security settings */
/** `hide-player-list-prelogin` — strip XUIDs from PreLoginPacket response */
bool hidePlayerListPreLogin;

View file

@ -37,6 +37,7 @@
#include "../../Minecraft.World/ConsoleSaveFileOriginal.h"
#include "../../Minecraft.World/net.minecraft.world.level.tile.h"
#include "../../Minecraft.World/Random.h"
#include "../../Minecraft.World/MobCategory.h"
#include <stdio.h>
#include <stdlib.h>
@ -557,10 +558,18 @@ int main(int argc, char **argv)
{
LogError("startup", "Minecraft initialization failed.");
CleanupDevice();
return 3;
}
MobCategory::monster->setMaxInstancesPerLevel(serverProperties.maxMonsters);
MobCategory::creature->setMaxInstancesPerLevel(serverProperties.maxAnimals);
MobCategory::ambient->setMaxInstancesPerLevel(serverProperties.maxAmbient);
MobCategory::waterCreature->setMaxInstancesPerLevel(serverProperties.maxWaterAnimals);
MobCategory::creature_wolf->setMaxInstancesPerLevel(serverProperties.maxWolves);
MobCategory::creature_chicken->setMaxInstancesPerLevel(serverProperties.maxChickens);
MobCategory::creature_mushroomcow->setMaxInstancesPerLevel(serverProperties.maxMushroomCows);
app.InitGameSettings();
MinecraftServer::resetFlags();

View file

@ -58,6 +58,11 @@ int MobCategory::getMaxInstancesPerLevel() // 4J added
return m_maxPerLevel;
}
void MobCategory::setMaxInstancesPerLevel(int max)
{
m_maxPerLevel = max;
}
Material *MobCategory::getSpawnPositionMaterial()
{
return (Material *) spawnPositionMaterial;

View file

@ -65,7 +65,7 @@ public:
private:
const int m_max;
const int m_maxPerLevel;
int m_maxPerLevel;
const Material *spawnPositionMaterial;
const bool m_isFriendly;
const bool m_isPersistent;
@ -79,6 +79,7 @@ public:
const eINSTANCEOF getEnumBaseClass(); // 4J added
int getMaxInstancesPerChunk();
int getMaxInstancesPerLevel(); // 4J added
void setMaxInstancesPerLevel(int max); // 4J added
Material *getSpawnPositionMaterial();
bool isFriendly();
bool isSingleType();