Skip to content
Permalink
Browse files

beds: Various bug fixes (#2566)

· Fixes players sleeping in an occupied bed (Wuzzys code)
· Fixes 'sleepwalking' by checking players velocity (Wuzzys code)
· Fixes sleeping player flying off the bed when damaged and flying far away from the bed after death
· Fixes sleeping player being immobilized and bed undiggable after death
  • Loading branch information
An0n3m0us committed Sep 2, 2020
1 parent 25bf3fd commit 268f869e67d5a3d37d30c5b130c45d25c7eb7558
Showing with 29 additions and 0 deletions.
  1. +29 −0 mods/beds/functions.lua
@@ -81,6 +81,21 @@ local function lay_down(player, pos, bed_pos, state, skip)

-- lay down
else

-- Check if bed is occupied
for _, other_pos in pairs(beds.bed_position) do
if vector.distance(bed_pos, other_pos) < 0.1 then
minetest.chat_send_player(name, S("This bed is already occupied!"))
return false
end
end

-- Check if player is moving
if vector.length(player:get_player_velocity()) > 0.001 then
minetest.chat_send_player(name, S("You have to stop moving before going to bed!"))
return false
end

beds.pos[name] = pos
beds.bed_position[name] = bed_pos
beds.player[name] = 1
@@ -230,6 +245,19 @@ minetest.register_on_leaveplayer(function(player)
end
end)

minetest.register_on_dieplayer(function(player)
local name = player:get_player_name()
local in_bed = beds.player
local pos = player:get_pos()
local yaw = get_look_yaw(pos)

if in_bed[name] then
lay_down(player, nil, pos, false)
player:set_look_horizontal(yaw)
player:set_pos(pos)
end
end)

minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "beds_form" then
return
@@ -256,3 +284,4 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end
end)

0 comments on commit 268f869

Please sign in to comment.
You can’t perform that action at this time.