You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
34 lines
1.1 KiB
local minetest |
|
= minetest |
|
|
|
-- Table of nodes that can be rotated by the mod. |
|
local registered_rotatables = {} |
|
|
|
|
|
local registry = {} |
|
|
|
function registry.register_rotatable(name, facedir_lookup) |
|
local def = 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 } |
|
end |
|
|
|
-- Returns whether the specified `node` is rotatable by this mod. |
|
function registry.is_rotatable(node) |
|
return not not registered_rotatables[node.name] |
|
end |
|
|
|
-- Fixes facedir for the specified `node` when rotated to `facedir`. |
|
-- * Returns `nil` if the node can't rotate this way. |
|
-- * Returns `facedir` when the node can rotate this way. |
|
-- * Returns another facedir when the node should rotate another equivalent way. |
|
function registry.fix_rotatable_facedir(node, facedir) |
|
local name = node and node.name or "" |
|
local entry = registered_rotatables[name] |
|
if not entry then return nil end |
|
if not entry.lookup then return facedir end |
|
return entry.lookup[facedir] |
|
end |
|
|
|
return registry
|
|
|