From e0690de642464cfcb2efedefef3c889b722a6641 Mon Sep 17 00:00:00 2001 From: copygirl Date: Fri, 27 Oct 2023 09:55:17 +0200 Subject: [PATCH] Fix late registry of rotatable --- init.lua | 9 ++++++--- registry.lua | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/init.lua b/init.lua index 197a140..0ed5ca9 100755 --- a/init.lua +++ b/init.lua @@ -53,16 +53,19 @@ do function(a, b) return vector.equals(a.f, b.r) and vector.equals(a.r, b.f) end) for _, lens_state in ipairs({ "", "_on", "_glow", "_glow_start" }) do - register_rotatable("nc_optics:lens" .. lens_state, LENS_FILTERED_LOOKUP) end + register_rotatable("nc_optics:lens" .. lens_state, nil, LENS_FILTERED_LOOKUP) end for _, prism_state in ipairs({ "", "_on", "_gated" }) do - register_rotatable("nc_optics:prism" .. prism_state, PRISM_FILTERED_LOOKUP) end + register_rotatable("nc_optics:prism" .. prism_state, nil, PRISM_FILTERED_LOOKUP) end -- Register all existing door panels. nodecore.register_on_register_item({ retroactive = true, func = function(name, def) + -- NOTE: This function is actually called BEFORE the item is registered with Minetest. + -- Because of this, looking up the node definition by name does not work. + name = name:gsub("^:", "") -- Fix for older versions of NodeCore. if def.groups and def.groups.door_panel and (not def.groups.door) - then register_rotatable(name, PANEL_FILTERED_LOOKUP) end + then register_rotatable(name, def, PANEL_FILTERED_LOOKUP) end end, }) end diff --git a/registry.lua b/registry.lua index e5df75e..927675b 100644 --- a/registry.lua +++ b/registry.lua @@ -7,8 +7,8 @@ local registered_rotatables = {} local registry = {} -function registry.register_rotatable(name, facedir_lookup) - local def = minetest.registered_nodes[name] +function registry.register_rotatable(name, def, facedir_lookup) + def = def or minetest.registered_nodes[name] if not def then error("Unknown node '" .. name .. "'") end if def.paramtype2 ~= "facedir" then error("Node '" .. name .. "' must be 'facedir'") end registered_rotatables[name] = { lookup = facedir_lookup } @@ -16,7 +16,7 @@ end -- Returns whether the specified `node` is rotatable by this mod. function registry.is_rotatable(node) - return not not registered_rotatables[node.name] + return registered_rotatables[node.name] ~= nil end -- Fixes facedir for the specified `node` when rotated to `facedir`.