From a62b2b1be2103d7de2fd66c7304b7473e369be3c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 5 May 2021 14:25:10 +0100 Subject: Move item placement into item handlers (#5184) * Move item placement into item handlers + Add appropriate CanBeAt checks in cPlayer::PlaceBlocks, into which all placement handlers call. * Partly addresses #5157 * Fixes #4878 * Fixes #2919 * Fixes #4629 * Fixes #4239 * Fixes #4849 Co-authored-by: changyong guo Co-authored-by: Xotheus Co-authored-by: Krist Pregracke * Review fixes * Update APIDesc.lua * Rename Co-authored-by: changyong guo Co-authored-by: Xotheus Co-authored-by: Krist Pregracke --- src/Blocks/BlockLever.h | 53 +++++++------------------------------------------ 1 file changed, 7 insertions(+), 46 deletions(-) (limited to 'src/Blocks/BlockLever.h') diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index ee5e99b9c..ddb459fbe 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -64,45 +64,6 @@ private: - virtual bool GetPlacementBlockTypeMeta( - cChunkInterface & a_ChunkInterface, - cPlayer & a_Player, - const Vector3i a_PlacedBlockPos, - eBlockFace a_ClickedBlockFace, - const Vector3i a_CursorPos, - BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta - ) const override - { - a_BlockType = m_BlockType; - a_BlockMeta = LeverDirectionToMetaData(a_ClickedBlockFace); - return true; - } - - - - - - /** Converts the block face of the neighbor to which the lever is attached to the lever block's meta. */ - inline static NIBBLETYPE LeverDirectionToMetaData(eBlockFace a_Dir) - { - // Determine lever direction: - switch (a_Dir) - { - case BLOCK_FACE_YP: return 0x6; - case BLOCK_FACE_XP: return 0x1; - case BLOCK_FACE_XM: return 0x2; - case BLOCK_FACE_ZP: return 0x3; - case BLOCK_FACE_ZM: return 0x4; - case BLOCK_FACE_YM: return 0x0; - case BLOCK_FACE_NONE: return 0x6; - } - UNREACHABLE("Unsupported block face"); - } - - - - - /** Converts the leve block's meta to the block face of the neighbor to which the lever is attached. */ inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) { @@ -128,18 +89,18 @@ private: - virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) const override + virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override { // Find the type of block the lever is attached to: - auto Meta = a_Chunk.GetMeta(a_RelPos); - auto NeighborFace = BlockMetaDataToBlockFace(Meta); - auto NeighborPos = AddFaceDirection(a_RelPos, NeighborFace, true); + auto NeighborFace = BlockMetaDataToBlockFace(a_Meta); + auto NeighborPos = AddFaceDirection(a_Position, NeighborFace, true); if (!cChunkDef::IsValidHeight(NeighborPos.y)) { return false; } BLOCKTYPE NeighborBlockType; - if (!a_Chunk.UnboundedRelGetBlock(NeighborPos, NeighborBlockType, Meta)) + NIBBLETYPE NeighborMeta; + if (!a_Chunk.UnboundedRelGetBlock(NeighborPos, NeighborBlockType, NeighborMeta)) { return false; } @@ -152,8 +113,8 @@ private: else if (cBlockSlabHandler::IsAnySlabType(NeighborBlockType)) { return ( - (((Meta & 0x08) == 0x08) && (NeighborFace == BLOCK_FACE_TOP)) || - (((Meta & 0x08) == 0) && (NeighborFace == BLOCK_FACE_BOTTOM)) + (((NeighborMeta & 0x08) == 0x08) && (NeighborFace == BLOCK_FACE_TOP)) || + (((NeighborMeta & 0x08) == 0) && (NeighborFace == BLOCK_FACE_BOTTOM)) ); } -- cgit v1.2.3