From 26062a9d2699eba7b8803003019c2d61ce9166b6 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 17 Sep 2024 21:07:24 -0500 Subject: [PATCH] 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 --- mods/ENTITIES/mobs_mc/wither.lua | 1 + mods/ITEMS/vl_projectile/init.lua | 3 +++ 2 files changed, 4 insertions(+) diff --git a/mods/ENTITIES/mobs_mc/wither.lua b/mods/ENTITIES/mobs_mc/wither.lua index 252873629..0afb846b9 100644 --- a/mods/ENTITIES/mobs_mc/wither.lua +++ b/mods/ENTITIES/mobs_mc/wither.lua @@ -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 diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index 84533dd78..416f5e275 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -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)