1 -- Minetest: builtin/misc.lua
9 local function update_timers(delay)
12 for index = 1, #timers do
14 local timer = timers[index]
15 timer.time = timer.time - delay
16 if timer.time <= 0 then
17 core.set_last_run_mod(timer.mod_origin)
18 timer.func(unpack(timer.args or {}))
19 table.remove(timers, index)
22 mintime = math.min(mintime, timer.time)
30 local function add_timers()
31 for _, timer in ipairs(timers_to_add) do
32 table.insert(timers, timer)
38 core.register_globalstep(function(dtime)
40 -- abort if no timers are running
47 if delay < mintime then
54 function core.after(time, func, ...)
55 assert(tonumber(time) and type(func) == "function",
56 "Invalid core.after invocation")
63 mod_origin = core.get_last_run_mod(),
67 mintime = math.min(mintime, time)
68 timers_to_add = timers_to_add or {}
69 timers_to_add[#timers_to_add+1] = {
73 mod_origin = core.get_last_run_mod(),
77 function core.check_player_privs(name, privs)
78 local player_privs = core.get_player_privs(name)
79 local missing_privileges = {}
80 for priv, val in pairs(privs) do
82 and not player_privs[priv] then
83 table.insert(missing_privileges, priv)
86 if #missing_privileges > 0 then
87 return false, missing_privileges
92 local player_list = {}
94 core.register_on_joinplayer(function(player)
95 player_list[player:get_player_name()] = player
98 core.register_on_leaveplayer(function(player)
99 player_list[player:get_player_name()] = nil
102 function core.get_connected_players()
103 local temp_table = {}
104 for index, value in pairs(player_list) do
105 if value:is_player_connected() then
106 table.insert(temp_table, value)
112 function core.hash_node_position(pos)
113 return (pos.z+32768)*65536*65536 + (pos.y+32768)*65536 + pos.x+32768
116 function core.get_position_from_hash(hash)
118 pos.x = (hash%65536) - 32768
119 hash = math.floor(hash/65536)
120 pos.y = (hash%65536) - 32768
121 hash = math.floor(hash/65536)
122 pos.z = (hash%65536) - 32768
126 function core.get_item_group(name, group)
127 if not core.registered_items[name] or not
128 core.registered_items[name].groups[group] then
131 return core.registered_items[name].groups[group]
134 function core.get_node_group(name, group)
135 core.log("deprecated", "Deprecated usage of get_node_group, use get_item_group instead")
136 return core.get_item_group(name, group)
139 function core.setting_get_pos(name)
140 local value = core.setting_get(name)
144 return core.string_to_pos(value)
147 -- To be overriden by protection mods
148 function core.is_protected(pos, name)
152 function core.record_protection_violation(pos, name)
153 for _, func in pairs(core.registered_on_protection_violation) do
158 local raillike_ids = {}
159 local raillike_cur_id = 0
160 function core.raillike_group(name)
161 local id = raillike_ids[name]
163 raillike_cur_id = raillike_cur_id + 1
164 raillike_ids[name] = raillike_cur_id