From 32ae6b3140e80908a1afe128907048b1ebce6fdb Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 8 Apr 2020 21:32:37 +0200 Subject: [PATCH] Add moon phases --- mods/ENVIRONMENT/mcl_moon/API.md | 15 +++++ mods/ENVIRONMENT/mcl_moon/init.lua | 54 ++++++++++++++++++ mods/ENVIRONMENT/mcl_moon/mod.conf | 2 + .../textures/mcl_moon_moon_phases.png | Bin 0 -> 1898 bytes 4 files changed, 71 insertions(+) create mode 100644 mods/ENVIRONMENT/mcl_moon/API.md create mode 100644 mods/ENVIRONMENT/mcl_moon/init.lua create mode 100644 mods/ENVIRONMENT/mcl_moon/mod.conf create mode 100644 mods/ENVIRONMENT/mcl_moon/textures/mcl_moon_moon_phases.png diff --git a/mods/ENVIRONMENT/mcl_moon/API.md b/mods/ENVIRONMENT/mcl_moon/API.md new file mode 100644 index 000000000..553df0de6 --- /dev/null +++ b/mods/ENVIRONMENT/mcl_moon/API.md @@ -0,0 +1,15 @@ +# `mcl_moon` API +This API has one function: + +## `mcl_moon.get_moon_phase()` + +Returns current moon phase (0-7). + +* 0 = Full Moon +* 1 = Waning Gibbous +* 2 = Last Quarter +* 3 = Waning Crescent +* 4 = New Moon +* 5 = Waxing Crescent +* 6 = First Quarter +* 7 = Waxing Gibbous diff --git a/mods/ENVIRONMENT/mcl_moon/init.lua b/mods/ENVIRONMENT/mcl_moon/init.lua new file mode 100644 index 000000000..df792651d --- /dev/null +++ b/mods/ENVIRONMENT/mcl_moon/init.lua @@ -0,0 +1,54 @@ +local MOON_PHASES = 8 +local MOON_PHASES_HALF = MOON_PHASES / 2 +local SHEET_W = 4 +local SHEET_H = 2 + +mcl_moon = {} +mcl_moon.MOON_PHASES = MOON_PHASES + +mcl_moon.get_moon_phase = function() + local after_midday = 0 + local tod = minetest.get_timeofday() + if tod > 0.5 then + after_midday = 1 + end + return (minetest.get_day_count() + after_midday) % MOON_PHASES +end + +local get_moon_texture = function() + local phase = mcl_moon.get_moon_phase() + local x = phase % MOON_PHASES_HALF + local y + if phase >= MOON_PHASES_HALF then + y = 1 + else + y = 0 + end + return "mcl_moon_moon_phases.png^[sheet:"..SHEET_W.."x"..SHEET_H..":"..x..","..y +end + +local timer = 0 +local last_reported_phase = nil +minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer < 5 then + return + end + timer = 0 + local phase = mcl_moon.get_moon_phase() + -- No-op when moon phase didn't change yet + if last_reported_phase == phase then + return + end + minetest.log("info", "[mcl_moon] New moon phase: "..phase) + last_reported_phase = phase + local moon_arg = {texture = get_moon_texture()} + local players = minetest.get_connected_players() + for p=1, #players do + players[p]:set_moon(moon_arg) + end +end) + +minetest.register_on_joinplayer(function(player) + player:set_moon({texture = get_moon_texture(), scale=3.75}) +end) diff --git a/mods/ENVIRONMENT/mcl_moon/mod.conf b/mods/ENVIRONMENT/mcl_moon/mod.conf new file mode 100644 index 000000000..9ff8c04ba --- /dev/null +++ b/mods/ENVIRONMENT/mcl_moon/mod.conf @@ -0,0 +1,2 @@ +name = mcl_moon +description = Adds moon phases to the game diff --git a/mods/ENVIRONMENT/mcl_moon/textures/mcl_moon_moon_phases.png b/mods/ENVIRONMENT/mcl_moon/textures/mcl_moon_moon_phases.png new file mode 100644 index 0000000000000000000000000000000000000000..d2ee963a95817bff091ca8245cf2ea57f87602f8 GIT binary patch literal 1898 zcmb7_eK^$V8pogC?>FYnyr3}#6-luZ8D*uzVT8OU!Y;KmLM5fV6xK_>N^Fb9ON-bT zwVAV#EUlLe#$YAAkn(a^##j!ktx4oHvp;*C>zwQSd9Leo-Oqj9_j7%p`+NWMT=Q^u zq>{DB00649ll>t8AS?wa5y4__n4<-Dw0gLCJFHi+9s~mjfgl*dB8-89U?m8~!w3ce zMu;$uh+rs@5F81oM8@GUlyOQVB?3i>K*g;?Q6kdtL^_^C$KkOYOH}YARXiC(jew!N zfw&HXNMR7jssv>;uK+YK2#+VsLa4%_`l(HfL=yp=uc-RL$o>j|?yqmeGgYz5cTE|A+0auC7cA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