Fixed Sleeping Times based on time and storm status

This commit is contained in:
PrairieWind 2022-09-03 16:37:44 -06:00 committed by cora
parent f4ac6335eb
commit 847e37c81f

@ -251,16 +251,30 @@ end
-- Handle environment stuff related to sleeping: skip night and thunderstorm
function mcl_beds.sleep()
local storm_skipped = mcl_beds.skip_thunderstorm()
-- Always clear weather
if weather_mod then
mcl_weather.change_weather("none")
end
if is_night_skip_enabled() then
if not storm_skipped then
mcl_beds.skip_night()
if mcl_weather.get_weather() == "thunder" then
local tod = minetest.get_timeofday() * 24000
if (tod < 18541 and tod > 5458) then
mcl_beds.skip_night()
mcl_beds.kick_players()
else
-- Sleep for a half day (=minimum thunderstorm duration)
minetest.set_timeofday((minetest.get_timeofday() + 0.5) % 1)
mcl_beds.kick_players()
end
else
if is_night_skip_enabled() then
mcl_beds.skip_night()
mcl_beds.kick_players()
end
end
-- Always clear weather
mcl_weather.change_weather("none")
else
if is_night_skip_enabled() then
mcl_beds.skip_night()
mcl_beds.kick_players()
end
mcl_beds.kick_players()
end
end
@ -287,16 +301,6 @@ function mcl_beds.skip_night()
minetest.set_timeofday(0.25) -- tod = 6000
end
function mcl_beds.skip_thunderstorm()
-- Skip thunderstorm
if weather_mod and mcl_weather.get_weather() == "thunder" then
-- Sleep for a half day (=minimum thunderstorm duration)
minetest.set_timeofday((minetest.get_timeofday() + 0.5) % 1)
return true
end
return false
end
function mcl_beds.on_rightclick(pos, player, is_top)
-- Anti-Inception: Don't allow to sleep while you're sleeping
if player:get_meta():get_string("mcl_beds:sleeping") == "true" then