Weather: Don't read connected players at init time

This commit is contained in:
Wuzzy 2021-02-04 22:18:10 +01:00
parent 163cecbed3
commit e78dd6d2ad
1 changed files with 11 additions and 8 deletions

View File

@ -24,6 +24,9 @@ local sound_min_height = -20 -- Below -20m you can't hear weather
local default_cloud_state = nil
local loaded_weather = mod_storage:get_string("weather:weather")
local weather_inited = false
local function update_sounds(do_repeat)
if weather.weather == "storm" then
for _, player in ipairs(minetest.get_connected_players()) do
@ -79,7 +82,14 @@ end
minetest.register_globalstep(
function(dtime)
if minetest.settings:get_bool("weather_enable") then
if weather_pr:next(0, 5000) < 1 then
if not weather_inited then
if loaded_weather == "" then
setweather_type("clear", true)
else
setweather_type(loaded_weather, true)
end
weather_inited = true
elseif weather_pr:next(0, 5000) < 1 then
local weathertype = weather_pr:next(0, 19)
-- on avg., every 1800 globalsteps, the weather.weather will change to one of:
@ -219,11 +229,4 @@ minetest.register_on_leaveplayer(function(player)
sound_handles[player:get_player_name()] = nil
end)
local loaded_weather = mod_storage:get_string("weather:weather")
if loaded_weather == "" then
setweather_type("clear", true)
else
setweather_type(loaded_weather, true)
end
default.log("mod:weather", "loaded")