diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 0a3b7d38a3..13257bff1e 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -366,29 +366,8 @@ end -- main mob function function mob_class:on_step(dtime) self.lifetimer = self.lifetimer - dtime - local pos = self.object:get_pos() - -- Despawning: when lifetimer expires, remove mob - if remove_far - and self.can_despawn == true - and ((not self.nametag) or (self.nametag == "")) - and self.state ~= "attack" - and self.following == nil then - if self.despawn_immediately or self.lifetimer <= 0 then - if spawn_logging then - minetest.log("action", "[mcl_mobs] Mob "..self.name.." despawns at "..minetest.pos_to_string(pos, 1) .. " lifetimer ran out") - end - mcl_burning.extinguish(self.object) - self.object:remove() - return - elseif self.lifetimer <= 10 then - if math.random(10) < 4 then - self.despawn_immediately = true - else - self.lifetimer = 20 - end - end - end + if self:check_despawn(pos) then return true end local v = self.object:get_velocity() local d = 0.85 diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index d7e3deb2b5..b8ed3347c1 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -1,5 +1,7 @@ --lua locals -local minetest,vector,math,table = minetest,vector,math,table +local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs +local mob_class = mcl_mobs.mob_class + local get_node = minetest.get_node local get_item_group = minetest.get_item_group local get_node_light = minetest.get_node_light @@ -722,6 +724,30 @@ if mobs_spawn then end) end +function mob_class:check_despawn(pos) + -- Despawning: when lifetimer expires, remove mob + if remove_far + and self.can_despawn == true + and ((not self.nametag) or (self.nametag == "")) + and self.state ~= "attack" + and self.following == nil then + if self.despawn_immediately or self.lifetimer <= 0 then + if spawn_logging then + minetest.log("action", "[mcl_mobs] Mob "..self.name.." despawns at "..minetest.pos_to_string(pos, 1) .. " lifetimer ran out") + end + mcl_burning.extinguish(self.object) + self.object:remove() + return true + elseif self.lifetimer <= 10 then + if math.random(10) < 4 then + self.despawn_immediately = true + else + self.lifetimer = 20 + end + end + end +end + minetest.register_chatcommand("mobstats",{ privs = { debug = true }, func = function(n,param)