1
0

Fixed double chests (#3741)

Normal and trapped chests next to each other don't open a double chest window.
Slot changes in the secondary chest are broadcast.
Placing a chest in +x of another updates the original chest's metadata.
This commit is contained in:
peterbell10 2017-06-03 20:17:53 +01:00 committed by Mattes D
parent 8f1e55611e
commit 36be4a89f8
3 changed files with 25 additions and 8 deletions

View File

@ -127,21 +127,28 @@ void cChestEntity::ScanNeighbours()
{ {
public: public:
cChestEntity * m_Neighbour; cChestEntity * m_Neighbour;
BLOCKTYPE m_ChestType;
cFindNeighbour() : cFindNeighbour(BLOCKTYPE a_ChestType) :
m_Neighbour(nullptr) m_Neighbour(nullptr),
m_ChestType(a_ChestType)
{ {
} }
virtual bool Item(cChestEntity * a_Chest) override virtual bool Item(cChestEntity * a_Chest) override
{ {
if (a_Chest->GetBlockType() != m_ChestType)
{
// Neighboring block is not the same type of chest
return true;
}
m_Neighbour = a_Chest; m_Neighbour = a_Chest;
return false; return false;
} }
}; };
// Scan horizontally adjacent blocks for any neighbouring chest: // Scan horizontally adjacent blocks for any neighbouring chest of the same type:
cFindNeighbour FindNeighbour; cFindNeighbour FindNeighbour(m_BlockType);
if ( if (
m_World->DoWithChestAt(m_PosX - 1, m_PosY, m_PosZ, FindNeighbour) || m_World->DoWithChestAt(m_PosX - 1, m_PosY, m_PosZ, FindNeighbour) ||
m_World->DoWithChestAt(m_PosX + 1, m_PosY, m_PosZ, FindNeighbour) || m_World->DoWithChestAt(m_PosX + 1, m_PosY, m_PosZ, FindNeighbour) ||

View File

@ -39,7 +39,7 @@ public:
virtual void SendTo(cClientHandle & a_Client) override; virtual void SendTo(cClientHandle & a_Client) override;
virtual bool UsedBy(cPlayer * a_Player) override; virtual bool UsedBy(cPlayer * a_Player) override;
/** Search horizontally adjacent blocks for neighbouring chests and links them together. */ /** Search horizontally adjacent blocks for neighbouring chests of the same type and links them together. */
void ScanNeighbours(); void ScanNeighbours();
/** Opens a new chest window where this is the primary chest and any neighbour is the secondary. */ /** Opens a new chest window where this is the primary chest and any neighbour is the secondary. */
@ -72,9 +72,19 @@ private:
ASSERT(a_Grid == &m_Contents); ASSERT(a_Grid == &m_Contents);
if (m_World != nullptr) if (m_World != nullptr)
{ {
if (GetWindow() != nullptr) cWindow * Window = GetWindow();
if (
(Window == nullptr) &&
(m_Neighbour != nullptr)
)
{ {
GetWindow()->BroadcastWholeWindow(); // Neighbour might own the window
Window = m_Neighbour->GetWindow();
}
if (Window != nullptr)
{
Window->BroadcastWholeWindow();
} }
m_World->MarkChunkDirty(GetChunkX(), GetChunkZ()); m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());

View File

@ -154,7 +154,7 @@ public:
} }
// Adjust the existing chest, if any: // Adjust the existing chest, if any:
if (NeighborIdx > 0) if (NeighborIdx != -1)
{ {
a_World.FastSetBlock(a_BlockX + CrossCoords[NeighborIdx].x, a_BlockY, a_BlockZ + CrossCoords[NeighborIdx].z, ChestBlockType, Meta); a_World.FastSetBlock(a_BlockX + CrossCoords[NeighborIdx].x, a_BlockY, a_BlockZ + CrossCoords[NeighborIdx].z, ChestBlockType, Meta);
} }