1
0

Fix improper destruction of BEs on /regen

This commit is contained in:
Tiger Wang 2021-04-11 23:10:25 +01:00
parent 0137e71f6b
commit 64778c6a39

View File

@ -253,9 +253,9 @@ void cChunk::OnUnload()
}
// Notify all block entities of imminent unload:
for (auto & BlockEntity : m_BlockEntities)
for (auto & KeyPair : m_BlockEntities)
{
BlockEntity.second->OnRemoveFromWorld();
KeyPair.second->OnRemoveFromWorld();
}
}
@ -362,19 +362,26 @@ void cChunk::SetAllData(SetChunkData && a_SetChunkData)
Entity->SetIsTicking(true);
}
// Clear the block entities present - either the loader / saver has better, or we'll create empty ones:
// Remove the block entities present - either the loader / saver has better, or we'll create empty ones:
for (auto & KeyPair : m_BlockEntities)
{
KeyPair.second->Destroy();
KeyPair.second->OnRemoveFromWorld();
}
// Clear the old ones:
m_BlockEntities = std::move(a_SetChunkData.BlockEntities);
// Check that all block entities have a valid blocktype at their respective coords (DEBUG-mode only):
#ifndef NDEBUG
for (auto & KeyPair : m_BlockEntities)
{
cBlockEntity * Block = KeyPair.second.get();
BLOCKTYPE EntityBlockType = Block->GetBlockType();
BLOCKTYPE WorldBlockType = GetBlock(Block->GetRelX(), Block->GetPosY(), Block->GetRelZ());
ASSERT(WorldBlockType == EntityBlockType);
} // for KeyPair - m_BlockEntities
#endif // !NDEBUG
#ifndef NDEBUG
for (auto & KeyPair : m_BlockEntities)
{
cBlockEntity * Block = KeyPair.second.get();
BLOCKTYPE EntityBlockType = Block->GetBlockType();
BLOCKTYPE WorldBlockType = GetBlock(Block->GetRelX(), Block->GetPosY(), Block->GetRelZ());
ASSERT(WorldBlockType == EntityBlockType);
}
#endif
// Set all block entities' World variable:
for (auto & KeyPair : m_BlockEntities)