Skip to content

Commit 279b85f

Browse files
Lymkwiparamat
authored andcommittedSep 29, 2015
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.
1 parent 24578ca commit 279b85f

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed
 

‎minetest.conf.example

+8
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@
2626
# Enable the stairs mod ABM that replaces the old 'upside down'
2727
# stair and slab nodes in old maps with the new param2 versions.
2828
#enable_stairs_replace_abm = false
29+
30+
# Whether you allow respawning in beds
31+
# Default value is true
32+
#enable_bed_respawn = true
33+
34+
# Whether players can skip night by sleeping
35+
# Default value is true
36+
#enable_bed_night_skip = true

‎mods/beds/README.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ if more than 50% of the players are lying in bed and use this option.
1414
Another feature is a controled respawning. If you have slept in bed (not just lying in it) your respawn point
1515
is set to the beds location and you will respawn there after death.
1616
You can disable the respawn at beds by setting "enable_bed_respawn = false" in minetest.conf
17-
17+
You can also disable the night skip feature by setting "enable_bed_night_skip = false" in minetest.conf or by using
18+
the /set command ingame.
1819

1920

2021
License of source code, textures: WTFPL

‎mods/beds/functions.lua

+26-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ local function get_look_yaw(pos)
2121
end
2222
end
2323

24+
local function is_night_skip_enabled()
25+
local enable_night_skip = minetest.setting_getbool("enable_bed_night_skip")
26+
if enable_night_skip == nil then
27+
enable_night_skip = true
28+
end
29+
return enable_night_skip
30+
end
31+
2432
local function check_in_beds(players)
2533
local in_bed = beds.player
2634
if not players then
@@ -56,7 +64,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
5664
if skip then
5765
return
5866
end
59-
if p then
67+
if p then
6068
player:setpos(p)
6169
end
6270

@@ -100,8 +108,8 @@ local function update_formspecs(finished)
100108
"label[2.7,11; Good morning.]"
101109
else
102110
form_n = beds.formspec ..
103-
"label[2.2,11;"..tostring(player_in_bed).." of "..tostring(ges).." players are in bed]"
104-
if is_majority then
111+
"label[2.2,11;"..tostring(player_in_bed).." of "..tostring(ges).." players are in bed]"
112+
if is_majority and is_night_skip_enabled() then
105113
form_n = form_n ..
106114
"button_exit[2,8;4,0.75;force;Force night skip]"
107115
end
@@ -154,11 +162,13 @@ function beds.on_rightclick(pos, player)
154162
-- skip the night and let all players stand up
155163
if check_in_beds() then
156164
minetest.after(2, function()
157-
beds.skip_night()
158165
if not is_sp then
159-
update_formspecs(true)
166+
update_formspecs(is_night_skip_enabled())
167+
end
168+
if is_night_skip_enabled() then
169+
beds.skip_night()
170+
beds.kick_players()
160171
end
161-
beds.kick_players()
162172
end)
163173
end
164174
end
@@ -189,9 +199,11 @@ minetest.register_on_leaveplayer(function(player)
189199
beds.player[name] = nil
190200
if check_in_beds() then
191201
minetest.after(2, function()
192-
beds.skip_night()
193-
update_formspecs(true)
194-
beds.kick_players()
202+
update_formspecs(is_night_skip_enabled())
203+
if is_night_skip_enabled() then
204+
beds.skip_night()
205+
beds.kick_players()
206+
end
195207
end)
196208
end
197209
end)
@@ -206,8 +218,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
206218
end
207219

208220
if fields.force then
209-
beds.skip_night()
210-
update_formspecs(true)
211-
beds.kick_players()
221+
update_formspecs(is_night_skip_enabled())
222+
if is_night_skip_enabled() then
223+
beds.skip_night()
224+
beds.kick_players()
225+
end
212226
end
213227
end)

0 commit comments

Comments
 (0)
Please sign in to comment.