Randomize initial moon phase
This commit is contained in:
parent
32ae6b3140
commit
0c271a2af9
1 changed files with 12 additions and 2 deletions
|
@ -3,16 +3,26 @@ local MOON_PHASES_HALF = MOON_PHASES / 2
|
||||||
local SHEET_W = 4
|
local SHEET_W = 4
|
||||||
local SHEET_H = 2
|
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 = {}
|
||||||
mcl_moon.MOON_PHASES = MOON_PHASES
|
mcl_moon.MOON_PHASES = MOON_PHASES
|
||||||
|
|
||||||
mcl_moon.get_moon_phase = function()
|
mcl_moon.get_moon_phase = function()
|
||||||
local after_midday = 0
|
local after_midday = 0
|
||||||
|
-- Moon phase changes after midday
|
||||||
local tod = minetest.get_timeofday()
|
local tod = minetest.get_timeofday()
|
||||||
if tod > 0.5 then
|
if tod > 0.5 then
|
||||||
after_midday = 1
|
after_midday = 1
|
||||||
end
|
end
|
||||||
return (minetest.get_day_count() + after_midday) % MOON_PHASES
|
return (minetest.get_day_count() + phase_offset + after_midday) % MOON_PHASES
|
||||||
end
|
end
|
||||||
|
|
||||||
local get_moon_texture = function()
|
local get_moon_texture = function()
|
||||||
|
@ -31,7 +41,7 @@ local timer = 0
|
||||||
local last_reported_phase = nil
|
local last_reported_phase = nil
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if timer < 5 then
|
if timer < 8 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
timer = 0
|
timer = 0
|
||||||
|
|
Reference in a new issue