From 4fd4425aae0cc890e3b0d7400efc94b2ff9d3f4a Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Sat, 7 Jan 2023 20:37:29 +0000 Subject: [PATCH] Improved mob debug --- mods/ENTITIES/mcl_mobs/spawning.lua | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index ee1986073..075659bee 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -244,6 +244,24 @@ local function count_mobs_total(mob_type) return num end +local function count_mobs_all() + local mobs_found = {} + local num = 0 + for _,entity in pairs(minetest.luaentities) do + if entity.is_mob then + local mob_type = entity.type -- animal / monster / npc + local mob_name = entity.name + if mobs_found[mob_name] then + mobs_found[mob_name] = mobs_found[mob_name] + 1 + else + mobs_found[mob_name] = 1 + end + num = num + 1 + end + end + return mobs_found, num +end + local function count_mobs_total_cap(mob_type) local num = 0 for _,l in pairs(minetest.luaentities) do @@ -628,6 +646,9 @@ if mobs_spawn then local perlin_noise + -- Get pos to spawn, x and z are randomised, y is range + + local function spawn_a_mob(pos, dimension, y_min, y_max) --create a disconnected clone of the spawn dictionary --prevents memory leak @@ -757,5 +778,18 @@ minetest.register_chatcommand("mobstats",{ minetest.chat_send_player(n,"total mobs:"..count_mobs_total()) minetest.chat_send_player(n,"spawning attempts since server start:"..dbg_spawn_attempts) minetest.chat_send_player(n,"successful spawns since server start:"..dbg_spawn_succ) + + + local mob_counts, total_mobs = count_mobs_all() + if (total_mobs) then + minetest.log("action", "Total mobs found: " .. total_mobs) + end + if mob_counts then + for k, v1 in pairs(mob_counts) do + minetest.log("action", "k: " .. tostring(k)) + minetest.log("action", "v1: " .. tostring(v1)) + end + end + end })