Handle conversion of mobs that were incorrectly converted

This commit is contained in:
teknomunk 2024-06-14 18:50:05 -05:00 committed by the-real-herowl
parent 75a767a0ab
commit 0a2336ad82
2 changed files with 12 additions and 4 deletions

@ -149,6 +149,11 @@ function mob_class:mob_activate(staticdata, def, dtime)
local tmp = minetest.deserialize(staticdata)
-- Patch incorrectly converted mobs
if tmp.base_mesh ~= minetest.registered_entities[self.name].mesh then
mcl_mobs.strip_staticdata(tmp)
end
if tmp then
for _,stat in pairs(tmp) do
self[_] = stat

@ -344,14 +344,17 @@ end -- END mcl_mobs.register_mob function
local STRIP_FIELDS = { "mesh", "base_size", "textures", "base_mesh", "base_texture" }
function mcl_mobs.strip_staticdata(staticdata)
-- Strip select fields from the staticdata to prevent conversion issues
for i = 1,#STRIP_FIELDS do
unpacked_staticdata[STRIP_FIELDS[i]] = nil
end
end
function mcl_mobs.register_conversion(old_name, new_name)
minetest.register_entity(old_name, {
on_activate = function(self, staticdata, dtime)
-- Strip select fields from the staticdata to prevent conversion issues
local unpacked_staticdata = minetest.deserialize(staticdata)
for i = 1,#STRIP_FIELDS do
unpacked_staticdata[STRIP_FIELDS[i]] = nil
end
mcl_mobs.strip_staticdata(unpacked_staticdata)
staticdata = minetest.serialize(unpacked_staticdata)
local old_object = self.object