NodeCore mod that adds contraptions
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.

46 lines
1.6 KiB

local ipairs, setmetatable, tostring, print
= ipairs, setmetatable, tostring, print
local minetest, vector
= minetest, vector
local mod_name = minetest.get_current_modname()
local utility = {}
-- Prints an error message by concatenating the parameters as strings.
function error(...)
local str = "[" .. mod_name .. "] "
for _, v in ipairs({...}) do str = str + tostring(v) end
print(str)
end
utility.error = utility
if not vector.convert then
function vector.convert(v)
local t = type(v)
if t == "number" then
-- Assume the number was created by calling `vector.hash`.
return setmetatable(minetest.get_position_from_hash(v), vector.metatable)
elseif t == "string" then
-- Assume the string is either in `(x, y, z)` or `{x=x, y=y, z=z}` format.
local first_chr = v:byte(1)
if first_chr == "(" then return vector.from_string(v)
elseif first_chr == "{" then return setmetatable(minetest.deserialize(v), vector.metatable)
else error("Cannot convert string '" .. v .. "' to vector") end
elseif t == "table" then
-- Assume the table already has `x`, `y` and `z` entries.
-- Returns the same table, making sure its metatable is set.
return setmetatable(v, vector.metatable)
else error("Cannot convert type '" .. t .. "' to vector") end
end
end
if not vector.hash then
function vector:hash()
return minetest.hash_node_position(self)
end
end
return utility