From bdd0123c7748141f0fca659a522b25d31b01b2f7 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 6 Jan 2021 05:09:05 +0400 Subject: [PATCH] keep mobs from disappearance --- mods/ENTITIES/mcl_mobs/api.lua | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 703b0790a9..4465bea602 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3,7 +3,7 @@ mobs = {} mobs.mod = "mrm" -mobs.version = "20180531" -- don't rely too much on this, rarely updated, if ever +mobs.version = "20210106" -- don't rely too much on this, rarely updated, if ever local MAX_MOB_NAME_LENGTH = 30 local HORNY_TIME = 30 @@ -3589,20 +3589,17 @@ local mob_step = function(self, dtime) and ((not self.nametag) or (self.nametag == "")) then self.lifetimer = self.lifetimer - dtime - local despawn = self.despawn_immediately - if not despawn and self.lifetimer <= 10 then + 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() + elseif self.lifetimer <= 10 then if math.random(10) < 4 then - despawn = true + self.despawn_immediately = true else self.lifetimer = 20 end end - if despawn 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() - end - self.despawn_immediately = true end end @@ -4545,20 +4542,19 @@ function mobs:alias_mob(old_name, new_name) end -minetest.register_globalstep(function() +local timer = 0 +minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer < 1 then return end for _, player in ipairs(minetest.get_connected_players()) do local pos = player:get_pos() - for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 24)) do - local lua = obj:get_luaentity() - if lua and lua._cmi_is_mob then - lua.lifetimer = 20 - end - end - for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 32)) do + for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 47)) do local lua = obj:get_luaentity() if lua and lua._cmi_is_mob then + lua.lifetimer = math.max(20, lua.lifetimer) lua.despawn_immediately = false end end end + timer = 0 end)