This is a modified version of the freely published version in the paper by
Stefan Gustavson at
http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
public function generateChunk($chunkX, $chunkZ) { $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed()); $hills = []; $base = []; $incline = []; for ($z = 0; $z < 16; ++$z) { for ($x = 0; $x < 16; ++$x) { $i = ($z << 4) + $x; $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true); $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true); if ($base[$i] < 0) { $base[$i] *= 0.5; } } } $chunk = $this->level->getChunk($chunkX, $chunkZ); for ($z = 0; $z < 16; ++$z) { for ($x = 0; $x < 16; ++$x) { $i = ($z << 4) + $x; $height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 7; $height = (int) $height; for ($y = 0; $y < 128; ++$y) { $block = $this->pickBlock($x, $y, $z, $height); $chunk->setBlock($x, $y, $z, ...$block); } } } }
public function generateChunk($chunkX, $chunkZ) { $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed()); $hills = []; $base = []; for ($z = 0; $z < 16; ++$z) { for ($x = 0; $x < 16; ++$x) { $i = ($z << 4) + $x; $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true); $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true); if ($base[$i] < 0) { $base[$i] *= 0.5; } } } $chunk = $this->level->getChunk($chunkX, $chunkZ); for ($z = 0; $z < 16; ++$z) { for ($x = 0; $x < 16; ++$x) { $i = ($z << 4) + $x; $height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 7; $height = (int) $height; for ($y = 0; $y < 128; ++$y) { $diff = $height - $y; if ($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)) { $chunk->setBlockId($x, $y, $z, Block::BEDROCK); } elseif ($diff > 2) { $chunk->setBlockId($x, $y, $z, Block::STONE); } elseif ($diff > 0) { $chunk->setBlockId($x, $y, $z, Block::DIRT); } elseif ($y <= $this->waterHeight) { if ($this->waterHeight - $y <= 1 and $diff === 0) { $chunk->setBlockId($x, $y, $z, Block::SAND); } elseif ($diff === 0) { $chunk->setBlockId($x, $y, $z, Block::DIRT); } else { $chunk->setBlockId($x, $y, $z, Block::STILL_WATER); } } elseif ($diff === 0) { $chunk->setBlockId($x, $y, $z, Block::GRASS); } } } } }
public function getRainfall($x, $z) { return ($this->rainfall->noise2D($x, $z, \true) + 1) / 2; }