getFastNoise2D() public static method

public static getFastNoise2D ( Noise $noise, integer $xSize, integer $zSize, integer $samplingRate, integer $x, integer $y, integer $z ) : SplFixedArray
$noise pocketmine\level\generator\noise\Noise
$xSize integer
$zSize integer
$samplingRate integer
$x integer
$y integer
$z integer
return SplFixedArray
Ejemplo n.º 1
0
 public function generateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     $seaFloorNoise = Generator::getFastNoise2D($this->noiseSeaFloor, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
     $landNoise = Generator::getFastNoise2D($this->noiseLand, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
     $mountainNoise = Generator::getFastNoise2D($this->noiseMountains, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
     $baseNoise = Generator::getFastNoise2D($this->noiseBaseGround, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
     $riverNoise = Generator::getFastNoise2D($this->noiseRiver, 16, 16, 4, $chunkX * 16, 0, $chunkZ * 16);
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     for ($genx = 0; $genx < 16; $genx++) {
         for ($genz = 0; $genz < 16; $genz++) {
             $canBaseGround = false;
             $canRiver = true;
             //using a quadratic function which smooth the world
             //y = (2.956x)^2 - 0.6,  (0 <= x <= 2)
             $landHeightNoise = $landNoise[$genx][$genz] + 1;
             $landHeightNoise *= 2.956;
             $landHeightNoise = $landHeightNoise * $landHeightNoise;
             $landHeightNoise = $landHeightNoise - 0.6;
             $landHeightNoise = $landHeightNoise > 0 ? $landHeightNoise : 0;
             //generate mountains
             $mountainHeightGenerate = $mountainNoise[$genx][$genz] - 0.2;
             $mountainHeightGenerate = $mountainHeightGenerate > 0 ? $mountainHeightGenerate : 0;
             $mountainGenerate = (int) ($this->mountainHeight * $mountainHeightGenerate);
             $landHeightGenerate = (int) ($this->landHeightRange * $landHeightNoise);
             if ($landHeightGenerate > $this->landHeightRange) {
                 if ($landHeightGenerate > $this->landHeightRange) {
                     $canBaseGround = true;
                 }
                 $landHeightGenerate = $this->landHeightRange;
             }
             $genyHeight = $this->seaFloorHeight + $landHeightGenerate;
             $genyHeight += $mountainGenerate;
             //prepare for generate ocean, desert, and land
             if ($genyHeight < $this->beathStartHeight) {
                 if ($genyHeight < $this->beathStartHeight - 5) {
                     $genyHeight += (int) ($this->seaFloorGenerateRange * $seaFloorNoise[$genx][$genz]);
                 }
                 $biome = Biome::getBiome(Biome::OCEAN);
                 if ($genyHeight < $this->seaFloorHeight - $this->seaFloorGenerateRange) {
                     $genyHeight = $this->seaFloorHeight;
                 }
                 $canRiver = false;
             } else {
                 if ($genyHeight <= $this->beathStopHeight && $genyHeight >= $this->beathStartHeight) {
                     //todo: there is no beach biome, use desert temporarily
                     $biome = Biome::getBiome(Biome::DESERT);
                 } else {
                     $biome = $this->pickBiome($chunkX * 16 + $genx, $chunkZ * 16 + $genz);
                     if ($canBaseGround) {
                         $baseGroundHeight = (int) ($this->landHeightRange * $landHeightNoise) - $this->landHeightRange;
                         $baseGroundHeight2 = (int) ($this->basegroundHeight * ($baseNoise[$genx][$genz] + 1));
                         if ($baseGroundHeight2 > $baseGroundHeight) {
                             $baseGroundHeight2 = $baseGroundHeight;
                         }
                         if ($baseGroundHeight2 > $mountainGenerate) {
                             $baseGroundHeight2 = $baseGroundHeight2 - $mountainGenerate;
                         } else {
                             $baseGroundHeight2 = 0;
                         }
                         $genyHeight += $baseGroundHeight2;
                     }
                 }
             }
             if ($canRiver && $genyHeight <= $this->seaHeight - 5) {
                 $canRiver = false;
             }
             //generate river
             if ($canRiver) {
                 $riverGenerate = $riverNoise[$genx][$genz];
                 if ($riverGenerate > -0.25 && $riverGenerate < 0.25) {
                     $riverGenerate = $riverGenerate > 0 ? $riverGenerate : -$riverGenerate;
                     $riverGenerate = 0.25 - $riverGenerate;
                     //y=x^2 * 4 - 0.0000001
                     $riverGenerate = $riverGenerate * $riverGenerate * 4;
                     //smooth again
                     $riverGenerate = $riverGenerate - 1.0E-7;
                     $riverGenerate = $riverGenerate > 0 ? $riverGenerate : 0;
                     $genyHeight -= $riverGenerate * 64;
                     if ($genyHeight < $this->seaHeight) {
                         $biome = Biome::getBiome(Biome::RIVER);
                         //to generate river floor
                         if ($genyHeight <= $this->seaHeight - 8) {
                             $genyHeight1 = $this->seaHeight - 9 + (int) ($this->basegroundHeight * ($baseNoise[$genx][$genz] + 1));
                             $genyHeight2 = $genyHeight < $this->seaHeight - 7 ? $this->seaHeight - 7 : $genyHeight;
                             $genyHeight = $genyHeight1 > $genyHeight2 ? $genyHeight1 : $genyHeight2;
                         }
                     }
                 }
             }
             $chunk->setBiomeId($genx, $genz, $biome->getId());
             //biome color
             //todo: smooth chunk color
             $biomeColor = $biome->getColor();
             $chunk->setBiomeColor($genx, $genz, $biomeColor >> 16, $biomeColor >> 8 & 0xff, $biomeColor & 0xff);
             //generating
             $generateHeight = $genyHeight > $this->seaHeight ? $genyHeight : $this->seaHeight;
             for ($geny = 0; $geny <= $generateHeight; $geny++) {
                 if ($geny <= $this->bedrockDepth && ($geny == 0 or $this->random->nextRange(1, 5) == 1)) {
                     $chunk->setBlockId($genx, $geny, $genz, Block::BEDROCK);
                 } elseif ($geny > $genyHeight) {
                     if (($biome->getId() == Biome::ICE_PLAINS or $biome->getId() == Biome::TAIGA) and $geny == $this->seaHeight) {
                         $chunk->setBlockId($genx, $geny, $genz, Block::ICE);
                     } else {
                         $chunk->setBlockId($genx, $geny, $genz, Block::STILL_WATER);
                     }
                 } else {
                     $chunk->setBlockId($genx, $geny, $genz, Block::STONE);
                 }
             }
         }
     }
     //populator chunk
     foreach ($this->generationPopulators as $populator) {
         $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
     }
 }