Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no sq] Kick players from beds that have ceased existing #3168

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ globals = {
read_globals = {
"DIR_DELIM",
"minetest",
"core",
"dump",
"vector",
"VoxelManip", "VoxelArea",
Expand Down
1 change: 1 addition & 0 deletions game_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Beds API

* `beds.can_dig(bed_pos)` Returns a boolean whether the bed at `bed_pos` may be dug
* `beds.read_spawns() ` Returns a table containing players respawn positions
* `beds.kick(player)` Forces `player` to leave bed
* `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
Expand Down
11 changes: 9 additions & 2 deletions mods/beds/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ local function destruct_bed(pos, n)
end
end

beds.is_bed_node = {}

local function register_bed_node(name, def)
beds.is_bed_node[name] = true
core.register_node(name, def)
end

function beds.register_bed(name, def)
minetest.register_node(name .. "_bottom", {
register_bed_node(name .. "_bottom", {
description = def.description,
inventory_image = def.inventory_image,
wield_image = def.wield_image,
Expand Down Expand Up @@ -150,7 +157,7 @@ function beds.register_bed(name, def)
end,
})

minetest.register_node(name .. "_top", {
register_bed_node(name .. "_top", {
drawtype = "nodebox",
tiles = def.tiles.top,
use_texture_alpha = "clip",
Expand Down
17 changes: 14 additions & 3 deletions mods/beds/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,24 @@ end

-- Public functions

function beds.kick(player)
lay_down(player, nil, nil, false)
end

function beds.kick_players()
for name, _ in pairs(beds.player) do
local player = minetest.get_player_by_name(name)
lay_down(player, nil, nil, false)
for name in pairs(beds.player) do
beds.kick(core.get_player_by_name(name))
end
end

core.register_globalstep(function()
for name, bed_pos in pairs(beds.bed_position) do
if not beds.is_bed_node[core.get_node(bed_pos).name] then
beds.kick(core.get_player_by_name(name))
end
end
end)

function beds.skip_night()
minetest.set_timeofday(0.23)
end
Expand Down