From c20a7def3f446b6577a0e0810eae84ba3aca23fe Mon Sep 17 00:00:00 2001 From: j-r Date: Fri, 1 Dec 2023 17:14:56 +0100 Subject: [PATCH] ENTITIES/mcl_mobs: fix broken passive mob timer The timer has to be decremented by the full time elapsed since the last call, but check_timer isn't called on every invocation of the globalstep function and therefore misses time. Decrement it directly in the globalstep function instead. Previously check_timer seems to have assumed to be called with the spawn_class as parameter (called mob_type, though), but actually it is called on the spawn definition, leading to always returning true. Instead retrieve spawn class from mob def found in registry. The timer reset logic was reset even on non passive mobs, erronously reducing the chance of spawning passive mobs. (Not noticable because logic couldn't identify passive mobs correctly.) Also PASSIVE_INTERVAL had been set to 200 instead of the 20 seconds documented in the minecraft wiki. Change that, too. --- mods/ENTITIES/mcl_mobs/spawning.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index 800e322d1..dd5110527 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -10,7 +10,7 @@ local overworld_threshold = tonumber(minetest.settings:get("mcl_mobs_overworld_t local overworld_sky_threshold = tonumber(minetest.settings:get("mcl_mobs_overworld_sky_threshold")) or 7 local overworld_passive_threshold = tonumber(minetest.settings:get("mcl_mobs_overworld_passive_threshold")) or 7 -local PASSIVE_INTERVAL = 200 +local PASSIVE_INTERVAL = 20 local dbg_spawn_attempts = 0 local dbg_spawn_succ = 0 local dbg_spawn_counts = {} @@ -384,11 +384,16 @@ end local passive_timer = PASSIVE_INTERVAL ---timer function to check if passive mobs should spawn (every 20 secs) -local function check_timer(mob_type,dtime) - passive_timer = passive_timer - dtime - if mob_type == "passive" and passive_timer > 0 then return false end - if passive_timer < 0 then passive_timer = PASSIVE_INTERVAL end +--timer function to check if passive mobs should spawn (only every 20 secs unlike other mob spawn classes) +local function check_timer(spawn_def, dtime) + local mob_def = minetest.registered_entities[spawn_def.name] + if mob_def and mob_def.spawn_class == "passive" then + if passive_timer > 0 then + return false + else + passive_timer = PASSIVE_INTERVAL + end + end return true end @@ -463,6 +468,7 @@ if mobs_spawn then local timer = 0 minetest.register_globalstep(function(dtime) + passive_timer = passive_timer - dtime timer = timer + dtime if timer < 10 then return end timer = 0