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 = {}
14 for index, timer in ipairs(core.timers) do
15 timer.time = timer.time - dtime
16 if timer.time <= 0 then
17 timer.func(unpack(timer.args or {}))
18 table.remove(core.timers,index)
23 function core.after(time, func, ...)
24 assert(tonumber(time) and type(func) == "function",
25 "Invalid core.after invocation")
26 table.insert(core.timers_to_add, {time=time, func=func, args={...}})
29 function core.check_player_privs(name, privs)
30 local player_privs = core.get_player_privs(name)
31 local missing_privileges = {}
32 for priv, val in pairs(privs) do
34 if not player_privs[priv] then
35 table.insert(missing_privileges, priv)
39 if #missing_privileges > 0 then
40 return false, missing_privileges
45 local player_list = {}
47 core.register_on_joinplayer(function(player)
48 player_list[player:get_player_name()] = player
51 core.register_on_leaveplayer(function(player)
52 player_list[player:get_player_name()] = nil
55 function core.get_connected_players()
57 for index, value in pairs(player_list) do
58 if value:is_player_connected() then
59 table.insert(temp_table, value)
65 function core.hash_node_position(pos)
66 return (pos.z+32768)*65536*65536 + (pos.y+32768)*65536 + pos.x+32768
69 function core.get_position_from_hash(hash)
71 pos.x = (hash%65536) - 32768
72 hash = math.floor(hash/65536)
73 pos.y = (hash%65536) - 32768
74 hash = math.floor(hash/65536)
75 pos.z = (hash%65536) - 32768
79 function core.get_item_group(name, group)
80 if not core.registered_items[name] or not
81 core.registered_items[name].groups[group] then
84 return core.registered_items[name].groups[group]
87 function core.get_node_group(name, group)
88 core.log("deprecated", "Deprecated usage of get_node_group, use get_item_group instead")
89 return core.get_item_group(name, group)
92 function core.string_to_pos(value)
94 p.x, p.y, p.z = string.match(value, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
95 if p.x and p.y and p.z then
102 p.x, p.y, p.z = string.match(value, "^%( *([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) *%)$")
103 if p.x and p.y and p.z then
112 assert(core.string_to_pos("10.0, 5, -2").x == 10)
113 assert(core.string_to_pos("( 10.0, 5, -2)").z == -2)
114 assert(core.string_to_pos("asd, 5, -2)") == nil)
116 function core.setting_get_pos(name)
117 local value = core.setting_get(name)
121 return core.string_to_pos(value)
124 -- To be overriden by protection mods
125 function core.is_protected(pos, name)
129 function core.record_protection_violation(pos, name)
130 for _, func in pairs(core.registered_on_protection_violation) do