From f40aba941eaf69b52ac0fbe3d8cea1ea349b97a6 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Wed, 8 Apr 2020 21:35:08 +0100 Subject: Add mixins for blocks that rotate based on player yaw at placement Also add observer block handler. --- src/Blocks/BlockChest.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/Blocks/BlockChest.h') diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 0e277532e..2176bba96 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -11,9 +11,9 @@ class cBlockChestHandler : - public cMetaRotator, 0x07, 0x02, 0x05, 0x03, 0x04> + public cYawRotator> { - using super = cMetaRotator, 0x07, 0x02, 0x05, 0x03, 0x04>; + using super = cYawRotator>; public: @@ -33,8 +33,6 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) override { - a_BlockType = m_BlockType; - // Is there a doublechest already next to this block? if (!CanBeAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ)) { @@ -42,12 +40,20 @@ public: return false; } - // Check if this forms a doublechest, if so, need to adjust the meta: + // Try to read double-chest information: cBlockArea Area; if (!Area.Read(a_ChunkInterface, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1)) { return false; } + + // Get meta as if this was a single-chest: + if (!super::GetPlacementBlockTypeMeta(a_ChunkInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta)) + { + return false; + } + + // Check if this forms a doublechest, if so, need to adjust the meta: double yaw = a_Player.GetYaw(); if ( (Area.GetRelBlockType(0, 0, 1) == m_BlockType) || @@ -58,17 +64,15 @@ public: return true; } if ( - (Area.GetRelBlockType(0, 0, 1) == m_BlockType) || - (Area.GetRelBlockType(2, 0, 1) == m_BlockType) + (Area.GetRelBlockType(1, 0, 0) == m_BlockType) || + (Area.GetRelBlockType(1, 0, 2) == m_BlockType) ) { - // FIXME: This is unreachable, as the condition is the same as the above one a_BlockMeta = (yaw < 0) ? 4 : 5; return true; } - // Single chest, get meta from rotation only - a_BlockMeta = PlayerYawToMetaData(yaw); + return true; } -- cgit v1.2.3