Skip to content

Commit b517bdb

Browse files
authored
Fix player not kicked out of bed on destruct (#3225)
1 parent df4bd15 commit b517bdb

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

game_api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Beds API
4949
* `beds.can_dig(bed_pos)` Returns a boolean whether the bed at `bed_pos` may be dug
5050
* `beds.read_spawns() ` Returns a table containing players respawn positions
5151
* `beds.kick_players()` Forces all players to leave bed
52+
* `beds.kick_player_at(pos)` Forces player out of bed at pos (returns true on success, false otherwise)
5253
* `beds.skip_night()` Sets world time to morning and saves respawn position of all players currently sleeping
5354
* `beds.day_interval` Is a table with keys "start" and "finish". Allows you
5455
to set the period of the day (timeofday format). Default: `{ start = 0.2, finish = 0.805 }`.

mods/beds/api.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ local function destruct_bed(pos, n)
3636
beds.remove_spawns_at(other)
3737
end
3838
beds.remove_spawns_at(pos)
39+
if n == 1 then
40+
beds.kick_player_at(pos)
41+
elseif n == 2 and other then
42+
beds.kick_player_at(other)
43+
end
3944
end
4045

4146
function beds.register_bed(name, def)

mods/beds/functions.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,24 @@ local function schedule_update()
251251
end)
252252
end
253253

254+
function beds.kick_player_at(kick_pos)
255+
for name, bed_pos in pairs(beds.bed_position) do
256+
if vector.equals(bed_pos, kick_pos) then
257+
if beds.player[name] then
258+
local player = core.get_player_by_name(name)
259+
if not player then
260+
return false
261+
end
262+
lay_down(player, nil, nil, false)
263+
core.close_formspec(name, "beds_form")
264+
core.log("info", "[beds] Kicked "..name.." out of bed at "..core.pos_to_string(kick_pos))
265+
return true
266+
end
267+
end
268+
end
269+
return false
270+
end
271+
254272
function beds.on_rightclick(pos, player)
255273
local name = player:get_player_name()
256274
local ppos = player:get_pos()

0 commit comments

Comments
 (0)