From 0c271a2af9465b866550c5d9765f7cc6c7aa5a9a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 8 Apr 2020 22:05:23 +0200 Subject: [PATCH] Randomize initial moon phase --- mods/ENVIRONMENT/mcl_moon/init.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_moon/init.lua b/mods/ENVIRONMENT/mcl_moon/init.lua index df792651d1..4ee2623a6b 100644 --- a/mods/ENVIRONMENT/mcl_moon/init.lua +++ b/mods/ENVIRONMENT/mcl_moon/init.lua @@ -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