本文整理匯總了PHP中pocketmine\level\generator\Generator::getFastNoise2D方法的典型用法代碼示例。如果您正苦於以下問題:PHP Generator::getFastNoise2D方法的具體用法?PHP Generator::getFastNoise2D怎麽用?PHP Generator::getFastNoise2D使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\level\generator\Generator
的用法示例。
在下文中一共展示了Generator::getFastNoise2D方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generateChunk
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);
//.........這裏部分代碼省略.........