mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-16 16:11:06 +01:00
fix mcl_beds: ignore players in other dimensions than overwold (#4257)
beds ignore players in other dimensions than "overworld" (because players can only sleep in the "overworld") Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/4257 Reviewed-by: the-real-herowl <the-real-herowl@noreply.git.minetest.land> Co-authored-by: nixnoxus <nixnoxus@web.de> Co-committed-by: nixnoxus <nixnoxus@web.de>
This commit is contained in:
parent
6756658ee9
commit
3975449ad2
1 changed files with 49 additions and 35 deletions
|
@ -8,7 +8,7 @@ local is_sp = minetest.is_singleplayer()
|
||||||
local weather_mod = minetest.get_modpath("mcl_weather")
|
local weather_mod = minetest.get_modpath("mcl_weather")
|
||||||
local explosions_mod = minetest.get_modpath("mcl_explosions")
|
local explosions_mod = minetest.get_modpath("mcl_explosions")
|
||||||
local spawn_mod = minetest.get_modpath("mcl_spawn")
|
local spawn_mod = minetest.get_modpath("mcl_spawn")
|
||||||
local worlds_mod = minetest.get_modpath("mcl_worlds")
|
local pos_to_dim = minetest.get_modpath("mcl_worlds") and mcl_worlds.pos_to_dimension or function(pos) return "overworld" end
|
||||||
|
|
||||||
local function mcl_log (message)
|
local function mcl_log (message)
|
||||||
mcl_util.mcl_log (message, "[Beds]")
|
mcl_util.mcl_log (message, "[Beds]")
|
||||||
|
@ -38,6 +38,16 @@ local function is_night_skip_enabled()
|
||||||
return players_in_bed_setting() <= 100
|
return players_in_bed_setting() <= 100
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function players_in_overworld(players)
|
||||||
|
local count = 0
|
||||||
|
for _, player in pairs(players) do
|
||||||
|
if player and pos_to_dim(player:get_pos()) == "overworld" then
|
||||||
|
count = count +1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
local function check_in_beds(players)
|
local function check_in_beds(players)
|
||||||
if not players then
|
if not players then
|
||||||
players = minetest.get_connected_players()
|
players = minetest.get_connected_players()
|
||||||
|
@ -45,7 +55,7 @@ local function check_in_beds(players)
|
||||||
if player_in_bed <= 0 then
|
if player_in_bed <= 0 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return players_in_bed_setting() <= (player_in_bed * 100) / #players
|
return players_in_bed_setting() <= (player_in_bed * 100) / players_in_overworld(players)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- These monsters do not prevent sleep
|
-- These monsters do not prevent sleep
|
||||||
|
@ -206,10 +216,10 @@ local function lay_down(player, pos, bed_pos, state, skip)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_formspecs(finished, ges)
|
local function update_formspecs(finished, players)
|
||||||
local ges = ges or #minetest.get_connected_players()
|
local ges = players_in_overworld(players or minetest.get_connected_players())
|
||||||
local form_n = "size[12,5;true]"
|
local form_n = "size[12,5;true]"
|
||||||
local all_in_bed = players_in_bed_setting() <= (player_in_bed * 100) / ges
|
local all_in_bed = ges and players_in_bed_setting() <= (player_in_bed * 100) / ges or 0
|
||||||
local night_skip = is_night_skip_enabled()
|
local night_skip = is_night_skip_enabled()
|
||||||
local button_leave = "button_exit[4,3;4,0.75;leave;"..F(S("Leave bed")).."]"
|
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 button_abort = "button_exit[4,3;4,0.75;leave;"..F(S("Abort sleep")).."]"
|
||||||
|
@ -349,13 +359,25 @@ function mcl_beds.get_bed_bottom (pos)
|
||||||
return bed_bottom
|
return bed_bottom
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function recheck_in_beds()
|
||||||
|
if check_in_beds() then
|
||||||
|
update_formspecs(is_night_skip_enabled())
|
||||||
|
mcl_beds.sleep()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check again (a player can change the dimension)
|
||||||
|
if player_in_bed > 0 then
|
||||||
|
update_formspecs(false)
|
||||||
|
minetest.after(5, recheck_in_beds)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function mcl_beds.on_rightclick(pos, player, is_top)
|
function mcl_beds.on_rightclick(pos, player, is_top)
|
||||||
-- Anti-Inception: Don't allow to sleep while you're sleeping
|
-- Anti-Inception: Don't allow to sleep while you're sleeping
|
||||||
if player:get_meta():get_string("mcl_beds:sleeping") == "true" then
|
if player:get_meta():get_string("mcl_beds:sleeping") == "true" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if worlds_mod then
|
local dim = pos_to_dim(pos)
|
||||||
local dim = mcl_worlds.pos_to_dimension(pos)
|
|
||||||
if dim == "nether" or dim == "end" then
|
if dim == "nether" or dim == "end" then
|
||||||
-- Bed goes BOOM in the Nether or End.
|
-- Bed goes BOOM in the Nether or End.
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
@ -368,7 +390,6 @@ function mcl_beds.on_rightclick(pos, player, is_top)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local ppos = player:get_pos()
|
local ppos = player:get_pos()
|
||||||
|
|
||||||
|
@ -385,10 +406,13 @@ function mcl_beds.on_rightclick(pos, player, is_top)
|
||||||
mcl_title.set(player, "actionbar", {text=message, color="white", stay=60})
|
mcl_title.set(player, "actionbar", {text=message, color="white", stay=60})
|
||||||
else -- someone just successfully entered a bed
|
else -- someone just successfully entered a bed
|
||||||
local connected_players = minetest.get_connected_players()
|
local connected_players = minetest.get_connected_players()
|
||||||
local sleep_hud_message = S("@1/@2 players currently in bed.", player_in_bed, math.ceil(players_in_bed_setting() * #connected_players / 100))
|
local ges = players_in_overworld(connected_players)
|
||||||
|
local sleep_hud_message = S("@1/@2 players currently in bed.", player_in_bed, math.ceil(players_in_bed_setting() * ges / 100))
|
||||||
for _, player in pairs(connected_players) do
|
for _, player in pairs(connected_players) do
|
||||||
if not mcl_beds.player[player:get_player_name()] then -- only send message to players not sleeping.
|
-- only send message to players not sleeping and in the "overworld"
|
||||||
if mcl_title.params_get(player) then mcl_title.clear(player) end -- clear, old message is still being displayed
|
if not mcl_beds.player[player:get_player_name()] and pos_to_dim(player:get_pos()) == "overworld" then
|
||||||
|
-- clear, old message is still being displayed
|
||||||
|
if mcl_title.params_get(player) then mcl_title.clear(player) end
|
||||||
mcl_title.set(player, "actionbar", {text=sleep_hud_message, color="white", stay=60})
|
mcl_title.set(player, "actionbar", {text=sleep_hud_message, color="white", stay=60})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -400,13 +424,8 @@ function mcl_beds.on_rightclick(pos, player, is_top)
|
||||||
update_formspecs(false)
|
update_formspecs(false)
|
||||||
|
|
||||||
-- skip the night and let all players stand up
|
-- skip the night and let all players stand up
|
||||||
if check_in_beds() then
|
if player_in_bed > 0 then
|
||||||
minetest.after(5, function()
|
minetest.after(5, recheck_in_beds)
|
||||||
if check_in_beds() then
|
|
||||||
update_formspecs(is_night_skip_enabled())
|
|
||||||
mcl_beds.sleep()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -433,15 +452,10 @@ minetest.register_on_leaveplayer(function(player)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if check_in_beds(players) then
|
if player_in_bed > 0 then
|
||||||
minetest.after(5, function()
|
minetest.after(5, recheck_in_beds)
|
||||||
if check_in_beds() then
|
|
||||||
update_formspecs(is_night_skip_enabled())
|
|
||||||
mcl_beds.sleep()
|
|
||||||
end
|
end
|
||||||
end)
|
update_formspecs(false, players)
|
||||||
end
|
|
||||||
update_formspecs(false, #players)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local message_rate_limit = tonumber(minetest.settings:get("chat_message_limit_per_10sec")) or 8 --NEVER change this! if this was java, i would've declared it as final
|
local message_rate_limit = tonumber(minetest.settings:get("chat_message_limit_per_10sec")) or 8 --NEVER change this! if this was java, i would've declared it as final
|
||||||
|
|
Loading…
Reference in a new issue