diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-01-06 01:35:42 +0100 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2021-01-12 13:34:34 +0100 |
commit | 054a89dd9e5d6819adede9d7ba781b69f98ff2f4 (patch) | |
tree | 820a104cae2d9e4ec912b0a1bd7debac52cf4cc9 /src/Chunk.cpp | |
parent | Convert most calls to blocking GetHeight/GetBiomeAt to direct chunk accesses (diff) | |
download | cuberite-054a89dd9e5d6819adede9d7ba781b69f98ff2f4.tar cuberite-054a89dd9e5d6819adede9d7ba781b69f98ff2f4.tar.gz cuberite-054a89dd9e5d6819adede9d7ba781b69f98ff2f4.tar.bz2 cuberite-054a89dd9e5d6819adede9d7ba781b69f98ff2f4.tar.lz cuberite-054a89dd9e5d6819adede9d7ba781b69f98ff2f4.tar.xz cuberite-054a89dd9e5d6819adede9d7ba781b69f98ff2f4.tar.zst cuberite-054a89dd9e5d6819adede9d7ba781b69f98ff2f4.zip |
Diffstat (limited to 'src/Chunk.cpp')
-rw-r--r-- | src/Chunk.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 4140d4f85..0dc333468 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -668,8 +668,10 @@ void cChunk::SpawnMobs(cMobSpawner & a_MobSpawner) void cChunk::Tick(std::chrono::milliseconds a_Dt) { + const auto ShouldTick = ShouldBeTicked(); + // If we are not valid, tick players and bailout - if (!IsValid()) + if (!ShouldTick) { for (const auto & Entity : m_Entities) { @@ -681,11 +683,6 @@ void cChunk::Tick(std::chrono::milliseconds a_Dt) return; } - CheckBlocks(); - - // Tick simulators: - m_World->GetSimulatorManager()->SimulateChunk(a_Dt, m_PosX, m_PosZ, this); - TickBlocks(); // Tick all block entities in this chunk: @@ -745,6 +742,13 @@ void cChunk::Tick(std::chrono::milliseconds a_Dt) ApplyWeatherToTop(); + // Tick simulators: + m_World->GetSimulatorManager()->SimulateChunk(a_Dt, m_PosX, m_PosZ, this); + + // Check blocks after everything else to apply at least one round of queued ticks (i.e. cBlockHandler::Check) this tick: + CheckBlocks(); + + // Finally, tell the client about all block changes: BroadcastPendingBlockChanges(); } @@ -768,9 +772,11 @@ void cChunk::MoveEntityToNewChunk(OwnedEntity a_Entity) cChunk * Neighbor = GetNeighborChunk(a_Entity->GetChunkX() * cChunkDef::Width, a_Entity->GetChunkZ() * cChunkDef::Width); if (Neighbor == nullptr) { - LOGWARNING("%s: Failed to move entity, destination chunk unreachable. Entity lost", __FUNCTION__); - a_Entity->OnRemoveFromWorld(*m_World); - return; + LOGWARNING("%s: Entity at %p (%s, ID %d) moving to a non-existent chunk.", + __FUNCTION__, static_cast<void *>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID() + ); + + Neighbor = &m_ChunkMap->ConstructChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ()); } ASSERT(Neighbor != this); // Moving into the same chunk? wtf? @@ -1480,7 +1486,7 @@ cBlockEntity * cChunk::GetBlockEntityRel(Vector3i a_RelPos) bool cChunk::ShouldBeTicked(void) const { - return (HasAnyClients() || (m_AlwaysTicked > 0)); + return IsValid() && (HasAnyClients() || (m_AlwaysTicked > 0)); } |