Compare commits

...

10 Commits

Author SHA1 Message Date
tenplus1
510bbd089a update russian translation (thx Randomei) 2024-12-29 11:29:01 +00:00
tenplus1
6fadc4afca tweak and tidy code 2024-12-27 12:00:20 +00:00
tenplus1
f21a550ae7 change movement check value 2024-12-11 12:47:55 +00:00
tenplus1
1441ee3cb8 fix on_sleep check 2024-11-17 15:59:53 +00:00
tenplus1
6418226c11 add custom on_sleep() function for bed registration. 2024-11-17 15:46:28 +00:00
tenplus1
9b09737d97 update esperanto translation (thx jadedctrl) 2024-05-20 08:12:57 +01:00
tenplus1
bbb08eb344 add setting to show when player sleeps in chat 2023-11-16 08:17:49 +00:00
tenplus1
edc22ba635 add esperanto translation (thx jadedctrl) 2023-10-16 07:53:33 +01:00
tenplus1
be96e8e13e update mod.conf 2023-09-30 07:51:32 +01:00
tenplus1
0cf4fb6bcd keep up to date with default beds fixes (thanks appgurueu) 2023-09-30 07:48:50 +01:00
12 changed files with 138 additions and 108 deletions

View File

@ -24,3 +24,7 @@
- 'bed_sleep_divide' setting added [1 for all, 2 for half, 3 for third]
- Add POVA support
- Add pink fancy bed and blue simple bed
1.2.1
-----
- Add 'bed_show_sleep_msg' setting that shows in chat when a player sleeps

View File

@ -38,6 +38,12 @@ death. Check configuration section for more info.
It features more beds, so along with the Red simple bed we now have White and
Blue, and the fance beds has the original Red and now Pink.
* Custom function:
Beds registered using beds.register_bed() function can also include a custom
on_sleep(pos, player) function that allows certain beds to have their own
characteristics, and by returning True the player will be kicked from their bed.
#### Dependencies
* default
@ -45,7 +51,6 @@ Blue, and the fance beds has the original Red and now Pink.
Optional dependences:
* intllib (only for older engines)
* pova (optional)
The pova mod are not xplicit set as optional depends, due the circular depends bug,

23
api.lua
View File

@ -32,14 +32,8 @@ function beds.register_bed(name, def)
fall_damage_add_percent = -40, bouncy = 85
},
sounds = default.node_sound_wood_defaults(),
selection_box = {
type = "fixed",
fixed = def.selectionbox
},
collision_box = {
type = "fixed",
fixed = def.collisionbox
},
selection_box = {type = "fixed", fixed = def.selectionbox},
collision_box = {type = "fixed", fixed = def.collisionbox},
on_place = function(itemstack, placer, pointed_thing)
@ -116,6 +110,14 @@ function beds.register_bed(name, def)
can_dig = function(pos, player)
return beds.can_dig(pos)
end,
on_sleep = function(pos, player)
return def.on_sleep and def.on_sleep(pos, player)
end,
on_blast = function(pos, intensity)
minetest.remove_node(pos)
end
})
@ -123,8 +125,5 @@ function beds.register_bed(name, def)
minetest.register_alias(name .. "_top", "air")
-- register recipe
minetest.register_craft({
output = name,
recipe = def.recipe
})
minetest.register_craft({output = name, recipe = def.recipe})
end

View File

@ -73,7 +73,11 @@ beds.register_bed("beds:bed_blue", {
recipe = {
{"wool:blue", "wool:blue", "wool:white"},
{"group:wood", "group:wood", "group:wood"}
}
},
on_sleep = function(pos, player)
-- print("----", minetest.pos_to_string(pos), player:get_player_name())
minetest.sound_play("default_dig_choppy", {pos = pos, gain = 0.5}, true)
end
})
-- Aliases for PilzAdam's beds mod
@ -83,32 +87,8 @@ minetest.register_alias("beds:bed_top_red", "beds:bed_top")
-- Fuel
minetest.register_craft({
type = "fuel",
recipe = "beds:fancy_bed",
burntime = 13
})
minetest.register_craft({
type = "fuel",
recipe = "beds:fancy_bed_pink",
burntime = 13
})
minetest.register_craft({
type = "fuel",
recipe = "beds:bed",
burntime = 12
})
minetest.register_craft({
type = "fuel",
recipe = "beds:bed_blue",
burntime = 12
})
minetest.register_craft({
type = "fuel",
recipe = "beds:bed_white",
burntime = 12
})
minetest.register_craft({type = "fuel", recipe = "beds:fancy_bed", burntime = 13})
minetest.register_craft({type = "fuel", recipe = "beds:fancy_bed_pink", burntime = 13})
minetest.register_craft({type = "fuel", recipe = "beds:bed", burntime = 12})
minetest.register_craft({type = "fuel", recipe = "beds:bed_blue", burntime = 12})
minetest.register_craft({type = "fuel", recipe = "beds:bed_white", burntime = 12})

