Improve auto-sync loop

This commit is contained in:
GreenBlob 2024-03-14 13:48:37 +08:00
parent 9805b3db9e
commit c3c9d689ec

View File

@ -1,3 +1,7 @@
local function truncate(num)
return math.floor(num * 10000) / 10000
end
local function get_time() local function get_time()
local now = os.date("*t") local now = os.date("*t")
local time = now.hour * 3600 + now.min * 60 + now.sec local time = now.hour * 3600 + now.min * 60 + now.sec
@ -9,12 +13,17 @@ local function sync_time()
end end
local function sync_time_loop() local function sync_time_loop()
local game_time = truncate(minetest.get_timeofday())
local world_time = truncate(get_time())
if game_time ~= world_time then
sync_time() sync_time()
end
minetest.after(60, sync_time_loop) minetest.after(60, sync_time_loop)
end end
minetest.after(0, function() minetest.after(0, function()
minetest.settings:set("time_speed", 1) minetest.settings:set("time_speed", 1)
sync_time()
sync_time_loop() sync_time_loop()
end) end)