Despawn out of range mobs when immobile

This commit is contained in:
cora 2022-10-13 21:14:18 +02:00
parent c146124a2c
commit 976b9da7d7

View File

@ -3602,7 +3602,7 @@ local mob_staticdata = function(self)
and ((not self.nametag) or (self.nametag == "")) and ((not self.nametag) or (self.nametag == ""))
and self.lifetimer <= 20 then and self.lifetimer <= 20 then
if spawn_logging 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 end
return "remove"-- nil return "remove"-- nil
@ -3826,6 +3826,30 @@ end
-- main mob function -- main mob function
local mob_step = function(self, dtime) local mob_step = function(self, dtime)
self.lifetimer = self.lifetimer - 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 if not player_in_active_range(self) then
set_animation(self, "stand", true) set_animation(self, "stand", true)
self.object:set_velocity(vector.new(0,0,0)) 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 if not self.object:get_pos() then return end
end end
local pos = self.object:get_pos()
local yaw = 0 local yaw = 0
if mobs_debug then if mobs_debug then
@ -4105,28 +4128,6 @@ local mob_step = function(self, dtime)
local yaw = self.object:get_yaw() or 0 local yaw = self.object:get_yaw() or 0
yaw = set_yaw(self, yaw + 0.78, 8) yaw = set_yaw(self, yaw + 0.78, 8)
end 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 end