This repository has been archived by the owner on Mar 16, 2020. It is now read-only.
/
Ender.php
156 lines (127 loc) · 4.57 KB
/
Ender.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/*
*
* _____ _ _____
* / ____| (_) | __ \
*| | __ ___ _ __ _ ___ _ _ ___| |__) | __ ___
*| | |_ |/ _ \ '_ \| / __| | | / __| ___/ '__/ _ \
*| |__| | __/ | | | \__ \ |_| \__ \ | | | | (_) |
* \_____|\___|_| |_|_|___/\__, |___/_| |_| \___/
* __/ |
* |___/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author GenisysPro
* @link https://github.com/GenisysPro/GenisysPro
*
*
*/
declare(strict_types = 1);
namespace CortexPE\level\generator\ender;
use CortexPE\level\generator\{
biome\Biome, ender\populator\EnderPilar
};
use pocketmine\block\Block;
use pocketmine\level\{
ChunkManager, generator\Generator, generator\noise\Simplex, generator\populator\Populator
};
use pocketmine\math\Vector3 as Vector3;
use pocketmine\utils\Random;
class Ender extends Generator {
private static $GAUSSIAN_KERNEL = null;
private static $SMOOTH_SIZE = 1;
/** @var ChunkManager */
protected $level;
/** @var Random */
protected $random;
/** @var Populator[] */
private $populators = [];
private $waterHeight = 0;
private $emptyHeight = 24;
private $emptyAmplitude = 2;
private $density = 0;
/** @var Populator[] */
private $generationPopulators = [];
/** @var Simplex */
private $noiseBase;
public function __construct(array $options = []){
if(self::$GAUSSIAN_KERNEL === null){
self::generateKernel();
}
}
private static function generateKernel(){
self::$GAUSSIAN_KERNEL = [];
$bellSize = 1 / self::$SMOOTH_SIZE;
$bellHeight = 2 * self::$SMOOTH_SIZE;
for($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx){
self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE] = [];
for($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz){
$bx = $bellSize * $sx;
$bz = $bellSize * $sz;
self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE] = $bellHeight * exp(-($bx * $bx + $bz * $bz) / 2);
}
}
}
public function getName(): string{
return "Ender";
}
public function getWaterHeight(): int{
return $this->waterHeight;
}
public function getSettings(): array{
return [];
}
public function init(ChunkManager $level, Random $random): void{
$this->level = $level;
$this->random = $random;
$this->random->setSeed($this->level->getSeed());
$this->noiseBase = new Simplex($this->random, 4, 1 / 4, 1 / 64);
$this->random->setSeed($this->level->getSeed());
$pilar = new EnderPilar();
$pilar->setBaseAmount(0);
$pilar->setRandomAmount(0);
$this->populators[] = $pilar;
}
public function generateChunk(int $chunkX, int $chunkZ): void{
$this->random->setSeed(0xa6fe78dc ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
$noise = $this->noiseBase->getFastNoise3D(16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
$chunk = $this->level->getChunk($chunkX, $chunkZ);
for($x = 0; $x < 16; ++$x){
for($z = 0; $z < 16; ++$z){
$biome = Biome::getBiome(Biome::END);
$biome->setGroundCover([
Block::get(Block::OBSIDIAN, 0),
]);
$chunk->setBiomeId($x, $z, $biome->getId());
for($y = 0; $y < 128; ++$y){
$noiseValue = (abs($this->emptyHeight - $y) / $this->emptyHeight) * $this->emptyAmplitude - $noise[$x][$z][$y];
$noiseValue -= 1 - $this->density;
$distance = new Vector3(0, 64, 0);
$distance = $distance->distance(new Vector3($chunkX * 16 + $x, ($y / 1.3), $chunkZ * 16 + $z));
if($noiseValue < 0 && $distance < 100 or $noiseValue < -0.2 && $distance > 400){
$chunk->setBlockId($x, $y, $z, Block::END_STONE);
}
}
}
}
foreach($this->generationPopulators as $populator){
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
}
}
public function populateChunk(int $chunkX, int $chunkZ): void{
$this->random->setSeed(0xa6fe78dc ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
foreach($this->populators as $populator){
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
}
$chunk = $this->level->getChunk($chunkX, $chunkZ);
$biome = Biome::getBiome($chunk->getBiomeId(7, 7));
$biome->populateChunk($this->level, $chunkX, $chunkZ, $this->random);
}
public function getSpawn(): Vector3{
return new Vector3(127.5, 128, 127.5);
}
}