1 -- Minetest: builtin/misc.lua
7 core.timers_to_add = {}
9 core.register_globalstep(function(dtime)
10 for _, timer in ipairs(core.timers_to_add) do
11 table.insert(core.timers, timer)
13 core.timers_to_add = {}
15 while index <= #core.timers do
16 local timer = core.timers[index]
17 timer.time = timer.time - dtime
18 if timer.time <= 0 then
19 timer.func(unpack(timer.args or {}))
20 table.remove(core.timers,index)
27 function core.after(time, func, ...)
28 assert(tonumber(time) and type(func) == "function",
29 "Invalid core.after invocation")
30 table.insert(core.timers_to_add, {time=time, func=func, args={...}})
33 function core.check_player_privs(name, privs)
34 local player_privs = core.get_player_privs(name)
35 local missing_privileges = {}
36 for priv, val in pairs(privs) do
38 if not player_privs[priv] then
39 table.insert(missing_privileges, priv)
43 if #missing_privileges > 0 then
44 return false, missing_privileges
49 local player_list = {}
51 core.register_on_joinplayer(function(player)
52 player_list[player:get_player_name()] = player
55 core.register_on_leaveplayer(function(player)
56 player_list[player:get_player_name()] = nil
59 function core.get_connected_players()
61 for index, value in pairs(player_list) do
62 if value:is_player_connected() then
63 table.insert(temp_table, value)
69 function core.hash_node_position(pos)
70 return (pos.z+32768)*65536*65536 + (pos.y+32768)*65536 + pos.x+32768
73 function core.get_position_from_hash(hash)
75 pos.x = (hash%65536) - 32768
76 hash = math.floor(hash/65536)
77 pos.y = (hash%65536) - 32768
78 hash = math.floor(hash/65536)
79 pos.z = (hash%65536) - 32768
83 function core.get_item_group(name, group)
84 if not core.registered_items[name] or not
85 core.registered_items[name].groups[group] then
88 return core.registered_items[name].groups[group]
91 function core.get_node_group(name, group)
92 core.log("deprecated", "Deprecated usage of get_node_group, use get_item_group instead")
93 return core.get_item_group(name, group)
96 function core.string_to_pos(value)
98 p.x, p.y, p.z = string.match(value, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
99 if p.x and p.y and p.z then
106 p.x, p.y, p.z = string.match(value, "^%( *([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) *%)$")
107 if p.x and p.y and p.z then
116 assert(core.string_to_pos("10.0, 5, -2").x == 10)
117 assert(core.string_to_pos("( 10.0, 5, -2)").z == -2)
118 assert(core.string_to_pos("asd, 5, -2)") == nil)
120 function core.setting_get_pos(name)
121 local value = core.setting_get(name)
125 return core.string_to_pos(value)
128 -- To be overriden by protection mods
129 function core.is_protected(pos, name)
133 function core.record_protection_violation(pos, name)
134 for _, func in pairs(core.registered_on_protection_violation) do