From e0a361de2a7e6b5f1f63905f5495137cf8cd7f51 Mon Sep 17 00:00:00 2001 From: Mat Date: Wed, 24 Jun 2020 14:48:50 +0300 Subject: Send entities in cChunkSender (#4532) Confer issue #3696 --- src/ChunkSender.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/ChunkSender.cpp') diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp index ee079e430..3c4c565a3 100644 --- a/src/ChunkSender.cpp +++ b/src/ChunkSender.cpp @@ -247,22 +247,38 @@ void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkZ, std::unordered_setSendChunkData(a_ChunkX, a_ChunkZ, Data); + Client->SendChunkData(a_ChunkX, a_ChunkZ, Data); // Send block-entity packets: for (const auto & Pos : m_BlockEntities) { - m_World.SendBlockEntity(Pos.x, Pos.y, Pos.z, *client); + m_World.SendBlockEntity(Pos.x, Pos.y, Pos.z, *Client); } // for itr - m_Packets[] + // Send entity packets: + for (const auto EntityID : m_EntityIDs) + { + m_World.DoWithEntityByID(EntityID, [Client](cEntity & a_Entity) + { + /* + // DEBUG: + LOGD("cChunkSender: Entity #%d (%s) at [%f, %f, %f] spawning for player \"%s\"", + a_Entity.GetUniqueID(), a_Entity.GetClass(), + a_Entity.GetPosition().x, a_Entity.GetPosition().y, a_Entity.GetPosition().z, + Client->GetUsername().c_str() + ); + */ + a_Entity.SpawnOn(*Client); + return true; + }); + } } m_Data.Clear(); m_BlockEntities.clear(); - - // TODO: Send entity spawn packets + m_EntityIDs.clear(); } @@ -278,9 +294,9 @@ void cChunkSender::BlockEntity(cBlockEntity * a_Entity) -void cChunkSender::Entity(cEntity *) +void cChunkSender::Entity(cEntity * a_Entity) { - // Nothing needed yet, perhaps in the future when we save entities into chunks we'd like to send them upon load, too ;) + m_EntityIDs.push_back(a_Entity->GetUniqueID()); } -- cgit v1.2.3