level = $level; $this->random = $random; $this->random->setSeed($this->level->getSeed()); $this->noiseBase = new NoiseGeneratorSimplex($this->random, 4); $this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 4); $this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4); $ores = new OrePopulator(); $ores->setOreTypes(array( new OreType(new CoalOreBlock(), 20, 16, 0, 128), new OreType(New IronOreBlock(), 20, 8, 0, 64), new OreType(new RedstoneOreBlock(), 8, 7, 0, 16), new OreType(new LapisOreBlock(), 1, 6, 0, 32), new OreType(new GoldOreBlock(), 2, 8, 0, 32), new OreType(new DiamondOreBlock(), 1, 7, 0, 16), new OreType(new DirtBlock(), 20, 32, 0, 128), new OreType(new GravelBlock(), 10, 16, 0, 128), )); $this->populators[] = $ores; } public function generateChunk($chunkX, $chunkZ){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); for($chunkY = 0; $chunkY < 8; ++$chunkY){ $chunk = ""; $startY = $chunkY << 4; $endY = $startY + 16; for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ $noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.6, 32, true) * 2; $noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.35, 64, true) * 15; $noiseBase = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 1/5, 16, true) * 3; $height = (int) ($this->worldHeight + $noise1 + $noise2 + $noiseBase); for($y = $startY; $y < $endY; ++$y){ $diff = $height - $y; if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){ $chunk .= "\x07"; //bedrock }elseif($diff > 3){ $chunk .= "\x01"; //stone }elseif($diff > 0){ $chunk .= "\x03"; //dirt }elseif($y <= $this->waterHeight){ if($y === $this->waterHeight and $diff === 0){ $chunk .= "\x0c"; //sand }else{ $chunk .= "\x09"; //still_water } }elseif($diff === 0){ $chunk .= "\x02"; //grass }else{ $chunk .= "\x00"; } } $chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; } } $this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $chunk); } } public function populateChunk($chunkX, $chunkZ){ foreach($this->populators as $populator){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } $this->level->level->setPopulated($chunkX, $chunkZ); } public function populateLevel(){ } public function getSpawn(){ return $this->level->getSafeSpawn(new Vector3(127.5, 128, 127.5)); } }