Add guard to prevent crash when converting old mobs and the minetest fails to create the new entity

This commit is contained in:
teknomunk 2024-06-09 08:38:47 -05:00 committed by the-real-herowl
parent 8aa65f85f2
commit bc343769ee

View file

@ -346,8 +346,10 @@ function mcl_mobs.register_conversion(old_name, new_name)
minetest.register_entity(old_name, { minetest.register_entity(old_name, {
on_activate = function(self, staticdata, dtime) on_activate = function(self, staticdata, dtime)
local obj = minetest.add_entity(self.object:get_pos(), new_name, staticdata) local obj = minetest.add_entity(self.object:get_pos(), new_name, staticdata)
if obj then
local hook = (obj:get_luaentity() or {})._on_after_convert local hook = (obj:get_luaentity() or {})._on_after_convert
if hook then hook(obj) end if hook then hook(obj) end
end
self.object:remove() self.object:remove()
end, end,
_convert_to = new_name, _convert_to = new_name,