當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Generator::getFastNoise3D方法代碼示例

本文整理匯總了PHP中pocketmine\level\generator\Generator::getFastNoise3D方法的典型用法代碼示例。如果您正苦於以下問題:PHP Generator::getFastNoise3D方法的具體用法?PHP Generator::getFastNoise3D怎麽用?PHP Generator::getFastNoise3D使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pocketmine\level\generator\Generator的用法示例。


在下文中一共展示了Generator::getFastNoise3D方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: generateChunk

 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);
     }
 }
開發者ID:ClearSkyTeam,項目名稱:ClearSky,代碼行數:34,代碼來源:Nether.php

示例2: generateChunk

 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);
     }
 }
開發者ID:Creeperface01,項目名稱:ImagicalMine,代碼行數:67,代碼來源:Normal.php

示例3: generateChunk

 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);
     }
 }
開發者ID:ken77731,項目名稱:PocketMine-0.13.0,代碼行數:58,代碼來源:Normal__64bit.php


注:本文中的pocketmine\level\generator\Generator::getFastNoise3D方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。