From 2fc86476ae04ea2f11a41215f783cdbc5d924579 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 9 Apr 2021 23:18:09 +0100 Subject: Improve bed handling robustness + Boot the player out if the bed was destroyed --- src/Entities/Player.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 563a1cb97..f5752ffb4 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -481,11 +481,12 @@ void cPlayer::SetIsInBed(const bool a_GoToBed) if (a_GoToBed && IsStanding()) { m_BodyStance = BodyStanceSleeping(*this); + m_World->BroadcastEntityAnimation(*this, EntityAnimation::PlayerEntersBed); } else if (!a_GoToBed && IsInBed()) { m_BodyStance = BodyStanceStanding(*this); - GetWorld()->BroadcastEntityAnimation(*this, 2); + m_World->BroadcastEntityAnimation(*this, EntityAnimation::PlayerLeavesBed); } } @@ -3252,6 +3253,14 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) SetElytraFlight(false); } } + else if (IsInBed()) + { + // Check if sleeping is still possible: + if ((GetPosition().Floor() != m_LastBedPos) || (m_World->GetBlock(m_LastBedPos) != E_BLOCK_BED)) + { + m_ClientHandle->HandleLeaveBed(); + } + } BroadcastMovementUpdate(m_ClientHandle.get()); -- cgit v1.2.3