From 2e8ac46120a764cdc6bba6a334215e05ab92bb69 Mon Sep 17 00:00:00 2001 From: ssdaniel24 <107036969+ssdaniel24@users.noreply.github.com> Date: Wed, 28 Sep 2022 12:07:50 +0300 Subject: [PATCH] Beds: Replace hardcoded values of day interval with constants (#2990) --- game_api.txt | 2 ++ mods/beds/functions.lua | 2 +- mods/beds/init.lua | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/game_api.txt b/game_api.txt index c8b4cec3..8d3653d5 100644 --- a/game_api.txt +++ b/game_api.txt @@ -49,6 +49,8 @@ Beds API * `beds.read_spawns() ` Returns a table containing players respawn positions * `beds.kick_players()` Forces all players to leave bed * `beds.skip_night()` Sets world time to morning and saves respawn position of all players currently sleeping + * `beds.day_interval` Is a table with keys "start" and "finish". Allows you + to set the period of the day (timeofday format). Default: `{ start = 0.2, finish = 0.805 }`. ### Bed definition diff --git a/mods/beds/functions.lua b/mods/beds/functions.lua index 409aa376..99e4dd72 100644 --- a/mods/beds/functions.lua +++ b/mods/beds/functions.lua @@ -186,7 +186,7 @@ function beds.on_rightclick(pos, player) local ppos = player:get_pos() local tod = minetest.get_timeofday() - if tod > 0.2 and tod < 0.805 then + if tod > beds.day_interval.start and tod < beds.day_interval.finish then if beds.player[name] then lay_down(player, nil, nil, false) end diff --git a/mods/beds/init.lua b/mods/beds/init.lua index a1a46ce9..14ced8ba 100644 --- a/mods/beds/init.lua +++ b/mods/beds/init.lua @@ -16,6 +16,11 @@ beds.formspec = "size[8,11;true]" .. "bgcolor[#080808BB;true]" .. "button_exit[2,10;4,0.75;leave;" .. esc(S("Leave Bed")) .. "]" +beds.day_interval = { + start = 0.2, + finish = 0.805, +} + local modpath = minetest.get_modpath("beds") -- Load files