View File

@ -4,7 +4,7 @@ local is_pova = minetest.get_modpath("pova")
local pi = math.pi
local is_sp = minetest.is_singleplayer()
local enable_respawn = minetest.settings:get_bool("enable_bed_respawn") ~= false
local chat_msg = minetest.settings:get_bool("bed_show_sleep_msg")
-- Helper functions
@ -48,13 +48,11 @@ local function check_in_beds(players)
players = minetest.get_connected_players()
end
for n, player in ipairs(players) do
for n, player in pairs(players) do
local name = player:get_player_name()
local name = player and player:get_player_name()
if not in_bed[name] then
return false
end
if not in_bed[name] then return false end
end
return #players > 0
@ -66,9 +64,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
local name = player:get_player_name()
local hud_flags = player:hud_get_flags()
if not player or not name then
return
end
if not player or not name then return end
-- stand up
if state ~= nil and not state then
@ -80,9 +76,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
beds.bed_position[name] = nil
-- skip here to prevent sending player specific changes (used for leaving players)
if skip then
return
end
if skip then return end
player:set_pos(beds.pos[name])
@ -124,7 +118,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
end
-- Check if player is moving
if is_54 and vector.length(player:get_velocity()) > 0.001 then
if is_54 and vector.length(player:get_velocity()) > 0.05 then
minetest.chat_send_player(name,
S("You have to stop moving before going to bed!"))
@ -133,14 +127,10 @@ local function lay_down(player, pos, bed_pos, state, skip)
end
-- Check if player is attached to an object
if player:get_attach() then
return false
end
if player:get_attach() then return false end
if beds.player[name] then
-- player already in bed, do nothing
return false
end
-- player already in bed, do nothing
if beds.player[name] then return false end
beds.pos[name] = pos
beds.bed_position[name] = bed_pos
@ -173,6 +163,10 @@ local function lay_down(player, pos, bed_pos, state, skip)
player_api.set_animation(player, "lay" , 0)
hud_flags.wielditem = false
if chat_msg then
minetest.chat_send_all(S("@1 has gone to bed.", name))
end
end
player:hud_set_flags(hud_flags)
@ -236,6 +230,35 @@ function beds.skip_night()
end
local update_scheduled = false
local function schedule_update()
if update_scheduled then
-- there already is an update scheduled; don't schedule more to prevent races
return
end
update_scheduled = true
minetest.after(2, function()
update_scheduled = false
if not is_sp then
update_formspecs(is_night_skip_enabled())
end
if is_night_skip_enabled() then
-- skip the night and let all players stand up
beds.skip_night()
beds.kick_players()
end
end)
end
function beds.on_rightclick(pos, player)
local name = player:get_player_name()
@ -263,24 +286,25 @@ function beds.on_rightclick(pos, player)
lay_down(player, nil, nil, false)
end
-- check for custom on_sleep function
local nod = minetest.get_node(pos).name
local def = minetest.registered_nodes[nod]
local on_sleep = def and def.on_sleep
-- if on_sleep returns True then skip sleeping
if on_sleep and on_sleep(pos, player) then
lay_down(player, nil, nil, false)
return
end
if not is_sp then
update_formspecs(false)
end
-- skip the night and let all players stand up
if check_in_beds() then
minetest.after(2, function()
if not is_sp then
update_formspecs(is_night_skip_enabled())
end
if is_night_skip_enabled() then
beds.skip_night()
beds.kick_players()
end
end)
schedule_update()
end
end
@ -340,16 +364,7 @@ minetest.register_on_leaveplayer(function(player)
beds.player[name] = nil
if check_in_beds() then
minetest.after(2, function()
update_formspecs(is_night_skip_enabled())
if is_night_skip_enabled() then
beds.skip_night()
beds.kick_players()
end
end)
schedule_update()
end
end)

View File

