1
0

Replace ItemCallbacks with lambdas (#3993)

This commit is contained in:
peterbell10
2017-09-11 22:20:49 +01:00
committed by Mattes D
parent 115bc5609a
commit e225b7f826
69 changed files with 919 additions and 1817 deletions

View File

@@ -138,33 +138,18 @@ bool cChestEntity::UsedBy(cPlayer * a_Player)
void cChestEntity::ScanNeighbours()
{
// Callback for finding neighbouring chest:
class cFindNeighbour :
public cChestCallback
auto FindNeighbour = [this](cChestEntity & a_Chest)
{
public:
cChestEntity * m_Neighbour;
BLOCKTYPE m_ChestType;
cFindNeighbour(BLOCKTYPE a_ChestType) :
m_Neighbour(nullptr),
m_ChestType(a_ChestType)
if (a_Chest.GetBlockType() != m_BlockType)
{
// Neighboring block is not the same type of chest
return true;
}
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;
return false;
}
m_Neighbour = &a_Chest;
return false;
};
// Scan horizontally adjacent blocks for any neighbouring chest of the same type:
cFindNeighbour FindNeighbour(m_BlockType);
if (
m_World->DoWithChestAt(m_PosX - 1, m_PosY, m_PosZ, FindNeighbour) ||
m_World->DoWithChestAt(m_PosX + 1, m_PosY, m_PosZ, FindNeighbour) ||
@@ -172,7 +157,6 @@ void cChestEntity::ScanNeighbours()
m_World->DoWithChestAt(m_PosX, m_PosY, m_PosZ + 1, FindNeighbour)
)
{
m_Neighbour = FindNeighbour.m_Neighbour;
m_Neighbour->m_Neighbour = this;
// Force neighbour's window shut. Does Mojang server do this or should a double window open?
m_Neighbour->DestroyWindow();