[5.6][lightning] fix unsafe entitiy handling

this does not excuse all on_strike callbacks to allow oversights.
it must also track entity removal.
This commit is contained in:
iliekprogrammar 2022-08-07 10:44:13 +08:00
parent 221ee0fcf1
commit bce4d29737
No known key found for this signature in database
GPG Key ID: 8E7B20514DBCFBFA

View File

@ -120,11 +120,10 @@ function lightning.strike(pos)
if not pos then if not pos then
return false return false
end end
-- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS
-- mcl_util.deal_damage inside one of on_strike_functions
local objects = get_objects_inside_radius(pos2, 3.5)
if lightning.on_strike_functions then if lightning.on_strike_functions then
for _, func in pairs(lightning.on_strike_functions) do for _, func in pairs(lightning.on_strike_functions) do
-- allow on_strike callbacks to destroy entities by re-obtaining objects for each callback
local objects = get_objects_inside_radius(pos2, 3.5)
func(pos, pos2, objects) func(pos, pos2, objects)
end end
end end
@ -176,7 +175,7 @@ lightning.register_on_strike(function(pos, pos2, objects)
elseif lua and lua.name == "mobs_mc:creeper" then elseif lua and lua.name == "mobs_mc:creeper" then
mcl_util.replace_mob(obj, "mobs_mc:creeper_charged") mcl_util.replace_mob(obj, "mobs_mc:creeper_charged")
else else
-- ERROR: [#2523] THIS WILL CAUSE INVALID OBJECTREFS -- WARNING: unsafe entity handling. object may be removed immediately
mcl_util.deal_damage(obj, 5, { type = "lightning_bolt" }) mcl_util.deal_damage(obj, 5, { type = "lightning_bolt" })
end end
end end