@ -1,16 +1,9 @@
-- Load support for MT game translation.
local S
if minetest.get_translator ~= nil then
S = minetest.get_translator("beds") -- 5.x translation function
else -- boilerplate function for 0.4
S = function(str, ...)
local args = {...}
return str:gsub("@%d+", function(match)
return args[tonumber(match:sub(2))]
end)
end
end
-- translation support
local S = minetest.get_translator("beds")
-- global
beds = {
mod = "redo",
@ -27,6 +20,7 @@ beds = {
.. "button_exit[2,10;4,0.75;leave;" .. minetest.formspec_escape(S("Leave Bed")) .. "]"
}
-- load api, register beds, load player respawn positions
local modpath = minetest.get_modpath("beds")

13
locale/beds.eo.tr Normal file
View File

@ -0,0 +1,13 @@
# textdomain: beds
Red Fancy Bed=Ruĝa luksa lito
Pink Fancy Bed=Rozkolora luksa lito
White Simple Bed=Blanka simpla lito
Red Simple Bed=Ruĝa simpla lito
Blue Simple Bed=Blua simpla lito
This bed is already occupied!=Iu jam kuŝas en tiu lito!
You have to stop moving before going to bed!=Vi devas senmovi por enlitiĝi!
Good morning.=Bonan matenon.
@1 of @2 players are in bed=@1 el @2 ludantoj enlitas
Force night skip=Permane tagigi
You can only sleep at night.=Oni sole povas dormi nokte.
Leave Bed=Ellitiĝi

View File

@ -1,10 +1,16 @@
# textdomain: beds
Fancy Bed=Детализированная Кровать
Simple Bed=Обычная Кровать
This bed is already occupied!=
You have to stop moving before going to bed!=
Fancy Bed=Изысканная кровать
Simple Bed=Простая кровать
Red Fancy Bed=Красная изысканная кровать
Pink Fancy Bed=Розовая изысканная кровать
White Simple Bed=Белая простая кровать
Red Simple Bed=Красная простая кровать
Blue Simple Bed=Синяя простая кровать
This bed is already occupied!=Эта кровать уже занята!
You have to stop moving before going to bed!=Нужно перестать двигаться, чтобы лечь в кровать!
Good morning.=Доброе утро.
@1 of @2 players are in bed=@1 из @2 игроков в кровати
Force night skip=Пропустить ночь
You can only sleep at night.=Вы можете спать только ночью.
Leave Bed=Встать с кровати
@1 has gone to bed.=Игрок @1 лёг спать.

View File

@ -1,6 +1,11 @@
# textdomain: beds
Fancy Bed=
Simple Bed=
Red Fancy Bed=
Pink Fancy Bed=
White Simple Bed=
Red Simple Bed=
Blue Simple Bed=
This bed is already occupied!=
You have to stop moving before going to bed!=
Good morning.=
@ -8,3 +13,4 @@ Good morning.=
Force night skip=
You can only sleep at night.=
Leave Bed=
@1 has gone to bed.=

View File

@ -1,4 +1,5 @@
name = beds
description = beds which allows sleep, featured to (auto) skip the night.
description = mesh beds which allows sleep, featured to (auto) skip the night.
depends = default, wool
optional_depends = player_api, pova
min_minetest_version = 5.0

View File

@ -3,3 +3,5 @@ enable_bed_respawn (Enable bed respawn) bool true
enable_bed_night_skip (Enable night skip) bool true
bed_sleep_divide (Division of players needed to skip night) float 2
bed_show_sleep_msg (Show when player sleeps in chat) bool false

View File

@ -1,10 +1,13 @@
-- paths
local world_path = minetest.get_worldpath()
local org_file = world_path .. "/beds_spawns"
local file = world_path .. "/beds_spawns"
local bkwd = false
-- check for old PilzAdams beds mod spawns
-- check for PA's beds mod spawns
local cf = io.open(world_path .. "/beds_player_spawns", "r")
if cf ~= nil then
@ -13,6 +16,7 @@ if cf ~= nil then
bkwd = true
end
-- get respawn positions
function beds.read_spawns()
@ -25,9 +29,7 @@ function beds.read_spawns()
local x = input:read("*n")
if x == nil then
break
end
if x == nil then break end
local y = input:read("*n")
local z = input:read("*n")
@ -49,10 +51,11 @@ function beds.read_spawns()
end
end
-- load player spawn positions
beds.read_spawns()
-- save respawn positions
function beds.save_spawns()
@ -71,6 +74,7 @@ function beds.save_spawns()
io.close(output)
end
-- set spawn position
function beds.set_spawns()
@ -88,6 +92,7 @@ function beds.set_spawns()
beds.save_spawns()
end
-- remove respawn position
function beds.remove_spawns_at(pos)