1
0
Fork 0

Can't sleep in occupied beds

This commit is contained in:
Wuzzy 2019-02-20 20:40:06 +01:00
parent 079b09c80f
commit 88872c8ce2
2 changed files with 13 additions and 2 deletions

View File

@ -71,6 +71,13 @@ local function lay_down(player, pos, bed_pos, state, skip)
return false return false
end end
for _, other_pos in pairs(mcl_beds.bed_pos) do
if vector.distance(bed_pos, other_pos) < 0.1 then
minetest.chat_send_player(name, "This bed is already occupied!")
return false
end
end
-- No sleeping while moving. This is a workaround. -- No sleeping while moving. This is a workaround.
-- TODO: Ideally, the player speed should be force-set to 0, -- TODO: Ideally, the player speed should be force-set to 0,
-- but this is not possible in Minetest 0.4.17. -- but this is not possible in Minetest 0.4.17.
@ -111,7 +118,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
return false return false
end end
if p then if p then
player:setpos(p) player:set_pos(p)
end end
-- physics, eye_offset, etc -- physics, eye_offset, etc
@ -125,6 +132,8 @@ local function lay_down(player, pos, bed_pos, state, skip)
player:set_attribute("mcl_beds:sleeping", "false") player:set_attribute("mcl_beds:sleeping", "false")
hud_flags.wielditem = true hud_flags.wielditem = true
mcl_player.player_set_animation(player, "stand" , 30) mcl_player.player_set_animation(player, "stand" , 30)
mcl_beds.pos[name] = nil
mcl_beds.bed_pos[name] = nil
-- lay down -- lay down
else else
@ -167,6 +176,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
mcl_beds.player[name] = 1 mcl_beds.player[name] = 1
mcl_beds.pos[name] = pos mcl_beds.pos[name] = pos
mcl_beds.bed_pos[name] = bed_pos
player_in_bed = player_in_bed + 1 player_in_bed = player_in_bed + 1
-- physics, eye_offset, etc -- physics, eye_offset, etc
player:set_eye_offset({x = 0, y = -13, z = 0}, {x = 0, y = 0, z = 0}) player:set_eye_offset({x = 0, y = -13, z = 0}, {x = 0, y = 0, z = 0})
@ -176,7 +186,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
player:set_attribute("mcl_beds:sleeping", "true") player:set_attribute("mcl_beds:sleeping", "true")
playerphysics.add_physics_factor(player, "speed", "mcl_beds:sleeping", 0) playerphysics.add_physics_factor(player, "speed", "mcl_beds:sleeping", 0)
playerphysics.add_physics_factor(player, "jump", "mcl_beds:sleeping", 0) playerphysics.add_physics_factor(player, "jump", "mcl_beds:sleeping", 0)
player:setpos(p) player:set_pos(p)
mcl_player.player_attached[name] = true mcl_player.player_attached[name] = true
hud_flags.wielditem = false hud_flags.wielditem = false
mcl_player.player_set_animation(player, "lay" , 0) mcl_player.player_set_animation(player, "lay" , 0)

View File

@ -1,6 +1,7 @@
mcl_beds = {} mcl_beds = {}
mcl_beds.player = {} mcl_beds.player = {}
mcl_beds.pos = {} mcl_beds.pos = {}
mcl_beds.bed_pos = {}
local modpath = minetest.get_modpath("mcl_beds") local modpath = minetest.get_modpath("mcl_beds")