diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-04-10 00:18:09 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2021-04-12 23:35:07 +0200 |
commit | 2fc86476ae04ea2f11a41215f783cdbc5d924579 (patch) | |
tree | 6c738eb84cb20d85f050785661e9df77ac6c29da /src/Blocks/BlockBed.h | |
parent | Unify multiprotocol entity animations (diff) | |
download | cuberite-2fc86476ae04ea2f11a41215f783cdbc5d924579.tar cuberite-2fc86476ae04ea2f11a41215f783cdbc5d924579.tar.gz cuberite-2fc86476ae04ea2f11a41215f783cdbc5d924579.tar.bz2 cuberite-2fc86476ae04ea2f11a41215f783cdbc5d924579.tar.lz cuberite-2fc86476ae04ea2f11a41215f783cdbc5d924579.tar.xz cuberite-2fc86476ae04ea2f11a41215f783cdbc5d924579.tar.zst cuberite-2fc86476ae04ea2f11a41215f783cdbc5d924579.zip |
Diffstat (limited to 'src/Blocks/BlockBed.h')
-rw-r--r-- | src/Blocks/BlockBed.h | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 1765773d6..7da6740bd 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -36,19 +36,40 @@ public: return Vector3i(); } - static void SetBedOccupationState(cChunkInterface & a_ChunkInterface, Vector3i a_BedPosition, bool a_IsOccupied) + static void VacateBed(cChunkInterface & a_ChunkInterface, cPlayer & a_Player) { - auto Meta = a_ChunkInterface.GetBlockMeta(a_BedPosition); - if (a_IsOccupied) + auto BedPosition = a_Player.GetLastBedPos(); + + BLOCKTYPE Type; + NIBBLETYPE Meta; + a_ChunkInterface.GetBlockTypeMeta(BedPosition, Type, Meta); + + if (Type != E_BLOCK_BED) { - Meta |= 0x04; // Where 0x4 = occupied bit + // Bed was incomplete, just wake: + a_Player.SetIsInBed(false); + return; } - else + + if ((Meta & 0x8) == 0) { - Meta &= 0x0b; // Clear the "occupied" bit of the bed's block + // BedPosition is the foot of the bed, adjust to the head: + BedPosition += MetaDataToDirection(Meta & 0x03); + + a_ChunkInterface.GetBlockTypeMeta(BedPosition, Type, Meta); + if (Type != E_BLOCK_BED) + { + // Bed was incomplete, just wake: + a_Player.SetIsInBed(false); + return; + } } - a_ChunkInterface.SetBlockMeta(a_BedPosition, Meta); + // Clear the "occupied" bit of the bed's pillow block: + a_ChunkInterface.SetBlockMeta(BedPosition, Meta & 0x0b); + + // Wake the player: + a_Player.SetIsInBed(false); } private: @@ -79,19 +100,9 @@ private: - static void SetBedPos(cPlayer & a_Player, const Vector3i a_BedPosition); - - - - - virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override { UNUSED(a_Meta); return 28; } } ; - - - - |