From 3093462ee3a59e5602e113f086ad0e24dc7a87bb Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 9 Sep 2022 23:31:02 +0200 Subject: [PATCH] Fix despawning --- mods/ENTITIES/mcl_mobs/api.lua | 18 +++++++++++------- mods/ENTITIES/mcl_mobs/spawning.lua | 17 ++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 6f3a4f13c..a9c36bfbb 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3406,21 +3406,20 @@ end -- get entity staticdata local mob_staticdata = function(self) ---[[ + -- remove mob when out of range unless tamed if remove_far and self.can_despawn and self.remove_ok and ((not self.nametag) or (self.nametag == "")) and self.lifetimer <= 20 then - - minetest.log("action", "Mob "..name.." despawns in mob_staticdata at "..minetest.pos_to_string(self.object.get_pos(), 1)) + minetest.log("action", "Mob "..tostring(self.name).." despawns in mob_staticdata at "..minetest.pos_to_string(self.object:get_pos())) mcl_burning.extinguish(self.object) self.object:remove() - return ""-- nil + return "remove"-- nil end ---]] + self.remove_ok = true self.attack = nil self.following = nil @@ -3456,6 +3455,11 @@ local mob_activate = function(self, staticdata, def, dtime) return end + if staticdata == "remove" then + mcl_burning.extinguish(self.object) + self.object:remove() + return + end -- load entity variables local tmp = minetest.deserialize(staticdata) @@ -3623,6 +3627,7 @@ end -- main mob function local mob_step = function(self, dtime) + self.lifetimer = self.lifetimer - dtime check_item_pickup(self) check_aggro(self,dtime) if not self.fire_resistant then @@ -3836,12 +3841,11 @@ local mob_step = function(self, dtime) and ((not self.nametag) or (self.nametag == "")) and self.state ~= "attack" and self.following == nil then - - self.lifetimer = self.lifetimer - dtime if self.despawn_immediately or self.lifetimer <= 0 then minetest.log("action", "Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1)) mcl_burning.extinguish(self.object) self.object:remove() + return elseif self.lifetimer <= 10 then if math.random(10) < 4 then self.despawn_immediately = true diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index ff86061db..36d59be8d 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -466,6 +466,15 @@ local function spawn_check(pos,spawn_def) return false end +function mcl_mobs.spawn(pos,id) + local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id] + if not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then + return false + end + return minetest.add_entity(pos, def.name) +end + + local function spawn_group(p,mob,spawn_on,group_max,group_min) if not group_min then group_min = 1 end local nn= minetest.find_nodes_in_area_under_air(vector.offset(p,-5,-3,-5),vector.offset(p,5,3,5),spawn_on) @@ -488,13 +497,7 @@ local function spawn_group(p,mob,spawn_on,group_max,group_min) return o end -function mcl_mobs.spawn(pos,id) - local def = minetest.registered_entities[id] or minetest.registered_entities["mobs_mc:"..id] or minetest.registered_entities["extra_mobs:"..id] - if not def or (def.can_spawn and not def.can_spawn(pos)) or not def.is_mob then - return false - end - return minetest.add_entity(pos, def.name) -end +mcl_mobs.spawn_group = spawn_group minetest.register_chatcommand("spawn_mob",{ privs = { debug = true },