From 0a2336ad82055bcd36f7809e05e2b611adce8ff8 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 14 Jun 2024 18:50:05 -0500 Subject: [PATCH] Handle conversion of mobs that were incorrectly converted --- mods/ENTITIES/mcl_mobs/api.lua | 5 +++++ mods/ENTITIES/mcl_mobs/init.lua | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 873d05bf2..8064c5511 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -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 diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index dcd1bed4d..f9828c7d0 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -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