diff --git a/Minecraft.Server/ServerProperties.cpp b/Minecraft.Server/ServerProperties.cpp index 711ebe10..1b6c5c0a 100644 --- a/Minecraft.Server/ServerProperties.cpp +++ b/Minecraft.Server/ServerProperties.cpp @@ -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); diff --git a/Minecraft.Server/ServerProperties.h b/Minecraft.Server/ServerProperties.h index 0e6f8813..fd251fc3 100644 --- a/Minecraft.Server/ServerProperties.h +++ b/Minecraft.Server/ServerProperties.h @@ -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; diff --git a/Minecraft.Server/Windows64/ServerMain.cpp b/Minecraft.Server/Windows64/ServerMain.cpp index ad46300d..d8d9e0a1 100644 --- a/Minecraft.Server/Windows64/ServerMain.cpp +++ b/Minecraft.Server/Windows64/ServerMain.cpp @@ -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 #include @@ -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(); diff --git a/Minecraft.World/MobCategory.cpp b/Minecraft.World/MobCategory.cpp index 8c6d3b44..fc45d844 100644 --- a/Minecraft.World/MobCategory.cpp +++ b/Minecraft.World/MobCategory.cpp @@ -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; diff --git a/Minecraft.World/MobCategory.h b/Minecraft.World/MobCategory.h index 4fe5c826..1b33b9df 100644 --- a/Minecraft.World/MobCategory.h +++ b/Minecraft.World/MobCategory.h @@ -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();