1
0
Fork 0

Beds now allow to skip thunderstorms

This commit is contained in:
Wuzzy 2017-11-20 05:06:58 +01:00
parent 547eb893af
commit f3919cace9
3 changed files with 35 additions and 21 deletions

View File

@ -22,17 +22,17 @@ local function destruct_bed(pos, n)
end end
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 beddesc = "Beds allow you to sleep at night and make the time pass faster."
local beduse = "Right-click on the bed to try to sleep in it. This only works when the sun sets or at night." 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 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 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 end
if minetest.settings:get_bool("enable_bed_night_skip") == false then 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 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 end
local default_sounds local default_sounds

View File

@ -3,3 +3,4 @@ mcl_util?
mcl_wool? mcl_wool?
mcl_dye? mcl_dye?
mcl_tnt? mcl_tnt?
weather_pack?

View File

@ -5,6 +5,7 @@ local enable_respawn = minetest.settings:get_bool("enable_bed_respawn")
if enable_respawn == nil then if enable_respawn == nil then
enable_respawn = true enable_respawn = true
end end
local weather_mod = minetest.get_modpath("weather_pack") ~= nil
-- Helper functions -- Helper functions
@ -121,9 +122,19 @@ local function update_formspecs(finished)
end end
end end
-- Public functions -- 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() function mcl_beds.kick_players()
for name, _ in pairs(mcl_beds.player) do for name, _ in pairs(mcl_beds.player) do
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
@ -135,6 +146,17 @@ function mcl_beds.skip_night()
minetest.set_timeofday(0.25) -- tod = 6000 minetest.set_timeofday(0.25) -- tod = 6000
end 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) function mcl_beds.on_rightclick(pos, player)
if minetest.get_modpath("mcl_init") then if minetest.get_modpath("mcl_init") then
local _, dim = mcl_util.y_to_layer(pos.y) 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 local tod = minetest.get_timeofday() * 24000
-- Values taken from Minecraft Wiki with offset of +6000 -- 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 if mcl_beds.player[name] then
lay_down(player, nil, nil, false) lay_down(player, nil, nil, false)
end 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 return
end end
@ -178,10 +200,7 @@ function mcl_beds.on_rightclick(pos, player)
if not is_sp then if not is_sp then
update_formspecs(is_night_skip_enabled()) update_formspecs(is_night_skip_enabled())
end end
if is_night_skip_enabled() then mcl_beds.sleep()
mcl_beds.skip_night()
mcl_beds.kick_players()
end
end) end)
end end
end end
@ -207,10 +226,7 @@ minetest.register_on_leaveplayer(function(player)
if check_in_beds() then if check_in_beds() then
minetest.after(2, function() minetest.after(2, function()
update_formspecs(is_night_skip_enabled()) update_formspecs(is_night_skip_enabled())
if is_night_skip_enabled() then mcl_beds.sleep()
mcl_beds.skip_night()
mcl_beds.kick_players()
end
end) end)
end end
end) end)
@ -226,9 +242,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.force then if fields.force then
update_formspecs(is_night_skip_enabled()) update_formspecs(is_night_skip_enabled())
if is_night_skip_enabled() then mcl_beds.sleep()
mcl_beds.skip_night()
mcl_beds.kick_players()
end
end end
end) end)