Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
79992a0445 | |||
f9182cae3f | |||
3e6abe5e42 | |||
b0aed595e5 | |||
22528c2e67 | |||
77f6c3695c | |||
46471862e9 |
16
README.md
@ -6,9 +6,13 @@ Make sure you have the latest version installed or [update your game](https://ww
|
||||
|
||||
## Dependencies
|
||||
This mod has no hard dependencies whatsoever, so you can use it as you will.
|
||||
However, I do recommend using the [skylayer](https://gitlab.com/rautars/skylayer) mod.
|
||||
With the Minetest's new sky API it is likely for more mods to change the sky configuration,
|
||||
possibly resulting in conflict. This utility mod can help circumvent these issues if both mods use it.
|
||||
If you are also using *climate_api* then it will use the included skybox registration instead of overriding the player configuration. Thus, moon_phases will will be compatible with your weather packs.
|
||||
|
||||
## Changes in v2.0
|
||||
- New classic moon textures!
|
||||
- Skybox changes. The sky will brighten up during a full moon and turn dark during a new moon.
|
||||
- Less stored data: Moon cycle now used Minetest's ``get_day_count()`` and only stores a date offset when changed via commands.
|
||||
- Climate API integration. Use moon phases with your favorite weather mod
|
||||
|
||||
## Commands
|
||||
This mod comes with two commands to print or change the current moon phase.
|
||||
@ -35,12 +39,12 @@ This results in a total cycle of 32 days.
|
||||
You can also set the default texture style for all players. You can choose between the same options as with the ``/set_moonstyle`` command.
|
||||
|
||||
## LICENSE
|
||||
All source code is licensed under GNU LESSER GENERAL PUBLIC LICENSE version 3.
|
||||
All source code is written by me and licensed under GNU LESSER GENERAL PUBLIC LICENSE version 3.
|
||||
You can find a copy of that license in the repository.
|
||||
|
||||
## Media
|
||||
All moon textures marked as "classic" are made by me. You can use them under a CC0 license.
|
||||
All moon textures marked as "classic" are made by Cap for this mod and usable under a *CC BY-SA (3.0)* license.
|
||||
|
||||
All included "realistic" moon textures are resized versions of graphics from *NASA's Scientific Visualization Studio* by [Ernie Wright](https://svs.gsfc.nasa.gov/cgi-bin/search.cgi?person=1059).
|
||||
These images are part of the Public Domain as CC-BY-SA 3.0.
|
||||
These images are part of the Public Domain as *CC BY-SA 3.0*.
|
||||
You can access the entire (high resolution) album on [their website](https://svs.gsfc.nasa.gov/4769#28564). See [NASA's media guidelines](https://www.nasa.gov/multimedia/guidelines/index.html) for more information on licensing.
|
||||
|
148
init.lua
@ -1,94 +1,126 @@
|
||||
local mod_climate_api = minetest.get_modpath("climate_api") ~= nil
|
||||
local mod_skylayer = minetest.get_modpath("skylayer") ~= nil
|
||||
|
||||
local modpath = minetest.get_modpath("moon_phases");
|
||||
|
||||
local GSCYCLE = 0.5 -- global step cycle
|
||||
local DEFAULT_LENGTH = 4 -- default cycle length
|
||||
local DEFAULT_STYLE = "realistic" -- default texture style
|
||||
|
||||
moon_phases = {}
|
||||
local state = minetest.get_mod_storage()
|
||||
if not state:contains("day") then
|
||||
state:from_table({
|
||||
day = 1,
|
||||
phase = 1,
|
||||
change_time = 1
|
||||
})
|
||||
end
|
||||
local GSCYCLE = 0.5 -- global step cycle in seconds
|
||||
local DEFAULT_LENGTH = 4 -- default moon cycle length in days
|
||||
local DEFAULT_STYLE = "classic" -- default texture style
|
||||
local PHASE_COUNT = 8 -- number of phases to go through
|
||||
|
||||
-- retrieve mod configuration
|
||||
local PHASE_LENGTH = minetest.settings:get("moon_phases_cycle") or DEFAULT_LENGTH
|
||||
local PHASE_LENGTH = tonumber(minetest.settings:get("moon_phases_cycle") or DEFAULT_LENGTH)
|
||||
local TEXTURE_STYLE = minetest.settings:get("moon_phases_style") or DEFAULT_STYLE
|
||||
|
||||
local sky_color = {
|
||||
"#1d293aff",
|
||||
"#1c4b8dff",
|
||||
nil,
|
||||
"#579dffff",
|
||||
nil,
|
||||
"#1c4b8dff",
|
||||
"#1d293aff",
|
||||
"#000000ff"
|
||||
}
|
||||
|
||||
local horizon_color = {
|
||||
"#243347ff",
|
||||
"#235fb3ff",
|
||||
nil,
|
||||
"#73aeffff",
|
||||
nil,
|
||||
"#3079dfff",
|
||||
"#173154ff",
|
||||
"#000000ff"
|
||||
}
|
||||
|
||||
moon_phases = {}
|
||||
local phase = 1
|
||||
local state = minetest.get_mod_storage()
|
||||
|
||||
-- calculate current moon phase from date
|
||||
-- and stored date offset
|
||||
local function calculate_phase()
|
||||
local time = minetest.get_timeofday()
|
||||
local day = minetest.get_day_count() + state:get_int("date_offset")
|
||||
if time > 0.5 then
|
||||
day = day + 1
|
||||
end
|
||||
return ((math.ceil(day / PHASE_LENGTH) - 1) % PHASE_COUNT) + 1
|
||||
end
|
||||
|
||||
-- return the current moon phase
|
||||
function moon_phases.get_phase()
|
||||
return phase
|
||||
end
|
||||
|
||||
-- set the moon texture of a player to the given phase
|
||||
local function set_texture(player, phase)
|
||||
local sl = {}
|
||||
if not player.get_stars then return end -- check for new sky API
|
||||
local meta_data = player:get_meta()
|
||||
local style = meta_data:get_string("moon_phases:texture_style")
|
||||
if style ~= "classic" and style ~= "realistic" then
|
||||
style = TEXTURE_STYLE
|
||||
end
|
||||
local texture = "moon_" .. phase .. "_" .. style .. ".png"
|
||||
sl.name = "moon_phases:custom"
|
||||
sl.moon_data = {
|
||||
local name = "moon_phases:cycle"
|
||||
local sky = {}
|
||||
sky.sky_data = {
|
||||
type = "regular",
|
||||
sky_color = {
|
||||
night_sky = sky_color[phase],
|
||||
night_horizon = horizon_color[phase]
|
||||
}
|
||||
}
|
||||
sky.moon_data = {
|
||||
visible = true,
|
||||
texture = texture,
|
||||
scale = 0.8
|
||||
}
|
||||
if mod_skylayer then
|
||||
skylayer.add_layer(player:get_player_name(), sl)
|
||||
local playername = player:get_player_name()
|
||||
if mod_climate_api then
|
||||
sky.priority = 0
|
||||
climate_api.skybox.add(playername, name, sky)
|
||||
elseif mod_skylayer then
|
||||
sky.name = name
|
||||
skylayer.add_layer(playername, sky)
|
||||
else
|
||||
player:set_moon(sl.moon_data)
|
||||
end
|
||||
end
|
||||
|
||||
-- update moon textures of all online players
|
||||
local function update_textures()
|
||||
local phase = state:get_int("phase")
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
set_texture(player, phase)
|
||||
player:set_sky(sky.sky_data)
|
||||
player:set_moon(sky.moon_data)
|
||||
end
|
||||
end
|
||||
|
||||
-- check for day changes
|
||||
local function handle_time_progression()
|
||||
local time = minetest.get_timeofday()
|
||||
local day = state:get_int("day")
|
||||
local phase = state:get_int("phase")
|
||||
local change_time = state:get_int("change_time") == 1
|
||||
if time >= 0.5 and change_time then
|
||||
day = day + 1
|
||||
state:set_int("day", day)
|
||||
if day % PHASE_LENGTH == 0 then
|
||||
state:set_int("phase", (phase % 8) + 1)
|
||||
state:set_int("change_time", 0)
|
||||
update_textures()
|
||||
end
|
||||
elseif time < 0.5 and not change_time then
|
||||
state:set_int("change_time", 1)
|
||||
local n_phase = calculate_phase()
|
||||
if n_phase ~= phase then
|
||||
phase = n_phase
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
set_texture(player, phase)
|
||||
end
|
||||
end
|
||||
|
||||
-- return the current moon phase
|
||||
function moon_phases.get_phase()
|
||||
return state:get_int("phase")
|
||||
end
|
||||
|
||||
-- set the current moon phase
|
||||
-- @param phase int Phase between 1 and 8
|
||||
function moon_phases.set_phase(phase)
|
||||
phase = math.floor(tonumber(phase))
|
||||
if (not phase) or phase < 1 or phase > 8 then
|
||||
-- @param phase int Phase between 1 and PHASE_COUNT
|
||||
function moon_phases.set_phase(nphase)
|
||||
nphase = math.floor(tonumber(nphase))
|
||||
if (not nphase) or nphase < 1 or nphase > PHASE_COUNT then
|
||||
return false
|
||||
end
|
||||
state:set_int("phase", phase)
|
||||
update_textures()
|
||||
local day = minetest.get_day_count()
|
||||
local date_offset = state:get_int("date_offset")
|
||||
local progress = (day + date_offset) % PHASE_LENGTH
|
||||
local phase_offset = (nphase - phase + PHASE_COUNT) % PHASE_COUNT
|
||||
local add_offset = ((phase_offset * PHASE_LENGTH) + date_offset - progress)
|
||||
state:set_int("date_offset", add_offset)
|
||||
handle_time_progression()
|
||||
return true
|
||||
end
|
||||
|
||||
-- set the moon's texture style for the given player
|
||||
function moon_phases.set_style(player, style)
|
||||
if style ~= "classic" and style ~= "realistic" then
|
||||
if style ~= nil and style ~= "classic" and style ~= "realistic" then
|
||||
return false
|
||||
end
|
||||
local meta_data = player:get_meta()
|
||||
@ -99,14 +131,11 @@ end
|
||||
|
||||
-- set the moon texture of newly joined player
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local phase = state:get_int("phase")
|
||||
-- phase might not have been set at server start
|
||||
if phase < 1 then phase = 1 end
|
||||
set_texture(player, phase)
|
||||
end)
|
||||
|
||||
-- check for day changes and call handlers
|
||||
local timer = 0
|
||||
local timer = math.huge
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
if timer < GSCYCLE then return end
|
||||
@ -114,5 +143,10 @@ minetest.register_globalstep(function(dtime)
|
||||
timer = 0
|
||||
end)
|
||||
|
||||
-- make moon phase available to weather effects
|
||||
if mod_climate_api then
|
||||
climate_api.register_global_influence("moonphase", moon_phases.get_phase)
|
||||
end
|
||||
|
||||
-- include API for chat commands
|
||||
dofile(modpath .. "/commands.lua")
|
6
mod.conf
@ -1,10 +1,12 @@
|
||||
name = moon_phases
|
||||
title = Moon Phases
|
||||
author = TestificateMods
|
||||
release = 10100
|
||||
description = """
|
||||
Changes the moon to follow a cycle between eight different phases.
|
||||
Expect the sky to change every four nights (or configure a custom schedule).
|
||||
Includes realistic 256x256px moon textures from NASA photographies as well as
|
||||
square vanilla themed 16x16px textures
|
||||
|
||||
Requires at least Minetest 5.2.0
|
||||
"""
|
||||
optional_depends = skylayer
|
||||
optional_depends = climate_api, skylayer
|
||||
|
BIN
screenshot.2.png
Before Width: | Height: | Size: 548 KiB After Width: | Height: | Size: 700 KiB |
BIN
screenshot.png
Before Width: | Height: | Size: 700 KiB After Width: | Height: | Size: 1.3 MiB |
@ -1,2 +1,6 @@
|
||||
# The moon will switch to the next phase every X days.
|
||||
moon_phases_cycle (Change moon phase every X days) int 4
|
||||
moon_phases_style (Choose a default texture style) enum realistic classic,realistic
|
||||
|
||||
# Use classic for a default-inspired set of textures.
|
||||
# Use realistic for a set of down-scaled NASA photography.
|
||||
moon_phases_style (Choose a default texture style) enum classic classic,realistic
|
Before Width: | Height: | Size: 610 B After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 638 B After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 576 B After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 269 B After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 545 B After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 602 B After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 620 B After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 75 B After Width: | Height: | Size: 5.7 KiB |