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
This commit is contained in:
parent
6d650d5f3c
commit
b30d70f09d
@ -41,8 +41,12 @@ void cBlockEntityWithItems::OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum)
|
|||||||
{
|
{
|
||||||
UNUSED(a_SlotNum);
|
UNUSED(a_SlotNum);
|
||||||
ASSERT(a_Grid == &m_Contents);
|
ASSERT(a_Grid == &m_Contents);
|
||||||
if (m_World != nullptr)
|
|
||||||
|
if (m_World == nullptr)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (GetWindow() != nullptr)
|
if (GetWindow() != nullptr)
|
||||||
{
|
{
|
||||||
GetWindow()->BroadcastWholeWindow();
|
GetWindow()->BroadcastWholeWindow();
|
||||||
@ -51,9 +55,13 @@ void cBlockEntityWithItems::OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum)
|
|||||||
m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
|
m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
|
||||||
m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk)
|
m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk)
|
||||||
{
|
{
|
||||||
m_World->GetRedstoneSimulator()->WakeUp(m_Pos, &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;
|
return true;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -76,17 +76,21 @@ private:
|
|||||||
/** cItemGrid::cListener overrides: */
|
/** cItemGrid::cListener overrides: */
|
||||||
virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) override
|
virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) override
|
||||||
{
|
{
|
||||||
UNUSED(a_SlotNum);
|
|
||||||
ASSERT(a_Grid == &m_Contents);
|
ASSERT(a_Grid == &m_Contents);
|
||||||
if (m_World != nullptr)
|
|
||||||
|
if (m_World == nullptr)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Have cBlockEntityWithItems update redstone and try to broadcast our window:
|
||||||
|
Super::OnSlotChanged(a_Grid, a_SlotNum);
|
||||||
|
|
||||||
cWindow * Window = GetWindow();
|
cWindow * Window = GetWindow();
|
||||||
if (
|
if ((Window == nullptr) && (m_Neighbour != nullptr))
|
||||||
(Window == nullptr) &&
|
|
||||||
(m_Neighbour != nullptr)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// Neighbour might own the window
|
// Window was null, Super will have failed.
|
||||||
|
// Neighbour might own the window:
|
||||||
Window = m_Neighbour->GetWindow();
|
Window = m_Neighbour->GetWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,11 +102,15 @@ private:
|
|||||||
m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
|
m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
|
||||||
m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk)
|
m_World->DoWithChunkAt(m_Pos, [&](cChunk & a_Chunk)
|
||||||
{
|
{
|
||||||
m_World->GetRedstoneSimulator()->WakeUp(m_Pos, &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;
|
return true;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} ; // tolua_export
|
} ; // tolua_export
|
||||||
|
Loading…
Reference in New Issue
Block a user