From 748b121703fa28b10933f4432c09391e66179118 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 28 Mar 2021 14:40:57 +0100 Subject: Unify DoWithBlockEntity (#5168) + DoWith calls now broadcast the block entity and mark the chunk dirty + Add block entity change queue to synchronise BE updates with block updates * Fixed a few incorrect assertions about BE type - Remove manual overloads --- src/BlockEntities/ChestEntity.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/BlockEntities/ChestEntity.cpp') diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index 039d62287..9ede18759 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -146,24 +146,25 @@ bool cChestEntity::UsedBy(cPlayer * a_Player) void cChestEntity::ScanNeighbours() { - // Callback for finding neighbouring chest: - auto FindNeighbour = [this](cChestEntity & a_Chest) + // Callback for finding neighbouring chest. + auto FindNeighbour = [this](cBlockEntity & a_BlockEntity) { - if (a_Chest.GetBlockType() != m_BlockType) + if (a_BlockEntity.GetBlockType() != m_BlockType) { // Neighboring block is not the same type of chest - return true; + return false; } - m_Neighbour = &a_Chest; - return false; + + m_Neighbour = static_cast(&a_BlockEntity); + return true; }; // Scan horizontally adjacent blocks for any neighbouring chest of the same type: if ( - m_World->DoWithChestAt(m_Pos.x - 1, m_Pos.y, m_Pos.z, FindNeighbour) || - m_World->DoWithChestAt(m_Pos.x + 1, m_Pos.y, m_Pos.z, FindNeighbour) || - m_World->DoWithChestAt(m_Pos.x, m_Pos.y, m_Pos.z - 1, FindNeighbour) || - m_World->DoWithChestAt(m_Pos.x, m_Pos.y, m_Pos.z + 1, FindNeighbour) + m_World->DoWithBlockEntityAt(m_Pos.addedX(-1), FindNeighbour) || + m_World->DoWithBlockEntityAt(m_Pos.addedX(+1), FindNeighbour) || + m_World->DoWithBlockEntityAt(m_Pos.addedZ(-1), FindNeighbour) || + m_World->DoWithBlockEntityAt(m_Pos.addedX(+1), FindNeighbour) ) { m_Neighbour->m_Neighbour = this; -- cgit v1.2.3