master #5

Merged
epCode merged 255 commits from VoxeLibre/VoxeLibre:master into master 2021-02-02 23:20:01 +01:00
4 changed files with 156 additions and 155 deletions
Showing only changes of commit f20f9f9a88 - Show all commits

View File

@ -1,4 +1,4 @@
local modpath = minetest.get_modpath("mcl_weather"); local modpath = minetest.get_modpath("mcl_weather")
mcl_weather = {} mcl_weather = {}

View File

@ -24,11 +24,8 @@ end
local timer = 0 local timer = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
timer = timer + dtime timer = timer + dtime
if timer >= 0.7 then if timer < 0.7 then return end
timer = 0 timer = 0
else
return
end
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
if not mcl_worlds.has_dust(player:get_pos()) then if not mcl_worlds.has_dust(player:get_pos()) then

View File

@ -40,7 +40,7 @@ local storage = minetest.get_mod_storage()
local save_weather = function() local save_weather = function()
storage:set_string("mcl_weather_state", mcl_weather.state) storage:set_string("mcl_weather_state", mcl_weather.state)
storage:set_int("mcl_weather_end_time", mcl_weather.end_time) storage:set_int("mcl_weather_end_time", mcl_weather.end_time)
minetest.log("action", "[mcl_weather] Weather data saved: state="..mcl_weather.state.." end_time="..mcl_weather.end_time) minetest.log("verbose", "[mcl_weather] Weather data saved: state="..mcl_weather.state.." end_time="..mcl_weather.end_time)
end end
minetest.register_on_shutdown(save_weather) minetest.register_on_shutdown(save_weather)
@ -164,11 +164,15 @@ end
-- Change weather to new_weather. -- Change weather to new_weather.
-- * explicit_end_time is OPTIONAL. If specified, explicitly set the -- * explicit_end_time is OPTIONAL. If specified, explicitly set the
-- gametime (minetest.get_gametime) in which the weather ends. -- gametime (minetest.get_gametime) in which the weather ends.
mcl_weather.change_weather = function(new_weather, explicit_end_time) -- * changer is OPTIONAL, for logging purposes.
mcl_weather.change_weather = function(new_weather, explicit_end_time, changer_name)
local changer_name = changer_name or debug.getinfo(2).name
if (mcl_weather.reg_weathers ~= nil and mcl_weather.reg_weathers[new_weather] ~= nil) then if (mcl_weather.reg_weathers ~= nil and mcl_weather.reg_weathers[new_weather] ~= nil) then
if (mcl_weather.state ~= nil and mcl_weather.reg_weathers[mcl_weather.state] ~= nil) then if (mcl_weather.state ~= nil and mcl_weather.reg_weathers[mcl_weather.state] ~= nil) then
mcl_weather.reg_weathers[mcl_weather.state].clear() mcl_weather.reg_weathers[mcl_weather.state].clear()
end end
minetest.log("action", "[mcl_weather] " .. changer_name .. " changed the weather from " .. mcl_weather.state .. " to " .. new_weather)
mcl_weather.state = new_weather mcl_weather.state = new_weather
local weather_meta = mcl_weather.reg_weathers[mcl_weather.state] local weather_meta = mcl_weather.reg_weathers[mcl_weather.state]
if explicit_end_time then if explicit_end_time then
@ -222,7 +226,7 @@ minetest.register_chatcommand("weather", {
end end
end end
local success = mcl_weather.change_weather(new_weather, end_time) local success = mcl_weather.change_weather(new_weather, end_time, name)
if success then if success then
return true return true
else else
@ -238,13 +242,13 @@ minetest.register_chatcommand("toggledownfall", {
func = function(name, param) func = function(name, param)
-- Currently rain/thunder/snow: Set weather to clear -- Currently rain/thunder/snow: Set weather to clear
if mcl_weather.state ~= "none" then if mcl_weather.state ~= "none" then
return mcl_weather.change_weather("none") return mcl_weather.change_weather("none", nil, name)
-- Currently clear: Set weather randomly to rain/thunder/snow -- Currently clear: Set weather randomly to rain/thunder/snow
else else
local new = { "rain", "thunder", "snow" } local new = { "rain", "thunder", "snow" }
local r = math.random(1, #new) local r = math.random(1, #new)
return mcl_weather.change_weather(new[r]) return mcl_weather.change_weather(new[r], nil, name)
end end
end end
}) })