Fix TNT mod crash when entities disappear during explosion (#2616)

This commit is contained in:
sfan5 2020-03-06 21:51:19 +01:00 committed by GitHub
parent 0c4c6d79c3
commit 329b088d1c

@ -163,9 +163,8 @@ local function entity_physics(pos, radius, drops)
local damage = (4 / dist) * radius local damage = (4 / dist) * radius
if obj:is_player() then if obj:is_player() then
-- currently the engine has no method to set -- we knock the player back 1.0 node, and slightly upwards
-- player velocity. See #2960 -- TODO: switch to add_player_velocity() introduced in 5.1
-- instead, we knock the player back 1.0 node, and slightly upwards
local dir = vector.normalize(vector.subtract(obj_pos, pos)) local dir = vector.normalize(vector.subtract(obj_pos, pos))
local moveoff = vector.multiply(dir, dist + 1.0) local moveoff = vector.multiply(dir, dist + 1.0)
local newpos = vector.add(pos, moveoff) local newpos = vector.add(pos, moveoff)
@ -174,31 +173,35 @@ local function entity_physics(pos, radius, drops)
obj:set_hp(obj:get_hp() - damage) obj:set_hp(obj:get_hp() - damage)
else else
local do_damage = true
local do_knockback = true
local entity_drops = {}
local luaobj = obj:get_luaentity() local luaobj = obj:get_luaentity()
local objdef = minetest.registered_entities[luaobj.name]
if objdef and objdef.on_blast then -- object might have disappeared somehow
do_damage, do_knockback, entity_drops = objdef.on_blast(luaobj, damage) if luaobj then
end local do_damage = true
local do_knockback = true
local entity_drops = {}
local objdef = minetest.registered_entities[luaobj.name]
if do_knockback then if objdef and objdef.on_blast then
local obj_vel = obj:get_velocity() do_damage, do_knockback, entity_drops = objdef.on_blast(luaobj, damage)
obj:set_velocity(calc_velocity(pos, obj_pos, end
obj_vel, radius * 10))
end if do_knockback then
if do_damage then local obj_vel = obj:get_velocity()
if not obj:get_armor_groups().immortal then obj:set_velocity(calc_velocity(pos, obj_pos,
obj:punch(obj, 1.0, { obj_vel, radius * 10))
full_punch_interval = 1.0, end
damage_groups = {fleshy = damage}, if do_damage then
}, nil) if not obj:get_armor_groups().immortal then
obj:punch(obj, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = damage},
}, nil)
end
end
for _, item in pairs(entity_drops) do
add_drop(drops, item)
end end
end
for _, item in pairs(entity_drops) do
add_drop(drops, item)
end end
end end
end end