From 624dafc12bb894cf4278f3475ea143ef39529eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Thu, 11 Feb 2021 12:30:37 +0100 Subject: [PATCH] Fix crash on exit of bed formspec if not sleeping (#2826) --- mods/beds/functions.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mods/beds/functions.lua b/mods/beds/functions.lua index 46641636..f0ddae7a 100644 --- a/mods/beds/functions.lua +++ b/mods/beds/functions.lua @@ -60,18 +60,19 @@ local function lay_down(player, pos, bed_pos, state, skip) -- stand up if state ~= nil and not state then - local p = beds.pos[name] or nil + if not beds.player[name] then + -- player not in bed, do nothing + return false + end beds.bed_position[name] = nil -- skip here to prevent sending player specific changes (used for leaving players) if skip then return end - if p then - player:set_pos(p) - end + player:set_pos(beds.pos[name]) -- physics, eye_offset, etc - local physics_override = assert(beds.player[name].physics_override) + local physics_override = beds.player[name].physics_override beds.player[name] = nil player:set_physics_override({ speed = physics_override.speed, @@ -101,6 +102,11 @@ local function lay_down(player, pos, bed_pos, state, skip) return false end + if beds.player[name] then + -- player already in bed, do nothing + return false + end + beds.pos[name] = pos beds.bed_position[name] = bed_pos beds.player[name] = {physics_override = player:get_physics_override()}