1
0

Rewritten block entity loading.

Block entities are now loaded based on the blocktype at the coords they specify; before loading, their type ("id" NBT tag) is checked.
The chunk now expects that all block entities given to it via cChunk::SetAllData() have their valid blocktype; asserts if they don't.
Fixes #1354.
This commit is contained in:
Mattes D
2014-08-29 19:19:27 +03:00
parent d0551e2e0a
commit 22e3bbd0db
7 changed files with 323 additions and 230 deletions

View File

@@ -5,6 +5,7 @@
#include "Globals.h"
#include "SetChunkData.h"
#include "BlockEntities/BlockEntity.h"
@@ -116,3 +117,35 @@ void cSetChunkData::CalculateHeightMap(void)
void cSetChunkData::RemoveInvalidBlockEntities(void)
{
for (cBlockEntityList::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end();)
{
BLOCKTYPE EntityBlockType = (*itr)->GetBlockType();
BLOCKTYPE WorldBlockType = cChunkDef::GetBlock(m_BlockTypes, (*itr)->GetRelX(), (*itr)->GetPosY(), (*itr)->GetRelZ());
if (EntityBlockType != WorldBlockType)
{
// Bad blocktype, remove the block entity:
LOGD("Block entity blocktype mismatch at {%d, %d, %d}: entity for blocktype %s(%d) in block %s(%d). Deleting the block entity.",
(*itr)->GetPosX(), (*itr)->GetPosY(), (*itr)->GetPosZ(),
ItemTypeToString(EntityBlockType).c_str(), EntityBlockType,
ItemTypeToString(WorldBlockType).c_str(), WorldBlockType
);
cBlockEntityList::iterator itr2 = itr;
itr2++;
m_BlockEntities.erase(itr);
delete *itr;
itr = itr2;
}
else
{
// Good blocktype, keep the block entity:
++itr;
}
} // for itr - m_BlockEntities[]
}