1
0

Beds: derestrict clicking block face (#4863)

Ref: https://github.com/cuberite/cuberite/issues/4860#issuecomment-691545904
This commit is contained in:
Tiger Wang 2020-09-13 11:58:39 +01:00 committed by GitHub
parent 198407807f
commit 33f3c18bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
};