Add global and per-player mob caps

This commit is contained in:
cora 2022-10-13 06:27:04 +02:00
parent cd862888d1
commit ea48be3f4c
3 changed files with 22 additions and 6 deletions

View File

@ -30,11 +30,13 @@ local dbg_spawn_counts = {}
local aoc_range = 136
local mob_cap = {
monster = minetest.settings:get_bool("mcl_mob_cap_monster") or 70,
animal = minetest.settings:get_bool("mcl_mob_cap_animal") or 10,
ambient = minetest.settings:get_bool("mcl_mob_cap_ambient") or 15,
water = minetest.settings:get_bool("mcl_mob_cap_water") or 5, --currently unused
water_ambient = minetest.settings:get_bool("mcl_mob_cap_water_ambient") or 20, --currently unused
monster = tonumber(minetest.settings:get("mcl_mob_cap_monster")) or 70,
animal = tonumber(minetest.settings:get("mcl_mob_cap_animal")) or 10,
ambient = tonumber(minetest.settings:get("mcl_mob_cap_ambient")) or 15,
water = tonumber(minetest.settings:get("mcl_mob_cap_water")) or 5, --currently unused
water_ambient = tonumber(minetest.settings:get("mcl_mob_cap_water_ambient")) or 20, --currently unused
player = tonumber(minetest.settings:get("mcl_mob_cap_player")) or 75,
total = tonumber(minetest.settings:get("mcl_mob_cap_total")) or 500,
}
--do mobs spawn?
@ -664,7 +666,13 @@ if mobs_spawn then
timer = timer + dtime
if timer < 10 then return end
timer = 0
for _, player in pairs(get_connected_players()) do
local players = get_connected_players()
local total_mobs = count_mobs_total()
if total_mobs > mob_cap.total or total_mobs > #players * mob_cap.player then
minetest.log("warning","[mcl_mobs] mob cap reached. no cycle spawning.")
return
end --mob cap per player
for _, player in pairs(players) do
local pos = player:get_pos()
local dimension = mcl_worlds.pos_to_dimension(pos)
-- ignore void and unloaded area

View File

@ -11,6 +11,8 @@ local cow_def = {
xp_min = 1,
xp_max = 3,
collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.39, 0.45},
spawn_in_group = 8,
spawn_in_group_min = 3,
visual = "mesh",
mesh = "mobs_mc_cow.b3d",
textures = { {

View File

@ -99,6 +99,12 @@ mobs_griefing (Mobs change blocks) bool true
# If enabled, mobs won't damage particles when they got hurt.
mobs_disable_blood (Disable mob damage particles) bool false
#Maximum amount mobs (default:500)
mcl_mob_cap_total (Global mob cap) int 500 0 2048
#Maximum amount of mobs per player (default:75)
mcl_mob_cap_player (Mob cap per player) int 75 0 2048
#Maximum amount of monsters that will spawn near a player (default:70)
mcl_mob_cap_monster (Mob cap monsters) int 70 0 2048