From 33f3c18bc1646496b95f7652ffc292c9aade7a05 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 13 Sep 2020 11:58:39 +0100 Subject: Beds: derestrict clicking block face (#4863) Ref: https://github.com/cuberite/cuberite/issues/4860#issuecomment-691545904 --- src/Items/ItemBed.h | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) (limited to 'src/Items/ItemBed.h') diff --git a/src/Items/ItemBed.h b/src/Items/ItemBed.h index 9c79a134a..98f9f614f 100644 --- a/src/Items/ItemBed.h +++ b/src/Items/ItemBed.h @@ -22,18 +22,12 @@ public: } - - - virtual bool IsPlaceable(void) override { return true; } - - - virtual bool GetBlocksToPlace( cWorld & a_World, cPlayer & a_Player, @@ -44,25 +38,19 @@ public: sSetBlockVector & a_BlocksToPlace ) override { - // Can only be placed on the floor: - if (a_ClickedBlockFace != BLOCK_FACE_TOP) - { - return false; - } - - // The "foot" block: - NIBBLETYPE BlockMeta = cBlockBedHandler::YawToMetaData(a_Player.GetYaw()); - a_BlocksToPlace.emplace_back(a_PlacedBlockPos, E_BLOCK_BED, BlockMeta); + const auto BlockMeta = cBlockBedHandler::YawToMetaData(a_Player.GetYaw()); + const auto HeadPosition = a_PlacedBlockPos + cBlockBedHandler::MetaDataToDirection(BlockMeta); + // Vanilla only allows beds to be placed into air // Check if there is empty space for the "head" block: - // (Vanilla only allows beds to be placed into air) - auto Direction = cBlockBedHandler::MetaDataToDirection(BlockMeta); - auto HeadPos = a_PlacedBlockPos + Direction; - if (a_World.GetBlock(HeadPos) != E_BLOCK_AIR) + if (a_World.GetBlock(HeadPosition) != E_BLOCK_AIR) { return false; } - a_BlocksToPlace.emplace_back(HeadPos, E_BLOCK_BED, BlockMeta | 0x08); + + // The "foot", and the "head" block: + a_BlocksToPlace.emplace_back(a_PlacedBlockPos, E_BLOCK_BED, BlockMeta); + a_BlocksToPlace.emplace_back(HeadPosition, E_BLOCK_BED, BlockMeta | 0x08); return true; } }; -- cgit v1.2.3