Fix minetest.after crashes in mcl_mobs

This commit is contained in:
Wuzzy 2018-06-03 16:13:46 +02:00
parent 9c6f5b3573
commit 201c2bf170
2 changed files with 41 additions and 17 deletions

View File

@ -493,8 +493,10 @@ local check_for_death = function(self, cause, cmi_cause)
set_animation(self, "die") set_animation(self, "die")
minetest.after(length, function(self) minetest.after(length, function(self)
if not self.object:get_luaentity() then
if use_cmi then return
end
if use_cmi then
cmi.notify_die(self.object, cmi_cause) cmi.notify_die(self.object, cmi_cause)
end end
@ -769,6 +771,9 @@ local do_jump = function(self)
-- when in air move forward -- when in air move forward
minetest.after(0.3, function(self, v) minetest.after(0.3, function(self, v)
if not self.object:get_luaentity() then
return
end
self.object:set_acceleration({ self.object:set_acceleration({
x = v.x * 2, x = v.x * 2,
y = 0, y = 0,
@ -949,17 +954,23 @@ local breed = function(self)
ent.hornytimer = 41 ent.hornytimer = 41
-- spawn baby -- spawn baby
minetest.after(5, function() minetest.after(5, function(parent1, parent2, pos)
if not parent1.object:get_luaentity() then
return
end
if not parent2.object:get_luaentity() then
return
end
-- custom breed function -- custom breed function
if self.on_breed then if parent1.on_breed then
-- when false skip going any further -- when false, skip going any further
if self.on_breed(self, ent) == false then if parent1.on_breed(parent1, parent2) == false then
return return
end end
end end
local child = mobs:spawn_child(pos, self.name) local child = mobs:spawn_child(pos, parent1.name)
local ent_c = child:get_luaentity() local ent_c = child:get_luaentity()
@ -967,9 +978,9 @@ local breed = function(self)
-- Use texture of one of the parents -- Use texture of one of the parents
local p = math.random(1, 2) local p = math.random(1, 2)
if p == 1 then if p == 1 then
ent_c.base_texture = self.base_texture ent_c.base_texture = parent1.base_texture
else else
ent_c.base_texture = ent.base_texture ent_c.base_texture = parent2.base_texture
end end
child:set_properties({ child:set_properties({
textures = ent_c.base_texture textures = ent_c.base_texture
@ -977,8 +988,8 @@ local breed = function(self)
-- tamed and owned by parents' owner -- tamed and owned by parents' owner
ent_c.tamed = true ent_c.tamed = true
ent_c.owner = self.owner ent_c.owner = parent1.owner
end) end, self, ent, pos)
num = 0 num = 0
@ -1096,6 +1107,9 @@ local smart_mobs = function(self, s, p, dist, dtime)
use_pathfind = false use_pathfind = false
minetest.after(1, function(self) minetest.after(1, function(self)
if not self.object:get_luaentity() then
return
end
if has_lineofsight then self.path.following = false end if has_lineofsight then self.path.following = false end
end, self) end, self)
end -- can see target! end -- can see target!
@ -1107,6 +1121,9 @@ local smart_mobs = function(self, s, p, dist, dtime)
self.path.stuck_timer = 0 self.path.stuck_timer = 0
minetest.after(1, function(self) minetest.after(1, function(self)
if not self.object:get_luaentity() then
return
end
if has_lineofsight then self.path.following = false end if has_lineofsight then self.path.following = false end
end, self) end, self)
end end
@ -1117,6 +1134,9 @@ local smart_mobs = function(self, s, p, dist, dtime)
self.path.stuck_timer = 0 self.path.stuck_timer = 0
minetest.after(1, function(self) minetest.after(1, function(self)
if not self.object:get_luaentity() then
return
end
if has_lineofsight then self.path.following = false end if has_lineofsight then self.path.following = false end
end, self) end, self)
end end

View File

@ -151,9 +151,11 @@ function mobs.attach(entity, player)
} }
}) })
minetest.after(0.2, function() minetest.after(0.2, function(player)
mcl_player.player_set_animation(player, "sit" , 30) if player:is_player() then
end) mcl_player.player_set_animation(player, "sit" , 30)
end
end, player)
player:set_look_horizontal(entity.object:get_yaw() - rot_view) player:set_look_horizontal(entity.object:get_yaw() - rot_view)
end end
@ -169,9 +171,11 @@ function mobs.detach(player, offset)
pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z} pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
minetest.after(0.1, function() minetest.after(0.1, function(player, pos)
player:setpos(pos) if player:is_player() then
end) player:set_pos(pos)
end
end, player, pos)
end end