Fix late registry of rotatable

main
copygirl 1 year ago
parent 0037cf4e3f
commit e0690de642
  1. 9
      init.lua
  2. 6
      registry.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

@ -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`.

Loading…
Cancel
Save