mirror of
https://github.com/t-affeldt/minetest_moon_phase.git
synced 2025-01-05 07:40:33 +01:00
Update for Climate API changes
This commit is contained in:
parent
b0aed595e5
commit
3e6abe5e42
19
init.lua
19
init.lua
@ -3,13 +3,13 @@ local mod_skylayer = minetest.get_modpath("skylayer") ~= nil
|
|||||||
|
|
||||||
local modpath = minetest.get_modpath("moon_phases");
|
local modpath = minetest.get_modpath("moon_phases");
|
||||||
|
|
||||||
local GSCYCLE = 0.5 -- global step cycle
|
local GSCYCLE = 0.5 -- global step cycle in seconds
|
||||||
local DEFAULT_LENGTH = 4 -- default cycle length
|
local DEFAULT_LENGTH = 4 -- default moon cycle length in days
|
||||||
local DEFAULT_STYLE = "classic" -- default texture style
|
local DEFAULT_STYLE = "classic" -- default texture style
|
||||||
local PHASE_COUNT = 8 -- number of phases to go through
|
local PHASE_COUNT = 8 -- number of phases to go through
|
||||||
|
|
||||||
-- retrieve mod configuration
|
-- retrieve mod configuration
|
||||||
local PHASE_LENGTH = 4--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 TEXTURE_STYLE = minetest.settings:get("moon_phases_style") or DEFAULT_STYLE
|
||||||
|
|
||||||
local sky_color = {
|
local sky_color = {
|
||||||
@ -35,6 +35,7 @@ local horizon_color = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moon_phases = {}
|
moon_phases = {}
|
||||||
|
local phase = 1
|
||||||
local state = minetest.get_mod_storage()
|
local state = minetest.get_mod_storage()
|
||||||
|
|
||||||
-- calculate current moon phase from date
|
-- calculate current moon phase from date
|
||||||
@ -48,8 +49,6 @@ local function calculate_phase()
|
|||||||
return ((math.ceil(day / PHASE_LENGTH) - 1) % PHASE_COUNT) + 1
|
return ((math.ceil(day / PHASE_LENGTH) - 1) % PHASE_COUNT) + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local phase = 1
|
|
||||||
|
|
||||||
-- return the current moon phase
|
-- return the current moon phase
|
||||||
function moon_phases.get_phase()
|
function moon_phases.get_phase()
|
||||||
return phase
|
return phase
|
||||||
@ -81,7 +80,7 @@ local function set_texture(player, phase)
|
|||||||
local playername = player:get_player_name()
|
local playername = player:get_player_name()
|
||||||
if mod_climate_api then
|
if mod_climate_api then
|
||||||
sky.priority = 0
|
sky.priority = 0
|
||||||
climate_api.skybox.add_layer(playername, name, sky)
|
climate_api.skybox.add(playername, name, sky)
|
||||||
elseif mod_skylayer then
|
elseif mod_skylayer then
|
||||||
sky.name = name
|
sky.name = name
|
||||||
skylayer.add_layer(playername, sky)
|
skylayer.add_layer(playername, sky)
|
||||||
@ -124,7 +123,6 @@ function moon_phases.set_style(player, style)
|
|||||||
if style ~= nil and style ~= "classic" and style ~= "realistic" then
|
if style ~= nil and style ~= "classic" and style ~= "realistic" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
--if style == DEFAULT_STYLE then style = nil end
|
|
||||||
local meta_data = player:get_meta()
|
local meta_data = player:get_meta()
|
||||||
meta_data:set_string("moon_phases:texture_style", style)
|
meta_data:set_string("moon_phases:texture_style", style)
|
||||||
set_texture(player, state:get_int("phase"))
|
set_texture(player, state:get_int("phase"))
|
||||||
@ -145,5 +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
|
-- include API for chat commands
|
||||||
dofile(modpath .. "/commands.lua")
|
dofile(modpath .. "/commands.lua")
|
||||||
|
Loading…
Reference in New Issue
Block a user