mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 13:53:45 +01:00
Merge pull request 'Bed Fixes' (#2622) from bed_fix into master
Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/2622 Reviewed-by: cora <cora@noreply.git.minetest.land>
This commit is contained in:
commit
e77e175085
@ -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.
|
||||
|
||||
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
|
||||
|
@ -58,6 +58,15 @@ local monster_exceptions = {
|
||||
["mobs_mc:shulker"] = true,
|
||||
}
|
||||
|
||||
function mcl_beds.is_night(tod)
|
||||
-- Values taken from Minecraft Wiki with offset of +600
|
||||
if not tod then
|
||||
tod = minetest.get_timeofday()
|
||||
end
|
||||
tod = ( tod * 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,6 +88,11 @@ local function lay_down(player, pos, bed_pos, state, skip)
|
||||
awards.unlock(player:get_player_name(), "mcl:sweetDreams")
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
|
||||
-- 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 +172,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
|
||||
@ -251,16 +258,22 @@ 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
|
||||
if weather_mod and mcl_weather.get_weather() == "thunder" then
|
||||
local endtime = (mcl_weather.end_time - minetest.get_gametime()) * 72 / 24000
|
||||
minetest.set_timeofday((minetest.get_timeofday() + endtime) %1)
|
||||
if mcl_beds.is_night() then
|
||||
mcl_beds.skip_night()
|
||||
mcl_beds.kick_players()
|
||||
else
|
||||
mcl_beds.kick_players()
|
||||
end
|
||||
-- Always clear weather
|
||||
mcl_weather.change_weather("none")
|
||||
elseif mcl_beds.is_night() then
|
||||
mcl_beds.skip_night()
|
||||
mcl_beds.kick_players()
|
||||
end
|
||||
mcl_beds.kick_players()
|
||||
end
|
||||
end
|
||||
|
||||
@ -287,16 +300,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
|
||||
|
Loading…
Reference in New Issue
Block a user