Prevent projectiles from crashing server when removed when it punched something (wither skull hitting the wither will cause this), mark wither skull with _removed = true when death timer removes it

This commit is contained in:
teknomunk 2024-09-17 21:07:24 -05:00
parent 9c11d0ce92
commit 26062a9d26
2 changed files with 4 additions and 0 deletions

@ -201,6 +201,7 @@ mcl_mobs.register_mob("mobs_mc:wither", {
self._death_timer = self._death_timer + self.health - self._health_old
if self.health == self._health_old then self._death_timer = self._death_timer + dtime end
if self._death_timer > 100 then
self._removed = true
self.object:remove()
return false
end

@ -276,6 +276,9 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
if do_damage then
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
-- Indicate damage
damage_particles(vector.add(pos, vector.multiply(self.object:get_velocity(), 0.1)), self._is_critical)