Randomize initial moon phase

This commit is contained in:
Wuzzy 2020-04-08 22:05:23 +02:00
parent 32ae6b3140
commit 0c271a2af9
1 changed files with 12 additions and 2 deletions

View File

@ -3,16 +3,26 @@ local MOON_PHASES_HALF = MOON_PHASES / 2
local SHEET_W = 4
local SHEET_H = 2
-- Randomize initial moon phase, based on map seed
local phase_offset
local mg_seed = minetest.get_mapgen_setting("seed")
local rand = PseudoRandom(mg_seed)
local phase_offset = rand:next(0, MOON_PHASES - 1)
rand = nil
minetest.log("info", "[mcl_moon] Moon phase offset of this world: "..phase_offset)
mcl_moon = {}
mcl_moon.MOON_PHASES = MOON_PHASES
mcl_moon.get_moon_phase = function()
local after_midday = 0
-- Moon phase changes after midday
local tod = minetest.get_timeofday()
if tod > 0.5 then
after_midday = 1
end
return (minetest.get_day_count() + after_midday) % MOON_PHASES
return (minetest.get_day_count() + phase_offset + after_midday) % MOON_PHASES
end
local get_moon_texture = function()
@ -31,7 +41,7 @@ local timer = 0
local last_reported_phase = nil
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 5 then
if timer < 8 then
return
end
timer = 0