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

Method WriteBlockArea

src/Chunk.cpp:353–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

351
352
353void cChunk::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes)
354{
355 if ((a_DataTypes & (cBlockArea::baTypes | cBlockArea::baMetas)) != (cBlockArea::baTypes | cBlockArea::baMetas))
356 {
357 LOGWARNING("cChunk::WriteBlockArea(): unsupported datatype request, can write only types + metas (0x%x), requested 0x%x. Ignoring.",
358 (cBlockArea::baTypes | cBlockArea::baMetas), a_DataTypes & (cBlockArea::baTypes | cBlockArea::baMetas)
359 );
360 return;
361 }
362
363 // SizeX, SizeZ are the dimensions of the block data to copy to the chunk (size of the geometric union)
364
365 int BlockStartX = std::max(a_MinBlockX, m_PosX * cChunkDef::Width);
366 int BlockEndX = std::min(a_MinBlockX + a_Area.GetSizeX(), (m_PosX + 1) * cChunkDef::Width);
367 int BlockStartZ = std::max(a_MinBlockZ, m_PosZ * cChunkDef::Width);
368 int BlockEndZ = std::min(a_MinBlockZ + a_Area.GetSizeZ(), (m_PosZ + 1) * cChunkDef::Width);
369 int SizeX = BlockEndX - BlockStartX;
370 int SizeZ = BlockEndZ - BlockStartZ;
371 int OffX = BlockStartX - m_PosX * cChunkDef::Width;
372 int OffZ = BlockStartZ - m_PosZ * cChunkDef::Width;
373 int BaseX = BlockStartX - a_MinBlockX;
374 int BaseZ = BlockStartZ - a_MinBlockZ;
375 int SizeY = a_Area.GetSizeY();
376
377 // TODO: Improve this by not calling FastSetBlock() and doing the processing here
378 // so that the heightmap is touched only once for each column.
379 BLOCKTYPE * AreaBlockTypes = a_Area.GetBlockTypes();
380 NIBBLETYPE * AreaBlockMetas = a_Area.GetBlockMetas();
381 for (int y = 0; y < SizeY; y++)
382 {
383 int ChunkY = a_MinBlockY + y;
384 int AreaY = y;
385 for (int z = 0; z < SizeZ; z++)
386 {
387 int ChunkZ = OffZ + z;
388 int AreaZ = BaseZ + z;
389 for (int x = 0; x < SizeX; x++)
390 {
391 int ChunkX = OffX + x;
392 int AreaX = BaseX + x;
393 int idx = a_Area.MakeIndex(AreaX, AreaY, AreaZ);
394 BLOCKTYPE BlockType = AreaBlockTypes[idx];
395 NIBBLETYPE BlockMeta = AreaBlockMetas[idx];
396 FastSetBlock(ChunkX, ChunkY, ChunkZ, BlockType, BlockMeta);
397 } // for x
398 } // for z
399 } // for y
400}
401
402
403

Callers

nothing calls this directly

Calls 6

GetSizeXMethod · 0.80
GetSizeZMethod · 0.80
GetSizeYMethod · 0.80
GetBlockMetasMethod · 0.80
GetBlockTypesMethod · 0.45
MakeIndexMethod · 0.45

Tested by

no test coverage detected