From f4ac6335eb9887f72c2c254c87dea352f6d82ed6 Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Fri, 2 Sep 2022 12:37:30 -0600 Subject: [PATCH 1/7] Fixed Bed Check Checks time before distance --- mods/ITEMS/mcl_beds/functions.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index e570bd8eb2..464c4ae45c 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -79,6 +79,13 @@ local function lay_down(player, pos, bed_pos, state, skip) awards.unlock(player:get_player_name(), "mcl:sweetDreams") end + -- Check day of time and weather + local tod = minetest.get_timeofday() * 24000 + -- Values taken from Minecraft Wiki with offset of +6000 + if tod < 18541 and tod > 5458 and (not weather_mod or (mcl_weather.get_weather() ~= "thunder")) then + return false, S("You can only sleep at night or during a thunderstorm.") + end + -- No sleeping if too far away if vector.distance(bed_pos, pos) > 2 and vector.distance(bed_pos2, pos) > 2 then return false, S("You can't sleep, the bed's too far away!") @@ -158,13 +165,6 @@ local function lay_down(player, pos, bed_pos, state, skip) return false, S("It's too dangerous to sleep here!") end - -- Check day of time and weather - local tod = minetest.get_timeofday() * 24000 - -- Values taken from Minecraft Wiki with offset of +6000 - if tod < 18541 and tod > 5458 and (not weather_mod or (mcl_weather.get_weather() ~= "thunder")) then - return false, S("You can only sleep at night or during a thunderstorm.") - end - mcl_beds.player[name] = 1 mcl_beds.pos[name] = pos mcl_beds.bed_pos[name] = bed_pos2 From 847e37c81fd4b3562bd803966431d178631423a7 Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Sat, 3 Sep 2022 16:37:44 -0600 Subject: [PATCH 2/7] Fixed Sleeping Times based on time and storm status --- mods/ITEMS/mcl_beds/functions.lua | 40 +++++++++++++++++-------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 464c4ae45c..5ce672b29d 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -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 From dadb39dd9225a10294265b937f079a55ba3851ad Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 5 Sep 2022 17:25:50 +0200 Subject: [PATCH 3/7] Fix wrong time checks in mcl_beds --- mods/ITEMS/mcl_beds/functions.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 5ce672b29d..f9f7435aa8 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -58,6 +58,12 @@ local monster_exceptions = { ["mobs_mc:shulker"] = true, } +function mcl_beds.is_night() + -- Values taken from Minecraft Wiki with offset of +600 + local tod = ( minetest.get_timeofday() * 24000 ) % 24000 + return tod > 18541 or tod < 5458 +end + local function lay_down(player, pos, bed_pos, state, skip) local name = player:get_player_name() local hud_flags = player:hud_get_flags() @@ -79,10 +85,8 @@ local function lay_down(player, pos, bed_pos, state, skip) awards.unlock(player:get_player_name(), "mcl:sweetDreams") end - -- Check day of time and weather - local tod = minetest.get_timeofday() * 24000 - -- Values taken from Minecraft Wiki with offset of +6000 - if tod < 18541 and tod > 5458 and (not weather_mod or (mcl_weather.get_weather() ~= "thunder")) then + + if not mcl_beds.is_night() and (not weather_mod or (mcl_weather.get_weather() ~= "thunder")) then return false, S("You can only sleep at night or during a thunderstorm.") end @@ -253,8 +257,7 @@ end function mcl_beds.sleep() if weather_mod then if mcl_weather.get_weather() == "thunder" then - local tod = minetest.get_timeofday() * 24000 - if (tod < 18541 and tod > 5458) then + if mcl_beds.is_night() then mcl_beds.skip_night() mcl_beds.kick_players() else From 38ea214bfe080ceb4233fe16539249de70c859f0 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 5 Sep 2022 17:55:50 +0200 Subject: [PATCH 4/7] optional time_of_day arg for mcl_beds.is_night() --- mods/ITEMS/mcl_beds/functions.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index f9f7435aa8..70324cb8ff 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -58,9 +58,12 @@ local monster_exceptions = { ["mobs_mc:shulker"] = true, } -function mcl_beds.is_night() +function mcl_beds.is_night(tod) -- Values taken from Minecraft Wiki with offset of +600 - local tod = ( minetest.get_timeofday() * 24000 ) % 24000 + if not tod then + tod = minetest.get_timeofday() + end + tod = ( tod * 24000 ) % 24000 return tod > 18541 or tod < 5458 end From 4c5c20e514d559e2ad7fd7450f7aff970dc76033 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 5 Sep 2022 17:56:38 +0200 Subject: [PATCH 5/7] Add documentation for mcl_beds.is_night() --- mods/ITEMS/mcl_beds/README.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/README.txt b/mods/ITEMS/mcl_beds/README.txt index 34b493702f..c0d2549f20 100644 --- a/mods/ITEMS/mcl_beds/README.txt +++ b/mods/ITEMS/mcl_beds/README.txt @@ -15,4 +15,7 @@ This mod adds a bed to Minetest which allows to skip the night. To sleep, rightclick the bed. Another feature is a controlled respawning. If you have slept in bed your respawn point is set to the beds location and you will respawn there after death. -Use the mcl_playersSleepingPercentage setting to enable/disable night skipping or set a percentage of how many players need to sleep to skip the night. \ No newline at end of file + +Use the mcl_playersSleepingPercentage setting to enable/disable night skipping or set a percentage of how many players need to sleep to skip the night. + +mcl_beds.is_night([ time of day ]) - returns wether it's night with optional argument of a minetest time of day value between 0 and 1 From 920377ae446f50170a9905646a100a3adfdd683f Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Tue, 6 Sep 2022 12:32:24 -0600 Subject: [PATCH 6/7] Slightly Improved Sleep Checks --- mods/ITEMS/mcl_beds/functions.lua | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 70324cb8ff..ec2c925d15 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -258,26 +258,19 @@ end -- Handle environment stuff related to sleeping: skip night and thunderstorm function mcl_beds.sleep() - if weather_mod then - if mcl_weather.get_weather() == "thunder" then - if mcl_beds.is_night() then - mcl_beds.skip_night() + if is_night_skip_enabled() then + if weather_mod and mcl_weather.get_weather() == "thunder" then + endtime = mcl_weather.end_time / 24000 + minetest.set_timeofday((minetest.get_timeofday() + endtime) %1) + if not mcl_beds.is_night() then 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 + -- Always clear weather + mcl_weather.change_weather("none") + elseif mcl_beds.is_night() then mcl_beds.skip_night() mcl_beds.kick_players() end From 58a28b8d8237de22050da69d9a2bfafa762e13dc Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 10 Sep 2022 03:07:17 +0200 Subject: [PATCH 7/7] Fix end time of thunderstorm conversion --- mods/ITEMS/mcl_beds/functions.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index ec2c925d15..c745b5f0c6 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -260,12 +260,12 @@ end function mcl_beds.sleep() if is_night_skip_enabled() then if weather_mod and mcl_weather.get_weather() == "thunder" then - endtime = mcl_weather.end_time / 24000 + local endtime = (mcl_weather.end_time - minetest.get_gametime()) * 72 / 24000 minetest.set_timeofday((minetest.get_timeofday() + endtime) %1) - if not mcl_beds.is_night() then + if mcl_beds.is_night() then + mcl_beds.skip_night() mcl_beds.kick_players() else - mcl_beds.skip_night() mcl_beds.kick_players() end -- Always clear weather