Update MultiPlayerChunkCache.cpp

This commit is contained in:
DeadVoxelx
2026-03-27 16:22:17 -04:00
committed by GitHub
parent e6062c7edf
commit 47ecda0cf3

View File

@@ -139,26 +139,19 @@ bool MultiPlayerChunkCache::reallyHasChunk(int x, int z)
return hasData[idx];
}
void MultiPlayerChunkCache::drop(const int x, const int z)
void MultiPlayerChunkCache::drop(int x, int z)
{
const int ix = x + XZOFFSET;
const int iz = z + XZOFFSET;
if ((ix < 0) || (ix >= XZSIZE)) return;
if ((iz < 0) || (iz >= XZSIZE)) return;
const int idx = ix * XZSIZE + iz;
LevelChunk* chunk = cache[idx];
if (chunk != nullptr && !chunk->isEmpty())
// 4J Stu - We do want to drop any entities in the chunks, especially for the case when a player is dead as they will
// not get the RemoveEntity packet if an entity is removed.
LevelChunk *chunk = getChunk(x, z);
if (!chunk->isEmpty())
{
// Unload chunk but keep tile entities
// Added parameter here specifies that we don't want to delete tile entities, as they won't get recreated unless they've got update packets
// The tile entities are in general only created on the client by virtue of the chunk rebuild
chunk->unload(false);
const auto it = std::find(loadedChunkList.begin(), loadedChunkList.end(), chunk);
if (it != loadedChunkList.end()) loadedChunkList.erase(it);
cache[idx] = nullptr;
hasData[idx] = false;
chunk->loaded = false;
// 4J - We just want to clear out the entities in the chunk, but everything else should be valid
chunk->loaded = true;
}
}
@@ -316,4 +309,4 @@ void MultiPlayerChunkCache::dataReceived(int x, int z)
if( ( iz < 0 ) || ( iz >= XZSIZE ) ) return;
int idx = ix * XZSIZE + iz;
hasData[idx] = true;
}
}