PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
Nether.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\world\generator\hell;
25
38use function abs;
39
40class Nether extends Generator{
41
42 private int $waterHeight = 32;
43 private int $emptyHeight = 64;
44 private int $emptyAmplitude = 1;
45 private float $density = 0.5;
46
48 private array $populators = [];
50 private array $generationPopulators = [];
51 private Simplex $noiseBase;
52
56 public function __construct(int $seed, string $preset){
57 parent::__construct($seed, $preset);
58
59 $this->noiseBase = new Simplex($this->random, 4, 1 / 4, 1 / 64);
60 $this->random->setSeed($this->seed);
61
62 $ores = new Ore();
63 $ores->setOreTypes([
64 new OreType(VanillaBlocks::NETHER_QUARTZ_ORE(), VanillaBlocks::NETHERRACK(), 16, 14, 10, 117)
65 ]);
66 $this->populators[] = $ores;
67 }
68
69 public function generateChunk(ChunkManager $world, int $chunkX, int $chunkZ) : void{
70 $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->seed);
71
72 $noise = $this->noiseBase->getFastNoise3D(Chunk::EDGE_LENGTH, 128, Chunk::EDGE_LENGTH, 4, 8, 4, $chunkX * Chunk::EDGE_LENGTH, 0, $chunkZ * Chunk::EDGE_LENGTH);
73
74 //TODO: why don't we just create and set the chunk here directly?
75 $chunk = $world->getChunk($chunkX, $chunkZ) ?? throw new \InvalidArgumentException("Chunk $chunkX $chunkZ does not yet exist");
76
77 $bedrock = VanillaBlocks::BEDROCK()->getStateId();
78 $netherrack = VanillaBlocks::NETHERRACK()->getStateId();
79 $stillLava = VanillaBlocks::LAVA()->getStateId();
80
81 for($x = 0; $x < Chunk::EDGE_LENGTH; ++$x){
82 for($z = 0; $z < Chunk::EDGE_LENGTH; ++$z){
83 for($y = World::Y_MIN; $y < World::Y_MAX; $y++){
84 $chunk->setBiomeId($x, $y, $z, BiomeIds::HELL);
85 }
86
87 for($y = 0; $y < 128; ++$y){
88 if($y === 0 || $y === 127){
89 $chunk->setBlockStateId($x, $y, $z, $bedrock);
90 continue;
91 }
92 $noiseValue = (abs($this->emptyHeight - $y) / $this->emptyHeight) * $this->emptyAmplitude - $noise[$x][$z][$y];
93 $noiseValue -= 1 - $this->density;
94
95 if($noiseValue > 0){
96 $chunk->setBlockStateId($x, $y, $z, $netherrack);
97 }elseif($y <= $this->waterHeight){
98 $chunk->setBlockStateId($x, $y, $z, $stillLava);
99 }
100 }
101 }
102 }
103
104 foreach($this->generationPopulators as $populator){
105 $populator->populate($world, $chunkX, $chunkZ, $this->random);
106 }
107 }
108
109 public function populateChunk(ChunkManager $world, int $chunkX, int $chunkZ) : void{
110 $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->seed);
111 foreach($this->populators as $populator){
112 $populator->populate($world, $chunkX, $chunkZ, $this->random);
113 }
114
115 $chunk = $world->getChunk($chunkX, $chunkZ);
116 $biome = BiomeRegistry::getInstance()->getBiome($chunk->getBiomeId(7, 7, 7));
117 $biome->populateChunk($world, $chunkX, $chunkZ, $this->random);
118 }
119}
__construct(int $seed, string $preset)
Definition Nether.php:56