diff options
Diffstat (limited to 'src/Blocks/BlockWallSign.h')
-rw-r--r-- | src/Blocks/BlockWallSign.h | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/Blocks/BlockWallSign.h b/src/Blocks/BlockWallSign.h index 551107d88..87c0355a9 100644 --- a/src/Blocks/BlockWallSign.h +++ b/src/Blocks/BlockWallSign.h @@ -33,39 +33,45 @@ public: - virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) override { - int BlockX = (a_Chunk.GetPosX() * cChunkDef::Width) + a_RelX; - int BlockZ = (a_Chunk.GetPosZ() * cChunkDef::Width) + a_RelZ; - GetBlockCoordsBehindTheSign(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ), BlockX, BlockZ); - BLOCKTYPE Type = a_ChunkInterface.GetBlock({BlockX, a_RelY, BlockZ}); - - return ((Type == E_BLOCK_WALLSIGN) || (Type == E_BLOCK_SIGN_POST) || cBlockInfo::IsSolid(Type)); + auto NeighborPos = a_RelPos + GetOffsetBehindTheSign(a_Chunk.GetMeta(a_RelPos)); + BLOCKTYPE NeighborType; + if (!a_Chunk.UnboundedRelGetBlockType(NeighborPos, NeighborType)) + { + // The neighbor is not accessible (unloaded chunk), bail out without changing this + return true; + } + return ((NeighborType == E_BLOCK_WALLSIGN) || (NeighborType == E_BLOCK_SIGN_POST) || cBlockInfo::IsSolid(NeighborType)); } - static void GetBlockCoordsBehindTheSign(NIBBLETYPE a_BlockMeta, int & a_BlockX, int & a_BlockZ) + /** Returns the offset from the sign coords to the block to which the wallsign is attached, based on the wallsign's block meta. + Asserts / returns a zero vector on wrong meta. */ + static Vector3i GetOffsetBehindTheSign(NIBBLETYPE a_BlockMeta) { switch (a_BlockMeta) { - case 2: a_BlockZ++; break; - case 3: a_BlockZ--; break; - case 4: a_BlockX++; break; - case 5: a_BlockX--; break; - default: break; + case 2: return Vector3i( 0, 0, 1); + case 3: return Vector3i( 0, 0, -1); + case 4: return Vector3i( 1, 0, 0); + case 5: return Vector3i(-1, 0, 0); } + ASSERT(!"Invalid wallsign block meta"); + return Vector3i(); } - static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction) + /** Converts the block face of the neighbor to which the wallsign is attached to the wallsign block's meta. */ + static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_NeighborBlockFace) { - switch (a_Direction) + switch (a_NeighborBlockFace) { case BLOCK_FACE_ZM: return 0x02; case BLOCK_FACE_ZP: return 0x03; |