Implement classic texture style and allow users to choose
18
commands.lua
@ -28,4 +28,22 @@ minetest.register_chatcommand("set_moonphase", {
|
|||||||
end
|
end
|
||||||
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
|
||||||
})
|
})
|
40
init.lua
@ -16,22 +16,19 @@ if not state:contains("day") then
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- retrieve and parse mod configuration
|
-- retrieve mod configuration
|
||||||
local function get_cycle_config()
|
local PHASE_LENGTH = minetest.settings:get("moon_phases_cycle") or DEFAULT_LENGTH
|
||||||
local config = minetest.settings:get("moon_phases_cycle") or DEFAULT_LENGTH
|
local TEXTURE_STYLE = minetest.settings:get("moon_phases_style") or DEFAULT_STYLE
|
||||||
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()
|
-- set the moon texture of a player to the given phase
|
||||||
|
local function set_texture(player, phase)
|
||||||
-- set the moon texture of a player to the given texture
|
|
||||||
local function set_texture(player, texture)
|
|
||||||
local sl = {}
|
local sl = {}
|
||||||
|
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.name = "moon_phases:custom"
|
||||||
sl.moon_data = {
|
sl.moon_data = {
|
||||||
visible = true,
|
visible = true,
|
||||||
@ -49,7 +46,7 @@ end
|
|||||||
local function update_textures()
|
local function update_textures()
|
||||||
local phase = state:get_int("phase")
|
local phase = state:get_int("phase")
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
set_texture(player, "moon_" .. phase .. ".png")
|
set_texture(player, phase)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -89,12 +86,23 @@ function moon_phases.set_phase(phase)
|
|||||||
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 ~= "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
|
-- set the moon texture of newly joined player
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local phase = state:get_int("phase")
|
local phase = state:get_int("phase")
|
||||||
-- phase might not have been set at server start
|
-- phase might not have been set at server start
|
||||||
if phase < 1 then phase = 1 end
|
if phase < 1 then phase = 1 end
|
||||||
set_texture(player, "moon_" .. phase .. ".png")
|
set_texture(player, phase)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- check for day changes and call handlers
|
-- check for day changes and call handlers
|
||||||
|
@ -1 +1,2 @@
|
|||||||
moon_phases_cycle (Change moon phase every X days) int 4
|
moon_phases_cycle (Change moon phase every X days) int 4
|
||||||
|
moon_phases_style (Choose a default texture style) enum classic classic,realistic
|
BIN
textures/moon_1_classic.png
Normal file
After Width: | Height: | Size: 610 B |
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
BIN
textures/moon_2_classic.png
Normal file
After Width: | Height: | Size: 638 B |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
BIN
textures/moon_3_classic.png
Normal file
After Width: | Height: | Size: 576 B |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
BIN
textures/moon_4_classic.png
Normal file
After Width: | Height: | Size: 269 B |
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 93 KiB |
BIN
textures/moon_5_classic.png
Normal file
After Width: | Height: | Size: 545 B |
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 80 KiB |
BIN
textures/moon_6_classic.png
Normal file
After Width: | Height: | Size: 602 B |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
BIN
textures/moon_7_classic.png
Normal file
After Width: | Height: | Size: 620 B |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
BIN
textures/moon_8_classic.png
Normal file
After Width: | Height: | Size: 75 B |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |