mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-12-24 00:49:34 +01:00
Minor weather code clean up, ref. https://git.minetest.land/Wuzzy/MineClone2/issues/897
This commit is contained in:
parent
a3ccb54376
commit
1f18c2438c
2 changed files with 176 additions and 173 deletions
|
@ -94,4 +94,3 @@ if mcl_weather.reg_weathers.snow == nil then
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ mcl_weather.state = "none"
|
||||||
-- player list for saving player meta info
|
-- player list for saving player meta info
|
||||||
mcl_weather.players = {}
|
mcl_weather.players = {}
|
||||||
|
|
||||||
-- default weather recalculation interval
|
-- default weather check interval for global step
|
||||||
mcl_weather.check_interval = 300
|
mcl_weather.check_interval = 5
|
||||||
|
|
||||||
-- weather min duration
|
-- weather min duration
|
||||||
mcl_weather.min_duration = 600
|
mcl_weather.min_duration = 600
|
||||||
|
@ -40,16 +40,16 @@ 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("verbose", "[mcl_weather] Weather data saved: state="..mcl_weather.state.." end_time="..mcl_weather.end_time)
|
minetest.log("action", "[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)
|
||||||
|
|
||||||
mcl_weather.get_rand_end_time = function(min_duration, max_duration)
|
mcl_weather.get_rand_end_time = function(min_duration, max_duration)
|
||||||
local r
|
local r
|
||||||
if min_duration ~= nil and max_duration ~= nil then
|
if min_duration ~= nil and max_duration ~= nil then
|
||||||
r = math.random(min_duration, max_duration);
|
r = math.random(min_duration, max_duration)
|
||||||
else
|
else
|
||||||
r = math.random(mcl_weather.min_duration, mcl_weather.max_duration);
|
r = math.random(mcl_weather.min_duration, mcl_weather.max_duration)
|
||||||
end
|
end
|
||||||
return minetest.get_gametime() + r
|
return minetest.get_gametime() + r
|
||||||
end
|
end
|
||||||
|
@ -121,7 +121,12 @@ mcl_weather.get_random_pos_by_player_look_dir = function(player)
|
||||||
return random_pos_x, random_pos_y, random_pos_z
|
return random_pos_x, random_pos_y, random_pos_z
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local t, wci = 0, mcl_weather.check_interval
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
t = t + dtime
|
||||||
|
if t < wci then return end
|
||||||
|
t = 0
|
||||||
|
|
||||||
if mcl_weather.end_time == nil then
|
if mcl_weather.end_time == nil then
|
||||||
mcl_weather.end_time = mcl_weather.get_rand_end_time()
|
mcl_weather.end_time = mcl_weather.get_rand_end_time()
|
||||||
end
|
end
|
||||||
|
@ -141,7 +146,7 @@ end)
|
||||||
|
|
||||||
-- Sets random weather (which could be 'none' (no weather)).
|
-- Sets random weather (which could be 'none' (no weather)).
|
||||||
mcl_weather.set_random_weather = function(weather_name, weather_meta)
|
mcl_weather.set_random_weather = function(weather_name, weather_meta)
|
||||||
if (weather_meta ~= nil) then
|
if weather_meta == nil then return end
|
||||||
local transitions = weather_meta.transitions
|
local transitions = weather_meta.transitions
|
||||||
local random_roll = math.random(0,100)
|
local random_roll = math.random(0,100)
|
||||||
local new_weather
|
local new_weather
|
||||||
|
@ -155,7 +160,6 @@ mcl_weather.set_random_weather = function(weather_name, weather_meta)
|
||||||
mcl_weather.change_weather(new_weather)
|
mcl_weather.change_weather(new_weather)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue