Add moon phases
This commit is contained in:
parent
868fa04818
commit
32ae6b3140
15
mods/ENVIRONMENT/mcl_moon/API.md
Normal file
15
mods/ENVIRONMENT/mcl_moon/API.md
Normal file
|
@ -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
|
54
mods/ENVIRONMENT/mcl_moon/init.lua
Normal file
54
mods/ENVIRONMENT/mcl_moon/init.lua
Normal file
|
@ -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)
|
2
mods/ENVIRONMENT/mcl_moon/mod.conf
Normal file
2
mods/ENVIRONMENT/mcl_moon/mod.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
name = mcl_moon
|
||||
description = Adds moon phases to the game
|
BIN
mods/ENVIRONMENT/mcl_moon/textures/mcl_moon_moon_phases.png
Normal file
BIN
mods/ENVIRONMENT/mcl_moon/textures/mcl_moon_moon_phases.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Loading…
Reference in New Issue
Block a user