diff --git a/mods/ITEMS/mcl_beds/api.lua b/mods/ITEMS/mcl_beds/api.lua index 958c983db..ed2869cc5 100644 --- a/mods/ITEMS/mcl_beds/api.lua +++ b/mods/ITEMS/mcl_beds/api.lua @@ -22,17 +22,17 @@ local function destruct_bed(pos, n) end end -local beddesc = "Beds allow you to sleep at night and waste some time. Survival in this world does not demand sleep, but sleeping might have some other uses. " -local beduse = "Right-click on the bed to try to sleep in it. This only works when the sun sets or at night." +local beddesc = "Beds allow you to sleep at night and make the time pass faster." +local beduse = "Right-click on the bed to sleep in it. This only works when the sun sets, at night or during a thunderstorm." if minetest.settings:get_bool("enable_bed_respawn") == false then - beddesc = beddesc .. "In local folklore, legends are told of other worlds where setting the start point for your next would be possible. But this world is not one of them. " + beddesc = beddesc .. "\n" .. "In local folklore, legends are told of other worlds where setting the start point for your next would be possible. But this world is not one of them." else - beddesc = beddesc .. "By sleeping in a bed, you set the starting point for your next life. " + beddesc = beddesc .. "\n" .. "By sleeping in a bed, you set the starting point for your next life." end if minetest.settings:get_bool("enable_bed_night_skip") == false then - beddesc = beddesc .. "In this strange world, the time will not pass faster for you when you sleep." + beddesc = beddesc .. "\n" .. "In this strange world, going to bed won't skip the night, but you can skip thunderstorms." else - beddesc = beddesc .. "Going into bed seems to make time pass faster: The night will be skipped when you go sleep and you're alone in this world. If you're not alone, the night is skipped when all players in this world went to sleep." + beddesc = beddesc .. "\n" .. "Sleeping allows you to skip the night if you're the only player in this world. If you're not alone, the night is skipped when all players in this world went to sleep. Thunderstorms can be skipped in the same manner." end local default_sounds diff --git a/mods/ITEMS/mcl_beds/depends.txt b/mods/ITEMS/mcl_beds/depends.txt index 93b5fc03e..a7964cfdb 100644 --- a/mods/ITEMS/mcl_beds/depends.txt +++ b/mods/ITEMS/mcl_beds/depends.txt @@ -3,3 +3,4 @@ mcl_util? mcl_wool? mcl_dye? mcl_tnt? +weather_pack? diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 5f8e4daf0..a00a534c2 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -5,6 +5,7 @@ local enable_respawn = minetest.settings:get_bool("enable_bed_respawn") if enable_respawn == nil then enable_respawn = true end +local weather_mod = minetest.get_modpath("weather_pack") ~= nil -- Helper functions @@ -121,9 +122,19 @@ local function update_formspecs(finished) end end - -- Public functions +-- Handle environment stuff related to sleeping: skip night and thunderstorm +function mcl_beds.sleep() + local storm_skipped = mcl_beds.skip_thunderstorm() + if is_night_skip_enabled() then + if not storm_skipped then + mcl_beds.skip_night() + end + mcl_beds.kick_players() + end +end + function mcl_beds.kick_players() for name, _ in pairs(mcl_beds.player) do local player = minetest.get_player_by_name(name) @@ -135,6 +146,17 @@ function mcl_beds.skip_night() minetest.set_timeofday(0.25) -- tod = 6000 end +function mcl_beds.skip_thunderstorm() + -- Skip thunderstorm + if weather_mod and weather.get_weather() == "thunder" then + weather.change_weather("none") + -- 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) if minetest.get_modpath("mcl_init") then local _, dim = mcl_util.y_to_layer(pos.y) @@ -152,11 +174,11 @@ function mcl_beds.on_rightclick(pos, player) local tod = minetest.get_timeofday() * 24000 -- Values taken from Minecraft Wiki with offset of +6000 - if tod < 18541 and tod > 5458 then + if tod < 18541 and tod > 5458 and (not weather_mod or (weather.get_weather() ~= "thunder")) then if mcl_beds.player[name] then lay_down(player, nil, nil, false) end - minetest.chat_send_player(name, "You can only sleep at night.") + minetest.chat_send_player(name, "You can only sleep at night or during a thunderstorm.") return end @@ -178,10 +200,7 @@ function mcl_beds.on_rightclick(pos, player) if not is_sp then update_formspecs(is_night_skip_enabled()) end - if is_night_skip_enabled() then - mcl_beds.skip_night() - mcl_beds.kick_players() - end + mcl_beds.sleep() end) end end @@ -207,10 +226,7 @@ minetest.register_on_leaveplayer(function(player) if check_in_beds() then minetest.after(2, function() update_formspecs(is_night_skip_enabled()) - if is_night_skip_enabled() then - mcl_beds.skip_night() - mcl_beds.kick_players() - end + mcl_beds.sleep() end) end end) @@ -226,9 +242,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.force then update_formspecs(is_night_skip_enabled()) - if is_night_skip_enabled() then - mcl_beds.skip_night() - mcl_beds.kick_players() - end + mcl_beds.sleep() end end)