Add option to disable bed's night skip - Solve second point of #512 by adding a setting, enable_bed_night_skip , with default value of true.

This commit is contained in:
LeMagnesium 2015-05-14 18:57:41 +02:00 committed by paramat
parent 24578ca968
commit 279b85fc45
3 changed files with 36 additions and 13 deletions

View File

@ -26,3 +26,11 @@
# Enable the stairs mod ABM that replaces the old 'upside down' # Enable the stairs mod ABM that replaces the old 'upside down'
# stair and slab nodes in old maps with the new param2 versions. # stair and slab nodes in old maps with the new param2 versions.
#enable_stairs_replace_abm = false #enable_stairs_replace_abm = false
# Whether you allow respawning in beds
# Default value is true
#enable_bed_respawn = true
# Whether players can skip night by sleeping
# Default value is true
#enable_bed_night_skip = true

View File

@ -14,7 +14,8 @@ if more than 50% of the players are lying in bed and use this option.
Another feature is a controled respawning. If you have slept in bed (not just lying in it) your respawn point Another feature is a controled respawning. If you have slept in bed (not just lying in it) your respawn point
is set to the beds location and you will respawn there after death. is set to the beds location and you will respawn there after death.
You can disable the respawn at beds by setting "enable_bed_respawn = false" in minetest.conf You can disable the respawn at beds by setting "enable_bed_respawn = false" in minetest.conf
You can also disable the night skip feature by setting "enable_bed_night_skip = false" in minetest.conf or by using
the /set command ingame.
License of source code, textures: WTFPL License of source code, textures: WTFPL

View File

@ -21,6 +21,14 @@ local function get_look_yaw(pos)
end end
end end
local function is_night_skip_enabled()
local enable_night_skip = minetest.setting_getbool("enable_bed_night_skip")
if enable_night_skip == nil then
enable_night_skip = true
end
return enable_night_skip
end
local function check_in_beds(players) local function check_in_beds(players)
local in_bed = beds.player local in_bed = beds.player
if not players then if not players then
@ -101,7 +109,7 @@ local function update_formspecs(finished)
else else
form_n = beds.formspec .. form_n = beds.formspec ..
"label[2.2,11;"..tostring(player_in_bed).." of "..tostring(ges).." players are in bed]" "label[2.2,11;"..tostring(player_in_bed).." of "..tostring(ges).." players are in bed]"
if is_majority then if is_majority and is_night_skip_enabled() then
form_n = form_n .. form_n = form_n ..
"button_exit[2,8;4,0.75;force;Force night skip]" "button_exit[2,8;4,0.75;force;Force night skip]"
end end
@ -154,11 +162,13 @@ function beds.on_rightclick(pos, player)
-- skip the night and let all players stand up -- skip the night and let all players stand up
if check_in_beds() then if check_in_beds() then
minetest.after(2, function() minetest.after(2, function()
beds.skip_night()
if not is_sp then if not is_sp then
update_formspecs(true) update_formspecs(is_night_skip_enabled())
end
if is_night_skip_enabled() then
beds.skip_night()
beds.kick_players()
end end
beds.kick_players()
end) end)
end end
end end
@ -189,9 +199,11 @@ minetest.register_on_leaveplayer(function(player)
beds.player[name] = nil beds.player[name] = nil
if check_in_beds() then if check_in_beds() then
minetest.after(2, function() minetest.after(2, function()
beds.skip_night() update_formspecs(is_night_skip_enabled())
update_formspecs(true) if is_night_skip_enabled() then
beds.kick_players() beds.skip_night()
beds.kick_players()
end
end) end)
end end
end) end)
@ -206,8 +218,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
if fields.force then if fields.force then
beds.skip_night() update_formspecs(is_night_skip_enabled())
update_formspecs(true) if is_night_skip_enabled() then
beds.kick_players() beds.skip_night()
beds.kick_players()
end
end end
end) end)