Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
79992a0445 | |||
f9182cae3f | |||
3e6abe5e42 | |||
b0aed595e5 | |||
22528c2e67 | |||
77f6c3695c | |||
46471862e9 | |||
42fa044c48 | |||
fa93b311d6 | |||
d5c611c9fc | |||
e2220440ec | |||
b81669c9da | |||
e07af4cdd2 | |||
05fd6a98d5 |
28
README.md
@ -1,19 +1,25 @@
|
|||||||
# Moon phases
|
# Moon phases
|
||||||
Make your sky change follow a cycle
|
Make your moon follow a realistic cycle
|
||||||
|
|
||||||
__Important__: This mod requires at least Minetest 5.2.0 for the game's new sky API.
|
__Important__: This mod requires at least Minetest 5.2.0 for the game's new sky API.
|
||||||
Make sure you have the latest version installed or [update your game](https://www.minetest.net/downloads/).
|
Make sure you have the latest version installed or [update your game](https://www.minetest.net/downloads/).
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
This mod has no hard dependencies whatsoever, so you can use it as you will.
|
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.
|
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.
|
||||||
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.
|
## 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
|
## Commands
|
||||||
This mod comes with two commands to print or change the current moon phase.
|
This mod comes with two commands to print or change the current moon phase.
|
||||||
- Use ``/moonphase`` to view the currently active phase.
|
- Use ``/moonphase`` to view the currently active phase.
|
||||||
- Use ``/set_moonphase <phase>`` to change it. ``<phase>`` has to be a full number between 1 and 8.
|
- Use ``/set_moonphase <phase>`` to change it. ``<phase>`` has to be a full number between 1 and 8.
|
||||||
|
- Use ``/set_moonstyle <style>`` to choose a texture preset. ``classic`` will result in a quadratic moon
|
||||||
|
inspired by default Minetest. ``realistic`` will result in 256x images of the real moon.
|
||||||
|
|
||||||
In order to change the phase, you will need the corresponding privilege.
|
In order to change the phase, you will need the corresponding privilege.
|
||||||
Use ``/grant <player> moonphase`` to grant it.
|
Use ``/grant <player> moonphase`` to grant it.
|
||||||
@ -22,17 +28,23 @@ Use ``/grant <player> moonphase`` to grant it.
|
|||||||
Just like the chat commands, this mod provides a LUA api for accessing the moon phase.
|
Just like the chat commands, this mod provides a LUA api for accessing the moon phase.
|
||||||
It contains a method called ``moon_phases.get_phase()`` that will return a numeric value representing the current moon phase.
|
It contains a method called ``moon_phases.get_phase()`` that will return a numeric value representing the current moon phase.
|
||||||
You can also set the phase via ``moon_phases.set_phase(phase)`` where ``phase`` is an integer between 1 and 8.
|
You can also set the phase via ``moon_phases.set_phase(phase)`` where ``phase`` is an integer between 1 and 8.
|
||||||
|
The texture style of a specific player can be set with ``moon_phases.set_style(player, style)`` where ``style`` referes to either
|
||||||
|
``classic`` or ``realistic``.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
The mod provides the option to change the length of the moon cycle.
|
The mod provides the option to change the length of the moon cycle.
|
||||||
By default, the moon texture will change every four (in-game) nights.
|
By default, the moon texture will change every four (in-game) nights.
|
||||||
This results in a total cycle of 32 days.
|
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
|
## 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.
|
You can find a copy of that license in the repository.
|
||||||
|
|
||||||
## Media
|
## Media
|
||||||
All included moon textures are resized versions of graphics from *NASA's Scientific Visualization Studio*.
|
All moon textures marked as "classic" are made by Cap for this mod and usable under a *CC BY-SA (3.0)* license.
|
||||||
These images are part of the Public Domain.
|
|
||||||
You can access the entire (high resolution) album on [their website](https://svs.gsfc.nasa.gov/4769#28564).
|
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*.
|
||||||
|
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.
|
||||||
|
20
commands.lua
@ -15,7 +15,7 @@ minetest.register_chatcommand("moonphase", {
|
|||||||
minetest.register_chatcommand("set_moonphase", {
|
minetest.register_chatcommand("set_moonphase", {
|
||||||
params = "<phase>",
|
params = "<phase>",
|
||||||
description = "Set moon phase to given value",
|
description = "Set moon phase to given value",
|
||||||
privs = {moonphase = true},
|
privs = { moonphase = true },
|
||||||
func = function(playername, param)
|
func = function(playername, param)
|
||||||
if param == nil or param == "" then
|
if param == nil or param == "" then
|
||||||
minetest.chat_send_player(playername, "Provide a number between 1 and 8")
|
minetest.chat_send_player(playername, "Provide a number between 1 and 8")
|
||||||
@ -29,3 +29,21 @@ minetest.register_chatcommand("set_moonphase", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_chatcommand("set_moonstyle", {
|
||||||
|
params = "<style>",
|
||||||
|
description = "Set your moon's texture style to the given preset",
|
||||||
|
func = function(playername, param)
|
||||||
|
if param == nil or param == "" then
|
||||||
|
minetest.chat_send_player(playername, "Provide a texture style. Possible styles are classic or realistic")
|
||||||
|
else
|
||||||
|
local player = minetest.get_player_by_name(playername)
|
||||||
|
local change = moon_phases.set_style(player, param)
|
||||||
|
if change then
|
||||||
|
minetest.chat_send_player(playername, "Moon texture changed successfully")
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(playername, "Invalid argument. Provide a valid preset.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
@ -1,48 +0,0 @@
|
|||||||
local mod_datastorage = minetest.get_modpath("datastorage") ~= nil
|
|
||||||
|
|
||||||
local default_state = {
|
|
||||||
change_time = true,
|
|
||||||
day = 1,
|
|
||||||
phase = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
local function use_datastorage()
|
|
||||||
local state = datastorage.get("moon_phases", "moon_state")
|
|
||||||
for key, val in pairs(default_state) do
|
|
||||||
if type(state[key]) == "nil" then
|
|
||||||
state[key] = val
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return state
|
|
||||||
end
|
|
||||||
|
|
||||||
local storage
|
|
||||||
local function use_filesystem()
|
|
||||||
local file_name = minetest.get_worldpath() .. "/moon_phases"
|
|
||||||
minetest.register_on_shutdown(function()
|
|
||||||
local file = io.open(file_name, "w")
|
|
||||||
file:write(minetest.serialize(storage))
|
|
||||||
file:close()
|
|
||||||
end)
|
|
||||||
|
|
||||||
local file = io.open(file_name, "r")
|
|
||||||
if file ~= nil then
|
|
||||||
storage = minetest.deserialize(file:read("*a"))
|
|
||||||
file:close()
|
|
||||||
if type(storage) == "table" then
|
|
||||||
return storage
|
|
||||||
end
|
|
||||||
end
|
|
||||||
storage = default_state
|
|
||||||
return storage
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_storage()
|
|
||||||
if mod_datastorage then
|
|
||||||
return use_datastorage()
|
|
||||||
else
|
|
||||||
return use_filesystem()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return get_storage
|
|
@ -1 +0,0 @@
|
|||||||
skylayer?
|
|
@ -1,3 +0,0 @@
|
|||||||
Changes the moon to follow a cycle between eight different phases.
|
|
||||||
Expect the sky to change every four nights (or configure a custom schedule).
|
|
||||||
Requires at least Minetest 5.2.0
|
|
180
init.lua
@ -1,81 +1,141 @@
|
|||||||
|
local mod_climate_api = minetest.get_modpath("climate_api") ~= nil
|
||||||
local mod_skylayer = minetest.get_modpath("skylayer") ~= nil
|
local mod_skylayer = minetest.get_modpath("skylayer") ~= nil
|
||||||
|
|
||||||
local modpath = minetest.get_modpath("moon_phases");
|
local modpath = minetest.get_modpath("moon_phases");
|
||||||
local state = dofile(modpath .. "/datastorage.lua")()
|
|
||||||
|
|
||||||
local GSCYCLE = 0.5
|
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 = 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 = {}
|
moon_phases = {}
|
||||||
|
local phase = 1
|
||||||
|
local state = minetest.get_mod_storage()
|
||||||
|
|
||||||
local function get_cycle_config()
|
-- calculate current moon phase from date
|
||||||
local DEFAULT_LENGTH = 4
|
-- and stored date offset
|
||||||
local config = minetest.settings:get("moon_phases_cycle") or DEFAULT_LENGTH
|
local function calculate_phase()
|
||||||
config = math.floor(tonumber(config))
|
|
||||||
if (not config) or config < 0 then
|
|
||||||
minetest.log("warning", "[Moon Phases] Invalid cycle configuration")
|
|
||||||
return DEFAULT_LENGTH
|
|
||||||
end
|
|
||||||
return config
|
|
||||||
end
|
|
||||||
|
|
||||||
local PHASE_LENGTH = get_cycle_config()
|
|
||||||
if state.day >= PHASE_LENGTH then
|
|
||||||
state.day = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
local function set_texture(player, texture)
|
|
||||||
local sl = {}
|
|
||||||
sl.name = "moon_phases:custom"
|
|
||||||
sl.moon_data = {
|
|
||||||
visible = true,
|
|
||||||
texture = texture
|
|
||||||
}
|
|
||||||
if mod_skylayer then
|
|
||||||
skylayer.add_layer(player:get_player_name(), sl)
|
|
||||||
else
|
|
||||||
player:set_moon(sl.moon_data)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function update_textures()
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
|
||||||
set_texture(player, "moon_" .. state.phase .. ".png")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function handle_time_progression()
|
|
||||||
local time = minetest.get_timeofday()
|
local time = minetest.get_timeofday()
|
||||||
if time >= 0.5 and state.change_time then
|
local day = minetest.get_day_count() + state:get_int("date_offset")
|
||||||
state.day = state.day + 1
|
if time > 0.5 then
|
||||||
if state.day == PHASE_LENGTH then
|
day = day + 1
|
||||||
state.day = 1
|
|
||||||
state.phase = (state.phase % 8) + 1
|
|
||||||
state.change_time = false
|
|
||||||
update_textures()
|
|
||||||
end
|
|
||||||
elseif time < 0.5 and not state.change_time then
|
|
||||||
state.change_time = true
|
|
||||||
end
|
end
|
||||||
|
return ((math.ceil(day / PHASE_LENGTH) - 1) % PHASE_COUNT) + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- return the current moon phase
|
||||||
function moon_phases.get_phase()
|
function moon_phases.get_phase()
|
||||||
return state.phase
|
return phase
|
||||||
end
|
end
|
||||||
|
|
||||||
function moon_phases.set_phase(phase)
|
-- set the moon texture of a player to the given phase
|
||||||
phase = math.floor(tonumber(phase))
|
local function set_texture(player, phase)
|
||||||
if (not phase) or phase < 0 or phase > 8 then
|
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"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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_sky(sky.sky_data)
|
||||||
|
player:set_moon(sky.moon_data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check for day changes
|
||||||
|
local function handle_time_progression()
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
-- set the current moon phase
|
||||||
|
-- @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
|
return false
|
||||||
end
|
end
|
||||||
state.phase = phase
|
local day = minetest.get_day_count()
|
||||||
update_textures()
|
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
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- set the moon's texture style for the given player
|
||||||
|
function moon_phases.set_style(player, style)
|
||||||
|
if style ~= nil and style ~= "classic" and style ~= "realistic" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local meta_data = player:get_meta()
|
||||||
|
meta_data:set_string("moon_phases:texture_style", style)
|
||||||
|
set_texture(player, state:get_int("phase"))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- set the moon texture of newly joined player
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
set_texture(player, "moon_" .. state.phase .. ".png")
|
set_texture(player, phase)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local timer = 0
|
-- check for day changes and call handlers
|
||||||
|
local timer = math.huge
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if timer < GSCYCLE then return end
|
if timer < GSCYCLE then return end
|
||||||
@ -83,4 +143,10 @@ minetest.register_globalstep(function(dtime)
|
|||||||
timer = 0
|
timer = 0
|
||||||
end)
|
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")
|
dofile(modpath .. "/commands.lua")
|
10
mod.conf
@ -1,4 +1,12 @@
|
|||||||
name = moon_phases
|
name = moon_phases
|
||||||
title = Moon Phases
|
title = Moon Phases
|
||||||
author = TestificateMods
|
author = TestificateMods
|
||||||
release = 1
|
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 = climate_api, skylayer
|
||||||
|
BIN
screenshot.2.png
Normal file
After Width: | Height: | Size: 700 KiB |
BIN
screenshot.3.png
Normal file
After Width: | Height: | Size: 608 KiB |
BIN
screenshot.png
Before Width: | Height: | Size: 548 KiB After Width: | Height: | Size: 1.3 MiB |
@ -1 +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_cycle (Change moon phase every X days) int 4
|
||||||
|
|
||||||
|
# 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
|
BIN
textures/moon_1_classic.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
BIN
textures/moon_2_classic.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
BIN
textures/moon_3_classic.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
BIN
textures/moon_4_classic.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 93 KiB |
BIN
textures/moon_5_classic.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 80 KiB |
BIN
textures/moon_6_classic.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
BIN
textures/moon_7_classic.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
BIN
textures/moon_8_classic.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |