forked from Mineclonia/Mineclonia
fix weather cycle
This commit is contained in:
parent
2ed3e01179
commit
336c188ab7
|
@ -196,29 +196,40 @@ end
|
||||||
|
|
||||||
function mcl_weather.change(new_weather,force)
|
function mcl_weather.change(new_weather,force)
|
||||||
if new_weather == mcl_weather.current then return end
|
if new_weather == mcl_weather.current then return end
|
||||||
if not force and os.time() < mcl_weather.current_endtime then return end
|
|
||||||
local def=mcl_weather.get_weatherdef(new_weather)
|
local def=mcl_weather.get_weatherdef(new_weather)
|
||||||
local old=mcl_weather.get_weatherdef(mcl_weather.current)
|
local old=mcl_weather.get_weatherdef(mcl_weather.current)
|
||||||
if not def then return end
|
if not def then return end
|
||||||
local duration = math.random(def.min_duration,def.max_duration)
|
|
||||||
if force or minetest.settings:get_bool("mcl_doWeatherCycle") then
|
if force or minetest.settings:get_bool("mcl_doWeatherCycle") then
|
||||||
mcl_weather.stop_weather(old)
|
mcl_weather.stop_weather(old)
|
||||||
mcl_weather.start_weather(def)
|
mcl_weather.start_weather(def)
|
||||||
mcl_weather.current = new_weather
|
mcl_weather.current = new_weather
|
||||||
mcl_weather.state = new_weather
|
mcl_weather.state = new_weather
|
||||||
mcl_weather.current_endtime = os.time() + duration
|
|
||||||
end
|
end
|
||||||
minetest.after(duration,function()
|
|
||||||
mcl_weather.change(mcl_weather.get_next_weather())
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mcl_weather.seasonal_change()
|
||||||
|
local new=mcl_weather.get_next_weather()
|
||||||
|
local def=mcl_weather.get_weatherdef(new)
|
||||||
|
local duration = math.random(def.min_duration,def.max_duration)
|
||||||
|
mcl_weather.current_endtime = os.time() + duration
|
||||||
|
minetest.log("action", "[mcl_weather] Weather changed from " .. mcl_weather.current .. " to " .. new .. " Duration: "..duration)
|
||||||
|
mcl_weather.change(new)
|
||||||
|
minetest.after(duration,mcl_weather.seasonal_change)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_mods_loaded(function()
|
||||||
|
minetest.after(5,mcl_weather.seasonal_change)
|
||||||
|
end)
|
||||||
|
|
||||||
function mcl_weather.change_player(name,new)
|
function mcl_weather.change_player(name,new)
|
||||||
if players.weather[name] ~= new then
|
if players.weather[name] ~= new then
|
||||||
local nd = mcl_weather.get_weatherdef(new)
|
local nd = mcl_weather.get_weatherdef(new)
|
||||||
local od=mcl_weather.get_weatherdef(mcl_weather.current)
|
local od=mcl_weather.get_weatherdef(mcl_weather.current)
|
||||||
if players.weather[name] ~= nil then
|
if players.weather[name] ~= nil then
|
||||||
|
minetest.log("action", "[mcl_weather] Weather for ".. name .." changed from "..players.weather[name].. " to "..new)
|
||||||
od=mcl_weather.get_weatherdef(players.weather[name])
|
od=mcl_weather.get_weatherdef(players.weather[name])
|
||||||
|
else
|
||||||
|
minetest.log("action", "[mcl_weather] Weather for ".. name .." changed from "..mcl_weather.current.. " to "..new)
|
||||||
end
|
end
|
||||||
if nd then
|
if nd then
|
||||||
mcl_weather.stop_weather_player(name,od)
|
mcl_weather.stop_weather_player(name,od)
|
||||||
|
|
Loading…
Reference in New Issue