1
0
Fork 0

Merge pull request 'Add playersSleepingPercentage server setting (Fix #920)' (#1861) from NO11/MineClone2:beds into master

Reviewed-on: MineClone2/MineClone2#1861
This commit is contained in:
NO11 2021-10-07 15:14:03 +00:00
commit 19b5a5aac7
5 changed files with 35 additions and 38 deletions

View File

@ -12,15 +12,7 @@ Authors of media (textures)
BlockMen (CC BY-SA 3.0)
This mod adds a bed to Minetest which allows to skip the night.
To sleep, rightclick the bed. If playing in singleplayer mode the night gets skipped
immediately. If playing multiplayer you get shown how many other players are in bed too,
if all players are sleeping the night gets skipped. The night skip can be forced if more
than 50% of the players are lying in bed and use this option.
Another feature is a controlled 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
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.
You can disable the respawn at beds by setting "enable_bed_respawn = false" in
minetest.conf.
You can disable the night skip feature by setting "enable_bed_night_skip = false" in
minetest.conf or by using the /set command in-game.
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.

View File

@ -14,39 +14,34 @@ local worlds_mod = minetest.get_modpath("mcl_worlds")
local function get_look_yaw(pos)
local n = minetest.get_node(pos)
if n.param2 == 1 then
return math.pi / 2, n.param2
elseif n.param2 == 3 then
return -math.pi / 2, n.param2
elseif n.param2 == 0 then
return math.pi, n.param2
local param = n.param2
if param == 1 then
return math.pi / 2, param
elseif param == 3 then
return -math.pi / 2, param
elseif param == 0 then
return math.pi, param
else
return 0, n.param2
return 0, param
end
end
local function players_in_bed_setting()
return tonumber(minetest.settings:get("mcl_playersSleepingPercentage"))
end
local function is_night_skip_enabled()
local enable_night_skip = minetest.settings:get_bool("enable_bed_night_skip")
if enable_night_skip == nil then
enable_night_skip = true
end
return enable_night_skip
return players_in_bed_setting() <= 100
end
local function check_in_beds(players)
local in_bed = mcl_beds.player
if not players then
players = minetest.get_connected_players()
end
for n, player in pairs(players) do
local name = player:get_player_name()
if not in_bed[name] then
if player_in_bed <= 0 then
return false
end
end
return #players > 0
return players_in_bed_setting() <= (player_in_bed * 100) / #players
end
-- These monsters do not prevent sleep
@ -198,7 +193,7 @@ end
local function update_formspecs(finished, ges)
local ges = ges or #minetest.get_connected_players()
local form_n = "size[12,5;true]"
local all_in_bed = ges == player_in_bed
local all_in_bed = players_in_bed_setting() <= (player_in_bed * 100) / ges
local night_skip = is_night_skip_enabled()
local button_leave = "button_exit[4,3;4,0.75;leave;"..F(S("Leave bed")).."]"
local button_abort = "button_exit[4,3;4,0.75;leave;"..F(S("Abort sleep")).."]"
@ -221,7 +216,13 @@ local function update_formspecs(finished, ges)
form_n = form_n .. bg_sleep
form_n = form_n .. button_abort
else
text = text .. "\n" .. S("You will fall asleep when all players are in bed.")
local comment = "You will fall asleep when "
if players_in_bed_setting() == 100 then
comment = S(comment .. "all players are in bed.")
else
comment = S(comment .. "@1% of all players are in bed.", players_in_bed_setting())
end
text = text .. "\n" .. comment
form_n = form_n .. bg_presleep
form_n = form_n .. button_leave
end
@ -349,7 +350,6 @@ function mcl_beds.on_rightclick(pos, player, is_top)
end
end
-- Callbacks
minetest.register_on_joinplayer(function(player)
local meta = player:get_meta()

View File

@ -37,5 +37,6 @@ Players in bed: @1/@2=Spieler im Bett: @1/@2
Note: Night skip is disabled.=Anmerkung: Überspringen der Nacht deaktiviert.
You're sleeping.=Sie schlafen.
You will fall asleep when all players are in bed.=Sie werden einschlafen, wenn alle Spieler im Bett sind.
You will fall asleep when @1% of all players are in bed.=Sie werden einschlafen, wenn @1% der Spieler im Bett sind.
You're in bed.=Sie sind im Bett.
Allows you to sleep=Zum Einschafen

View File

@ -37,5 +37,6 @@ Players in bed: @1/@2=
Note: Night skip is disabled.=
You're sleeping.=
You will fall asleep when all players are in bed.=
You will fall asleep when @1% of all players are in bed.=
You're in bed.=
Allows you to sleep=

View File

@ -33,9 +33,12 @@ mcl_tnt_griefing (TNT destroys blocks) bool true
# This setting is only read at startup.
enable_bed_respawn (Respawn at bed) bool true
# If enabled, the night can be skipped if all players are in bed.
# This setting is only read at startup.
enable_bed_night_skip (Skip night when sleeping) bool true
# How many players have to sleep to skip the night, in percent.
# Setting to 0 will mean 1 player is always enough to skip the night. Setting above 100 will prevent skipping the night.
# 100 by default.
# The setting can be changed ingame using `/set mcl_playersSleepingPercentage <number>`
mcl_playersSleepingPercentage (Players Sleeping Percentage) int 100
# Normally, players drop all their items when they die. Enable this
# setting, so players always keep their inventory on death.
mcl_keepInventory (Keep inventory on death) bool false