From 976b9da7d7486c2220b92ffb8660352b0c7f323c Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 13 Oct 2022 21:14:18 +0200 Subject: [PATCH] Despawn out of range mobs when immobile --- mods/ENTITIES/mcl_mobs/api.lua | 49 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 5d7940f3df..fbf65b3336 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3602,7 +3602,7 @@ local mob_staticdata = function(self) and ((not self.nametag) or (self.nametag == "")) and self.lifetimer <= 20 then if spawn_logging then - minetest.log("action", "[mcl_mobs] Mob "..tostring(self.name).." despawns in mob_staticdata at "..minetest.pos_to_string(vector.round(self.object:get_pos()))) + minetest.log("action", "[mcl_mobs] Mob "..tostring(self.name).." despawns at "..minetest.pos_to_string(vector.round(self.object:get_pos())) .. " - out of range") end return "remove"-- nil @@ -3826,6 +3826,30 @@ end -- main mob function local mob_step = function(self, 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 random(10) < 4 then + self.despawn_immediately = true + else + self.lifetimer = 20 + end + end + end + if not player_in_active_range(self) then set_animation(self, "stand", true) self.object:set_velocity(vector.new(0,0,0)) @@ -3840,7 +3864,6 @@ local mob_step = function(self, dtime) if not self.object:get_pos() then return end end - local pos = self.object:get_pos() local yaw = 0 if mobs_debug then @@ -4105,28 +4128,6 @@ local mob_step = function(self, dtime) local yaw = self.object:get_yaw() or 0 yaw = set_yaw(self, yaw + 0.78, 8) end - - -- 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 in mob_step at "..minetest.pos_to_string(pos, 1)) - end - mcl_burning.extinguish(self.object) - self.object:remove() - return - elseif self.lifetimer <= 10 then - if random(10) < 4 then - self.despawn_immediately = true - else - self.lifetimer = 20 - end - end - end end