MCPcopy Create free account
hub / github.com/cuberite/cuberite / SendChunk

Method SendChunk

src/ChunkSender.cpp:189–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187
188
189void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client)
190{
191 ASSERT(m_World != NULL);
192
193 // Ask the client if it still wants the chunk:
194 if (a_Client != NULL)
195 {
196 if (!a_Client->WantsSendChunk(a_ChunkX, a_ChunkY, a_ChunkZ))
197 {
198 return;
199 }
200 }
201
202 // If the chunk has no clients, no need to packetize it:
203 if (!m_World->HasChunkAnyClients(a_ChunkX, a_ChunkZ))
204 {
205 return;
206 }
207
208 // If the chunk is not valid, do nothing - whoever needs it has queued it for loading / generating
209 if (!m_World->IsChunkValid(a_ChunkX, a_ChunkZ))
210 {
211 return;
212 }
213
214 // If the chunk is not lighted, queue it for relighting and get notified when it's ready:
215 if (!m_World->IsChunkLighted(a_ChunkX, a_ChunkZ))
216 {
217 m_World->QueueLightChunk(a_ChunkX, a_ChunkZ, &m_Notify);
218 return;
219 }
220
221 // Query and prepare chunk data:
222 if (!m_World->GetChunkData(a_ChunkX, a_ChunkZ, *this))
223 {
224 return;
225 }
226 cChunkDataSerializer Data(m_BlockTypes, m_BlockMetas, m_BlockLight, m_BlockSkyLight, m_BiomeMap);
227
228 // Send:
229 if (a_Client == NULL)
230 {
231 m_World->BroadcastChunkData(a_ChunkX, a_ChunkZ, Data);
232 }
233 else
234 {
235 a_Client->SendChunkData(a_ChunkX, a_ChunkZ, Data);
236 }
237
238 // Send block-entity packets:
239 for (sBlockCoords::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end(); ++itr)
240 {
241 if (a_Client == NULL)
242 {
243 m_World->BroadcastBlockEntity(itr->m_BlockX, itr->m_BlockY, itr->m_BlockZ);
244 }
245 else
246 {

Callers

nothing calls this directly

Calls 13

WantsSendChunkMethod · 0.80
QueueLightChunkMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
clearMethod · 0.80
HasChunkAnyClientsMethod · 0.45
IsChunkValidMethod · 0.45
IsChunkLightedMethod · 0.45
GetChunkDataMethod · 0.45
BroadcastChunkDataMethod · 0.45
SendChunkDataMethod · 0.45
BroadcastBlockEntityMethod · 0.45

Tested by

no test coverage detected