1 -- Minetest: builtin/misc_s.lua
2 -- The distinction of what goes here is a bit tricky, basically it's everything
3 -- that does not (directly or indirectly) need access to ServerEnvironment,
4 -- Server or writable access to IGameDef on the engine side.
5 -- (The '_s' stands for standalone.)
11 function core.hash_node_position(pos)
12 return (pos.z + 32768) * 65536 * 65536
13 + (pos.y + 32768) * 65536
18 function core.get_position_from_hash(hash)
19 local x = (hash % 65536) - 32768
20 hash = math.floor(hash / 65536)
21 local y = (hash % 65536) - 32768
22 hash = math.floor(hash / 65536)
23 local z = (hash % 65536) - 32768
24 return vector.new(x, y, z)
28 function core.get_item_group(name, group)
29 if not core.registered_items[name] or not
30 core.registered_items[name].groups[group] then
33 return core.registered_items[name].groups[group]
37 function core.get_node_group(name, group)
38 core.log("deprecated", "Deprecated usage of get_node_group, use get_item_group instead")
39 return core.get_item_group(name, group)
43 function core.setting_get_pos(name)
44 local value = core.settings:get(name)
48 return core.string_to_pos(value)
52 -- See l_env.cpp for the other functions
53 function core.get_artificial_light(param1)
54 return math.floor(param1 / 16)
57 -- PNG encoder safety wrapper
59 local o_encode_png = core.encode_png
60 function core.encode_png(width, height, data, compression)
61 if type(width) ~= "number" then
62 error("Incorrect type for 'width', expected number, got " .. type(width))
64 if type(height) ~= "number" then
65 error("Incorrect type for 'height', expected number, got " .. type(height))
68 local expected_byte_count = width * height * 4
70 if type(data) ~= "table" and type(data) ~= "string" then
71 error("Incorrect type for 'data', expected table or string, got " .. type(data))
74 local data_length = type(data) == "table" and #data * 4 or string.len(data)
76 if data_length ~= expected_byte_count then
78 "Incorrect length of 'data', width and height imply %d bytes but %d were provided",
84 if type(data) == "table" then
87 dataBuf[i] = core.colorspec_to_bytes(data[i])
89 data = table.concat(dataBuf)
92 return o_encode_png(width, height, data, compression or 6)