From b30d70f09d8a068c32a78f85c5208ec637dee19c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 26 Jul 2020 00:02:07 +0100 Subject: Call BlockEntityWithItems from ChestEntity slot changed handler * Small degree of unification for what to do with the current entity * Make sure to do necessary actions for both sides of a double chest --- src/BlockEntities/BlockEntityWithItems.cpp | 34 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/BlockEntities/BlockEntityWithItems.cpp') diff --git a/src/BlockEntities/BlockEntityWithItems.cpp b/src/BlockEntities/BlockEntityWithItems.cpp index 8dad08650..1a8ae4342 100644 --- a/src/BlockEntities/BlockEntityWithItems.cpp +++ b/src/BlockEntities/BlockEntityWithItems.cpp @@ -41,19 +41,27 @@ void cBlockEntityWithItems::OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) { UNUSED(a_SlotNum); ASSERT(a_Grid == &m_Contents); - if (m_World != nullptr) + + if (m_World == nullptr) + { + return; + } + + if (GetWindow() != nullptr) { - if (GetWindow() != nullptr) - { - GetWindow()->BroadcastWholeWindow(); - } - - m_World->MarkChunkDirty(GetChunkX(), GetChunkZ()); - m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk) - { - m_World->GetRedstoneSimulator()->WakeUp(m_Pos, &a_Chunk); - return true; - } - ); + GetWindow()->BroadcastWholeWindow(); } + + m_World->MarkChunkDirty(GetChunkX(), GetChunkZ()); + m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk) + { + auto & Simulator = *m_World->GetRedstoneSimulator(); + + // Notify comparators: + Simulator.WakeUp(m_Pos + Vector3i(1, 0, 0), &a_Chunk); + Simulator.WakeUp(m_Pos + Vector3i(-1, 0, 0), &a_Chunk); + Simulator.WakeUp(m_Pos + Vector3i(0, 0, 1), &a_Chunk); + Simulator.WakeUp(m_Pos + Vector3i(0, 0, -1), &a_Chunk); + return true; + }); } -- cgit v1.2.3