From e7f6afd789747d757047cb9b49f5b527c0cbf688 Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Mon, 25 May 2020 11:27:20 -0400 Subject: [PATCH] More entity property setting reforms - Move comparison check into object metatable so it applies to all naive set_properties() calls. This should help catching it in downstream mods. - Remove sprite property filtering. It seems the issue was actually caused by a 2D/3D vector disagreement between caller and property def, which the hack wouldn't have fixed for sprite-type visuals anyway; it only actually helped in the current code because the only entities trying to set them to 3D vectors in the first place were non-sprite. --- mods/nc_api_ents/util.lua | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/mods/nc_api_ents/util.lua b/mods/nc_api_ents/util.lua index 9d56f4a7..5b31fca2 100644 --- a/mods/nc_api_ents/util.lua +++ b/mods/nc_api_ents/util.lua @@ -1,6 +1,6 @@ -- LUALOCALS < --------------------------------------------------------- -local nodecore, pairs, type - = nodecore, pairs, type +local getmetatable, minetest, nodecore, pairs, type + = getmetatable, minetest, nodecore, pairs, type -- LUALOCALS > --------------------------------------------------------- local function mismatch(a, b) @@ -19,22 +19,38 @@ local function mismatch(a, b) return a ~= b end -local sprite_vis = {sprite = true, upright_sprite = true} -local sprite_props = {initial_sprite_basepos = true, spritediv = true} +local old_set_props -function nodecore.ent_prop_set(obj, def) +local function set_properties_compare(obj, def) + if type(def) ~= "table" then return old_set_props(obj, def) end local old = obj:get_properties() if not old then return end if type(def) == "function" then def = def(old, obj) end - local issprite = sprite_vis[def.visual or old and old.visual or ""] local toset for k, v in pairs(def) do - if (issprite or not sprite_props[k]) and mismatch(v, old[k]) then + if mismatch(v, old[k]) then toset = toset or {} toset[k] = v end end - return toset and obj:set_properties(toset) + return toset and old_set_props(obj, toset) +end + +local function tryhook() + for _, v in pairs(minetest.object_refs) do + local mt = v and getmetatable(v) + if mt and mt.set_properties then + old_set_props = mt.set_properties + mt.set_properties = set_properties_compare + return + end + end + return minetest.after(0, tryhook) +end +tryhook() + +function nodecore.ent_prop_set(obj, def) + return obj:set_properties(def) end