Merge pull request 'Fix villagers/mobs despawning ( issue #26 )' (#29) from TioBlocos/MineClone5:fix/issue_26_villagers_despawning into master

Reviewed-on: MineClone5/MineClone5#29
This commit is contained in:
cora 2021-09-25 15:01:11 +00:00
commit 15a60ae638
2 changed files with 10 additions and 9 deletions

View File

@ -821,8 +821,7 @@ function mobs.mob_step(self, dtime)
self.lifetimer = self.lifetimer - dtime
if self.lifetimer <= 0 then
self.lifetimer = self.lifetimer_reset
if not mobs.check_for_player_within_area(self, 64) then
--print("removing in MAIN LOGIC!")
if mobs.can_despawn(self) then
self.object:remove()
return
end

View File

@ -5,17 +5,19 @@ local minetest_settings = minetest.settings
-- CMI support check
local use_cmi = minetest.global_exists("cmi")
mobs.can_despawn = function(self)
return (not self.tamed and not self.bred and not self.nametag and
not mobs.check_for_player_within_area(self, 64));
end
-- get entity staticdata
mobs.mob_staticdata = function(self)
--despawn mechanism
--don't despawned tamed or bred mobs
if not self.tamed and not self.bred then
if not mobs.check_for_player_within_area(self, 64) then
--print("removing SERIALIZED!")
if mobs.can_despawn(self) then
self.object:remove()
return
end
end
self.remove_ok = true
self.attack = nil