From 89ff666a6a7a456daf22a224f42ba7a34919aeec Mon Sep 17 00:00:00 2001 From: NO11 Date: Sun, 12 Sep 2021 12:21:18 +0000 Subject: [PATCH 01/10] Add playersSleepingPercentage server setting (Fix #920) --- mods/ITEMS/mcl_beds/functions.lua | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index e196f69ade..fd8a6d7cd0 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -9,6 +9,7 @@ local weather_mod = minetest.get_modpath("mcl_weather") local explosions_mod = minetest.get_modpath("mcl_explosions") local spawn_mod = minetest.get_modpath("mcl_spawn") local worlds_mod = minetest.get_modpath("mcl_worlds") +local players_in_bed_setting = tonumber(minetest.settings:get("mcl_playersSleepingPercentage")) -- Helper functions @@ -34,19 +35,10 @@ local function is_night_skip_enabled() 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 - return false - end - end - - return #players > 0 + return players_in_bed_setting <= (#mcl_beds.player * 100) / #players end -- These monsters do not prevent sleep @@ -198,8 +190,8 @@ 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 night_skip = is_night_skip_enabled() + local all_in_bed = players_in_bed_setting <= (player_in_bed * 100) / ges + local night_skip = is_night_skip_enabled() and players_in_bed_setting <= 100 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")).."]" local bg_presleep = "bgcolor[#00000080;true]" @@ -212,7 +204,7 @@ local function update_formspecs(finished, ges) return elseif not is_sp then local text = S("Players in bed: @1/@2", player_in_bed, ges) - if not night_skip then + if not night_skip or players_in_bed_setting > 100 then text = text .. "\n" .. S("Note: Night skip is disabled.") form_n = form_n .. bg_presleep form_n = form_n .. button_leave @@ -221,7 +213,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 = comment .. "all players are in bed." + else + comment = comment .. players_in_bed_setting .. "% of all players are in bed." + end + text = text .. "\n" .. S(comment) form_n = form_n .. bg_presleep form_n = form_n .. button_leave end From 0bc9ab9233811b508e1aa29c4b1ea421b47fead3 Mon Sep 17 00:00:00 2001 From: NO11 Date: Sun, 12 Sep 2021 12:23:28 +0000 Subject: [PATCH 02/10] Add playersSleepingPercentage setting to settingtypes.txt --- settingtypes.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/settingtypes.txt b/settingtypes.txt index f605019ad1..89e11833fc 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -33,6 +33,11 @@ mcl_tnt_griefing (TNT destroys blocks) bool true # This setting is only read at startup. enable_bed_respawn (Respawn at bed) 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. +mcl_playersSleepingPercentage (Players Sleeping Percentage) int 100 + # 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 From cd84c472dcb67b32b74397f87c00503b7414fc77 Mon Sep 17 00:00:00 2001 From: NO11 Date: Sun, 12 Sep 2021 12:49:39 +0000 Subject: [PATCH 03/10] Add translation support. --- 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 fd8a6d7cd0..01ccec851d 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -215,11 +215,11 @@ local function update_formspecs(finished, ges) else local comment = "You will fall asleep when " if players_in_bed_setting == 100 then - comment = comment .. "all players are in bed." + comment = S(comment .. "all players are in bed.") else - comment = comment .. players_in_bed_setting .. "% of all players are in bed." + comment = S(comment .. "@1% of all players are in bed.", players_in_bed_setting) end - text = text .. "\n" .. S(comment) + text = text .. "\n" .. comment form_n = form_n .. bg_presleep form_n = form_n .. button_leave end From 9f9799d96e699a0b64bce5fee061deeb040b3aa4 Mon Sep 17 00:00:00 2001 From: NO11 Date: Sun, 12 Sep 2021 12:50:54 +0000 Subject: [PATCH 04/10] Update template.txt in mcl_beds --- mods/ITEMS/mcl_beds/locale/template.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ITEMS/mcl_beds/locale/template.txt b/mods/ITEMS/mcl_beds/locale/template.txt index 8301dfa335..5525bd91bc 100644 --- a/mods/ITEMS/mcl_beds/locale/template.txt +++ b/mods/ITEMS/mcl_beds/locale/template.txt @@ -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= From 410b7c7844b674a062e1726a058e992698b9b34e Mon Sep 17 00:00:00 2001 From: NO11 Date: Sun, 12 Sep 2021 12:52:26 +0000 Subject: [PATCH 05/10] Update german translation for mcl_beds --- mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr index 16592115e8..eb6967941f 100644 --- a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr +++ b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr @@ -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 From df1d8077e6123cef815bc4f30dd02838b9b84dec Mon Sep 17 00:00:00 2001 From: NO11 Date: Tue, 21 Sep 2021 18:07:36 +0000 Subject: [PATCH 06/10] Some fixes for mcl_beds - remove enable_bed_night_skip setting (mcl_playersSleepingPercentage setting can be used to enable disable night skip) - make it possible to change mcl_playersSleepingPercentage ingame - fix weird bug which allowed only numbers <= 0 --- mods/ITEMS/mcl_beds/functions.lua | 39 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 01ccec851d..e7306b40aa 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -9,36 +9,36 @@ local weather_mod = minetest.get_modpath("mcl_weather") local explosions_mod = minetest.get_modpath("mcl_explosions") local spawn_mod = minetest.get_modpath("mcl_spawn") local worlds_mod = minetest.get_modpath("mcl_worlds") -local players_in_bed_setting = tonumber(minetest.settings:get("mcl_playersSleepingPercentage")) -- Helper functions 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) if not players then players = minetest.get_connected_players() end - return players_in_bed_setting <= (#mcl_beds.player * 100) / #players + return players_in_bed_setting() <= (player_in_bed * 100) / #players end -- These monsters do not prevent sleep @@ -190,8 +190,8 @@ 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 = players_in_bed_setting <= (player_in_bed * 100) / ges - local night_skip = is_night_skip_enabled() and players_in_bed_setting <= 100 + 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")).."]" local bg_presleep = "bgcolor[#00000080;true]" @@ -204,7 +204,7 @@ local function update_formspecs(finished, ges) return elseif not is_sp then local text = S("Players in bed: @1/@2", player_in_bed, ges) - if not night_skip or players_in_bed_setting > 100 then + if not night_skip then text = text .. "\n" .. S("Note: Night skip is disabled.") form_n = form_n .. bg_presleep form_n = form_n .. button_leave @@ -214,10 +214,10 @@ local function update_formspecs(finished, ges) form_n = form_n .. button_abort else local comment = "You will fall asleep when " - if players_in_bed_setting == 100 then + 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) + 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 @@ -347,7 +347,6 @@ function mcl_beds.on_rightclick(pos, player, is_top) end end - -- Callbacks minetest.register_on_joinplayer(function(player) local meta = player:get_meta() From 71f448537cb523c9f8287b630ccce6f1ddd91cca Mon Sep 17 00:00:00 2001 From: NO11 Date: Tue, 21 Sep 2021 18:14:24 +0000 Subject: [PATCH 07/10] Remove unused setting from settingtypes.txt --- settingtypes.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/settingtypes.txt b/settingtypes.txt index 89e11833fc..542711675a 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -36,11 +36,9 @@ enable_bed_respawn (Respawn at bed) 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 ` mcl_playersSleepingPercentage (Players Sleeping Percentage) int 100 -# 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 # 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 From e83438e42cb677e6336f52e5e17973fcbef5663c Mon Sep 17 00:00:00 2001 From: NO11 Date: Tue, 21 Sep 2021 18:19:07 +0000 Subject: [PATCH 08/10] Update mcl_bed README.txt --- mods/ITEMS/mcl_beds/README.txt | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mods/ITEMS/mcl_beds/README.txt b/mods/ITEMS/mcl_beds/README.txt index cda6ebd92b..34b493702f 100644 --- a/mods/ITEMS/mcl_beds/README.txt +++ b/mods/ITEMS/mcl_beds/README.txt @@ -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. \ No newline at end of file From 03be73656648136fdabff2dd68c6e44ed184f475 Mon Sep 17 00:00:00 2001 From: NO11 Date: Mon, 27 Sep 2021 20:13:12 +0000 Subject: [PATCH 09/10] Dont skip night if no players are in bed --- mods/ITEMS/mcl_beds/functions.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index e7306b40aa..e2bece0339 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -38,6 +38,9 @@ local function check_in_beds(players) if not players then players = minetest.get_connected_players() end + if player_in_bed < 0 then + return false + end return players_in_bed_setting() <= (player_in_bed * 100) / #players end From 16c73c1cb652b02f77e6140e9ad41f602d5f29aa Mon Sep 17 00:00:00 2001 From: NO11 Date: Tue, 28 Sep 2021 13:16:19 +0000 Subject: [PATCH 10/10] Add forgotten `=` --- mods/ITEMS/mcl_beds/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index e2bece0339..0622192942 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -38,7 +38,7 @@ local function check_in_beds(players) if not players then players = minetest.get_connected_players() end - if player_in_bed < 0 then + if player_in_bed <= 0 then return false end return players_in_bed_setting() <= (player_in_bed * 100) / #players