Skip to content

Commit 07a8067

Browse files
authoredMar 6, 2020
Fix TNT mod crash when entities disappear during explosion (#2616)
1 parent 3a86305 commit 07a8067

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed
 

‎mods/tnt/init.lua

+27-24
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ local function entity_physics(pos, radius, drops)
163163

164164
local damage = (4 / dist) * radius
165165
if obj:is_player() then
166-
-- currently the engine has no method to set
167-
-- player velocity. See #2960
168-
-- instead, we knock the player back 1.0 node, and slightly upwards
166+
-- we knock the player back 1.0 node, and slightly upwards
167+
-- TODO: switch to add_player_velocity() introduced in 5.1
169168
local dir = vector.normalize(vector.subtract(obj_pos, pos))
170169
local moveoff = vector.multiply(dir, dist + 1.0)
171170
local newpos = vector.add(pos, moveoff)
@@ -174,31 +173,35 @@ local function entity_physics(pos, radius, drops)
174173

175174
obj:set_hp(obj:get_hp() - damage)
176175
else
177-
local do_damage = true
178-
local do_knockback = true
179-
local entity_drops = {}
180176
local luaobj = obj:get_luaentity()
181-
local objdef = minetest.registered_entities[luaobj.name]
182177

183-
if objdef and objdef.on_blast then
184-
do_damage, do_knockback, entity_drops = objdef.on_blast(luaobj, damage)
185-
end
178+
-- object might have disappeared somehow
179+
if luaobj then
180+
local do_damage = true
181+
local do_knockback = true
182+
local entity_drops = {}
183+
local objdef = minetest.registered_entities[luaobj.name]
186184

187-
if do_knockback then
188-
local obj_vel = obj:get_velocity()
189-
obj:set_velocity(calc_velocity(pos, obj_pos,
190-
obj_vel, radius * 10))
191-
end
192-
if do_damage then
193-
if not obj:get_armor_groups().immortal then
194-
obj:punch(obj, 1.0, {
195-
full_punch_interval = 1.0,
196-
damage_groups = {fleshy = damage},
197-
}, nil)
185+
if objdef and objdef.on_blast then
186+
do_damage, do_knockback, entity_drops = objdef.on_blast(luaobj, damage)
187+
end
188+
189+
if do_knockback then
190+
local obj_vel = obj:get_velocity()
191+
obj:set_velocity(calc_velocity(pos, obj_pos,
192+
obj_vel, radius * 10))
193+
end
194+
if do_damage then
195+
if not obj:get_armor_groups().immortal then
196+
obj:punch(obj, 1.0, {
197+
full_punch_interval = 1.0,
198+
damage_groups = {fleshy = damage},
199+
}, nil)
200+
end
201+
end
202+
for _, item in pairs(entity_drops) do
203+
add_drop(drops, item)
198204
end
199-
end
200-
for _, item in pairs(entity_drops) do
201-
add_drop(drops, item)
202205
end
203206
end
204207
end

0 commit comments

Comments
 (0)
Please sign in to comment.