Change mcl_mobs to use mcl_util.remove_entity() when killing mobs, add guard in vl_projectile against removed mobs

This commit is contained in:
teknomunk 2024-12-15 09:03:17 -06:00
parent b8d2f67dfd
commit 60e3c139cc
5 changed files with 12 additions and 9 deletions

View File

@ -112,13 +112,13 @@ end
function mob_class:mob_activate(staticdata, def, dtime)
if not self.object:get_pos() or staticdata == "remove" then
mcl_burning.extinguish(self.object)
self.object:remove()
mcl_util.remove_entity(self)
return
end
if self.type == "monster"
and minetest.settings:get_bool("only_peaceful_mobs", false) then
mcl_burning.extinguish(self.object)
self.object:remove()
mcl_util.remove_entity(self)
return
end

View File

@ -442,7 +442,7 @@ function mob_class:boom(pos, strength, fire)
end
-- delete the object after it punched the player to avoid nil entities in e.g. mcl_shields!!
self.object:remove()
mcl_util.remove_entity(self)
end
-- deal damage and effects when mob punched
@ -875,7 +875,7 @@ function mob_class:do_states_attack(dtime)
mcl_mobs.effect(pos, 32, "mcl_particles_smoke.png", nil, nil, node_break_radius, 1, 0)
end
mcl_burning.extinguish(self.object)
self.object:remove()
mcl_util.remove_entity(self)
return true
end

View File

@ -419,7 +419,7 @@ function mob_class:check_for_death(cause, cmi_cause)
if on_die_exit == true then
self.state = "die"
mcl_burning.extinguish(self.object)
self.object:remove()
mcl_util.remove(self)
return true
end
end
@ -482,7 +482,7 @@ function mob_class:check_for_death(cause, cmi_cause)
local cbox = self.collisionbox
local yaw = self.object:get_rotation().y
mcl_burning.extinguish(self.object)
self.object:remove()
mcl_util.remove_entity(self)
mcl_mobs.death_effect(dpos, yaw, cbox, not self.instant_death)
end
@ -532,7 +532,7 @@ function mob_class:do_env_damage()
-- remove mob if beyond map limits
if not within_limits(pos, 0) then
mcl_burning.extinguish(self.object)
self.object:remove()
mcl_util.remove_entity(self)
return true
end

View File

@ -1094,7 +1094,7 @@ function mob_class:check_despawn(pos, dtime)
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()
mcl_util.remove_entity(self)
return true
elseif self.lifetimer <= 10 then
if math.random(10) < 4 then

View File

@ -505,7 +505,10 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
object:punch(self.object, 1.0, projectile_def.tool or {full_punch_interval = 1.0, damage_groups = dmg}, dir )
-- Guard against crashes when projectiles get destroyed in response to what it punched
if not self.object:get_pos() then return true end
if self._removed or not self.object:get_pos() then return true end
-- Guard against crashes when the object the projectile collided with was destroyed
if object_lua._removed or not object:get_pos() then return true end
-- Indicate damage
damage_particles(vector.add(pos, vector.multiply(self.object:get_velocity(), 0.1)), self._is_critical)