summaryrefslogtreecommitdiffstats
path: root/src/ChunkMap.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ChunkMap.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 0a8164b47..dba6f3f41 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1665,6 +1665,30 @@ void cChunkMap::AddEntity(cEntity * a_Entity)
+void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ());
+ if (
+ (Chunk == NULL) || // Chunk not present at all
+ (!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953)
+ )
+ {
+ LOGWARNING("Entity at %p (%s, ID %d) spawning in a non-existent chunk, the entity is lost.",
+ a_Entity, a_Entity->GetClass(), a_Entity->GetUniqueID()
+ );
+ return;
+ }
+ if (!Chunk->HasEntity(a_Entity->GetUniqueID()))
+ {
+ Chunk->AddEntity(a_Entity);
+ }
+}
+
+
+
+
+
bool cChunkMap::HasEntity(int a_UniqueID)
{
cCSLock Lock(m_CSLayers);