From 6dd8685db3b166b3b0be311f17ce07a566bde0e6 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Mon, 20 Mar 2023 21:29:53 +0300 Subject: [PATCH] new HellGenerator downgraded from pm 0.11 plugin --- src/API/LevelAPI.php | 3 + src/world/generator/HellGenerator.php | 141 ++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 src/world/generator/HellGenerator.php diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 7e3d18d3..00d30bd0 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -143,6 +143,9 @@ class LevelAPI{ $generator = new TemporalGenerator(); ConsoleAPI::warn("You should not use OLD world type."); break; + case "HELL": + $generator = new HellGenerator(); + break; default: $generator = new NormalGenerator($options); break; diff --git a/src/world/generator/HellGenerator.php b/src/world/generator/HellGenerator.php new file mode 100644 index 00000000..f6d2dd64 --- /dev/null +++ b/src/world/generator/HellGenerator.php @@ -0,0 +1,141 @@ +level = $level; + $this->random = $random; + $this->random->setSeed($this->level->getSeed()); + $this->noiseBase = new NoiseGeneratorSimplex($this->random, 4, 1 / 4, 1 / 64); + + /*$ores = new Ore(); + $ores->setOreTypes([ + new OreType(new CoalOre(), 20, 16, 0, 128), + new OreType(New IronOre(), 20, 8, 0, 64), + new OreType(new RedstoneOre(), 8, 7, 0, 16), + new OreType(new LapisOre(), 1, 6, 0, 32), + new OreType(new GoldOre(), 2, 8, 0, 32), + new OreType(new DiamondOre(), 1, 7, 0, 16), + new OreType(new Dirt(), 20, 32, 0, 128), + new OreType(new Gravel(), 10, 16, 0, 128) + ]); + $this->populators[] = $ores;*/ + } + + public function generateChunk($chunkX, $chunkZ){ + $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); + + $noise = ExperimentalGenerator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16); + + 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){ + $lightChunk = ""; + for($y = $startY; $y < $endY; ++$y){ + if($y === 0 or $y === 127){//Bedrock + $lightChunk .= "\x00"; + $chunk .= "\x07"; + continue; + } + $noiseValue = (abs($this->emptyHeight - $y) / $this->emptyHeight) * $this->emptyAmplitude - $noise[$x][$z][$y]; + $noiseValue -= 1 - $this->density; + + if($noiseValue > 0){//Netherrack + $lightChunk .= "\x00"; + $chunk .= "\x57"; + }elseif($y <= $this->waterHeight){//Lava + $lightChunk .= "\xff"; + $chunk .= "\x0b"; + } + else{//Air + $lightChunk .= "\x00"; + $chunk .= "\x00"; + } + } + $chunk .= str_repeat(chr(BIOME_HELL), 16); //biome + $chunk .= $lightChunk; //blocklight + $chunk .= str_repeat("\x00", 16); //skylight + $lightChunk = ""; + //$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //light + //$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //more light + } + } + $this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $chunk); + } + + foreach($this->generationPopulators as $populator){ + $populator->populate($this->level, $chunkX, $chunkZ, $this->random); + } + } + + public function populateChunk($chunkX, $chunkZ){ + $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); + foreach($this->populators as $populator){ + $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); + $populator->populate($this->level, $chunkX, $chunkZ, $this->random); + } + } + + public function getSpawn(){ + return new Vector3(127.5, 128, 127.5); + } + + public function populateLevel() + {} +} \ No newline at end of file