Use a new table beds.bed_position to check if a bed is in use.
def -- See [#Bed definition]
)
+ * `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_players()` Forces all players to leave bed
* `beds.skip_night()` Sets world time to morning and saves respawn position of all players currently sleeping
minetest.set_node(newp, {name = name .. "_top", param2 = new_param2})
return true
end,
+ can_dig = function(pos, player)
+ return beds.can_dig(pos)
+ end,
})
minetest.register_node(name .. "_top", {
on_destruct = function(pos)
destruct_bed(pos, 2)
end,
+ can_dig = function(pos, player)
+ local node = minetest.get_node(pos)
+ local dir = minetest.facedir_to_dir(node.param2)
+ local p = vector.add(pos, dir)
+ return beds.can_dig(p)
+ end,
})
minetest.register_alias(name, name .. "_bottom")
local p = beds.pos[name] or nil
if beds.player[name] ~= nil then
beds.player[name] = nil
+ beds.bed_position[name] = nil
player_in_bed = player_in_bed - 1
end
-- skip here to prevent sending player specific changes (used for leaving players)
else
beds.player[name] = 1
beds.pos[name] = pos
+ beds.bed_position[name] = bed_pos
player_in_bed = player_in_bed + 1
-- physics, eye_offset, etc
end
end
+function beds.can_dig(bed_pos)
+ -- Check all players in bed which one is at the expected position
+ for _, player_bed_pos in pairs(beds.bed_position) do
+ if vector.equals(bed_pos, player_bed_pos) then
+ return false
+ end
+ end
+ return true
+end
-- Callbacks
-- Only register respawn callback if respawn enabled
beds = {}
beds.player = {}
+beds.bed_position = {}
beds.pos = {}
beds.spawn = {}