getFastNoise3D() public static method

public static getFastNoise3D ( Noise $noise, integer $xSize, integer $ySize, integer $zSize, integer $xSamplingRate, integer $ySamplingRate, integer $zSamplingRate, integer $x, integer $y, integer $z ) : SplFixedArray
$noise pocketmine\level\generator\noise\Noise
$xSize integer
$ySize integer
$zSize integer
$xSamplingRate integer
$ySamplingRate integer
$zSamplingRate integer
$x integer
$y integer
$z integer
return SplFixedArray
示例#1
1
 public function generateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     $noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     for ($x = 0; $x < 16; ++$x) {
         for ($z = 0; $z < 16; ++$z) {
             $biome = Biome::getBiome(Biome::HELL);
             $chunk->setBiomeId($x, $z, $biome->getId());
             $color = [0, 0, 0];
             $bColor = $biome->getColor();
             $color[0] += ($bColor >> 16) ** 2;
             $color[1] += ($bColor >> 8 & 0xff) ** 2;
             $color[2] += ($bColor & 0xff) ** 2;
             $chunk->setBiomeColor($x, $z, $color[0], $color[1], $color[2]);
             for ($y = 0; $y < 128; ++$y) {
                 if ($y === 0 or $y === 127) {
                     $chunk->setBlockId($x, $y, $z, Block::BEDROCK);
                     continue;
                 }
                 $noiseValue = abs($this->emptyHeight - $y) / $this->emptyHeight * $this->emptyAmplitude - $noise[$x][$z][$y];
                 $noiseValue -= 1 - $this->density;
                 if ($noiseValue > 0) {
                     $chunk->setBlockId($x, $y, $z, Block::NETHERRACK);
                 } elseif ($y <= $this->waterHeight) {
                     $chunk->setBlockId($x, $y, $z, Block::STILL_LAVA);
                 }
             }
         }
     }
     foreach ($this->generationPopulators as $populator) {
         $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
     }
 }
示例#2
0
 public function generateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     $noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     $biomeCache = [];
     for ($x = 0; $x < 16; ++$x) {
         for ($z = 0; $z < 16; ++$z) {
             $minSum = 0;
             $maxSum = 0;
             $weightSum = 0;
             $biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
             $chunk->setBiomeId($x, $z, $biome->getId());
             $color = [0, 0, 0];
             for ($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx) {
                 for ($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz) {
                     $weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE];
                     if ($sx === 0 and $sz === 0) {
                         $adjacent = $biome;
                     } else {
                         $index = Level::chunkHash($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
                         if (isset($biomeCache[$index])) {
                             $adjacent = $biomeCache[$index];
                         } else {
                             $biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
                         }
                     }
                     $minSum += ($adjacent->getMinElevation() - 1) * $weight;
                     $maxSum += $adjacent->getMaxElevation() * $weight;
                     $bColor = $adjacent->getColor();
                     $color[0] += ($bColor >> 16) ** 2 * $weight;
                     $color[1] += ($bColor >> 8 & 0xff) ** 2 * $weight;
                     $color[2] += ($bColor & 0xff) ** 2 * $weight;
                     $weightSum += $weight;
                 }
             }
             $minSum /= $weightSum;
             $maxSum /= $weightSum;
             $chunk->setBiomeColor($x, $z, sqrt($color[0] / $weightSum), sqrt($color[1] / $weightSum), sqrt($color[2] / $weightSum));
             $solidLand = false;
             for ($y = 127; $y >= 0; --$y) {
                 if ($y === 0) {
                     $chunk->setBlockId($x, $y, $z, Block::BEDROCK);
                     continue;
                 }
                 // A noiseAdjustment of 1 will guarantee ground, a noiseAdjustment of -1 will guarantee air.
                 //$effHeight = min($y - $smoothHeight - $minSum,
                 $noiseAdjustment = 2 * (($maxSum - $y) / ($maxSum - $minSum)) - 1;
                 // To generate caves, we bring the noiseAdjustment down away from 1.
                 $caveLevel = $minSum - 10;
                 $distAboveCaveLevel = max(0, $y - $caveLevel);
                 // must be positive
                 $noiseAdjustment = min($noiseAdjustment, 0.4 + $distAboveCaveLevel / 10);
                 $noiseValue = $noise[$x][$z][$y] + $noiseAdjustment;
                 if ($noiseValue > 0) {
                     $chunk->setBlockId($x, $y, $z, Block::STONE);
                     $solidLand = true;
                 } elseif ($y <= $this->waterHeight && $solidLand == false) {
                     $chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
                 }
             }
         }
     }
     foreach ($this->generationPopulators as $populator) {
         $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
     }
 }
 public function generateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0.0 ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     $noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     $biomeCache = [];
     for ($x = 0; $x < 16; ++$x) {
         for ($z = 0; $z < 16; ++$z) {
             $minSum = 0;
             $maxSum = 0;
             $weightSum = 0;
             $biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
             $chunk->setBiomeId($x, $z, $biome->getId());
             $color = [0, 0, 0];
             for ($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx) {
                 for ($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz) {
                     $weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE];
                     if ($sx === 0 and $sz === 0) {
                         $adjacent = $biome;
                     } else {
                         $index = ($chunkX * 16 + $x + $sx & 4294967295.0) << 32 | $chunkZ * 16 + $z + $sz & 4294967295.0;
                         if (isset($biomeCache[$index])) {
                             $adjacent = $biomeCache[$index];
                         } else {
                             $biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
                         }
                     }
                     $minSum += ($adjacent->getMinElevation() - 1) * $weight;
                     $maxSum += $adjacent->getMaxElevation() * $weight;
                     $bColor = $adjacent->getColor();
                     $color[0] += ($bColor >> 16) ** 2 * $weight;
                     $color[1] += ($bColor >> 8 & 0xff) ** 2 * $weight;
                     $color[2] += ($bColor & 0xff) ** 2 * $weight;
                     $weightSum += $weight;
                 }
             }
             $minSum /= $weightSum;
             $maxSum /= $weightSum;
             $chunk->setBiomeColor($x, $z, \sqrt($color[0] / $weightSum), \sqrt($color[1] / $weightSum), \sqrt($color[2] / $weightSum));
             $smoothHeight = ($maxSum - $minSum) / 2;
             for ($y = 0; $y < 128; ++$y) {
                 if ($y === 0) {
                     $chunk->setBlockId($x, $y, $z, Block::BEDROCK);
                     continue;
                 }
                 $noiseValue = $noise[$x][$z][$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minSum);
                 if ($noiseValue > 0) {
                     $chunk->setBlockId($x, $y, $z, Block::STONE);
                 } elseif ($y <= $this->waterHeight) {
                     $chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
                 }
             }
         }
     }
     foreach ($this->generationPopulators as $populator) {
         $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
     }
 }