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

Function GetPineTreeImage

src/Generating/Trees.cpp:555–602  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

553
554
555void GetPineTreeImage(int a_BlockX, int a_BlockY, int a_BlockZ, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
556{
557 // Tall, little leaves on top. The top leaves are arranged in a shape of two cones joined by their bases.
558 // There can be one or two layers representing the cone bases (SameSizeMax)
559
560 int MyRandom = a_Noise.IntNoise3DInt(a_BlockX + 32 * a_Seq, a_BlockY, a_BlockZ + 32 * a_Seq) / 8;
561 int TrunkHeight = 8 + (MyRandom % 3);
562 int SameSizeMax = ((MyRandom & 8) == 0) ? 1 : 0;
563 MyRandom >>= 3;
564 int NumLeavesLayers = 2 + (MyRandom % 3); // Number of layers that have leaves in them
565 if (NumLeavesLayers == 2)
566 {
567 SameSizeMax = 0;
568 }
569
570 // Pre-allocate the vector:
571 a_LogBlocks.reserve(TrunkHeight);
572 a_OtherBlocks.reserve(NumLeavesLayers * 25);
573
574 // The entire trunk, out of logs:
575 for (int i = TrunkHeight; i >= 0; --i)
576 {
577 a_LogBlocks.push_back(sSetBlock(a_BlockX, a_BlockY + i, a_BlockZ, E_BLOCK_LOG, E_META_LOG_CONIFER));
578 }
579 int h = a_BlockY + TrunkHeight + 2;
580
581 // Top layer - just a single leaves block:
582 a_OtherBlocks.push_back(sSetBlock(a_BlockX, h, a_BlockZ, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER));
583 h--;
584
585 // One more layer is above the trunk, push the central leaves:
586 a_OtherBlocks.push_back(sSetBlock(a_BlockX, h, a_BlockZ, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER));
587
588 // Layers expanding in size, then collapsing again:
589 // LOGD("Generating %d layers of pine leaves, SameSizeMax = %d", NumLeavesLayers, SameSizeMax);
590 for (int i = 0; i < NumLeavesLayers; ++i)
591 {
592 int LayerSize = std::min(i, NumLeavesLayers - i + SameSizeMax - 1);
593 // LOGD("LayerSize %d: %d", i, LayerSize);
594 if (LayerSize < 0)
595 {
596 break;
597 }
598 ASSERT((size_t)LayerSize < ARRAYCOUNT(BigOs));
599 PushCoordBlocks(a_BlockX, h, a_BlockZ, a_OtherBlocks, BigOs[LayerSize].Coords, BigOs[LayerSize].Count, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER);
600 h--;
601 }
602}
603
604
605

Callers 2

Trees.hFile · 0.85
GetConiferTreeImageFunction · 0.85

Calls 3

sSetBlockClass · 0.85
PushCoordBlocksFunction · 0.85
IntNoise3DIntMethod · 0.80

Tested by

no test coverage detected