mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
endgenerator? uwu
This commit is contained in:
parent
2518ab67cb
commit
bfb75990ba
3 changed files with 131 additions and 0 deletions
|
|
@ -147,6 +147,9 @@ class LevelAPI{
|
|||
case "NETHER":
|
||||
$generator = new HellGenerator();
|
||||
break;
|
||||
case "END":
|
||||
$generator = new EndGenerator();
|
||||
break;
|
||||
default:
|
||||
$generator = new NormalGenerator($options);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ require_once(FILE_PATH . "/src/plugin/phar/IClassLoader.php");
|
|||
require_once(FILE_PATH . "/src/plugin/phar/PharUtils.php");
|
||||
|
||||
require_once(FILE_PATH . "/src/world/generator/LevelGenerator.php");
|
||||
require_once(FILE_PATH . "/src/world/generator/NewLevelGenerator.php");
|
||||
require_once(FILE_PATH . "/src/world/generator/biome/Biome.php");
|
||||
require_once(FILE_PATH . "/src/world/generator/biome/BiomeSelector.php");
|
||||
require_once(FILE_PATH . "/src/world/generator/biome/biomes/BiomeWithGrass.php");
|
||||
|
|
|
|||
127
src/world/generator/EndGenerator.php
Normal file
127
src/world/generator/EndGenerator.php
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
class EndGenerator implements NewLevelGenerator{
|
||||
|
||||
/** @var Populator[] */
|
||||
private $populators = [];
|
||||
/** @var Level */
|
||||
private $level;
|
||||
/** @var Random */
|
||||
private $random;
|
||||
private $density = 0.6;
|
||||
|
||||
/** @var Populator[] */
|
||||
private $generationPopulators = [];
|
||||
/** @var NoiseGeneratorSimplex */
|
||||
private $noiseBase;
|
||||
|
||||
private static $GAUSSIAN_KERNEL = null;
|
||||
private static $SMOOTH_SIZE = 2;
|
||||
|
||||
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(){
|
||||
return "end";
|
||||
}
|
||||
|
||||
public function getSettings(){
|
||||
return [];
|
||||
}
|
||||
|
||||
public function init(Level $level, Random $random){
|
||||
$this->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){
|
||||
$noiseValue = $noise[$x][$z][$y];
|
||||
$noiseValue -= 1 - $this->density;
|
||||
|
||||
if($noiseValue > 0){
|
||||
$lightChunk .= "\x00";
|
||||
$chunk .= "\x79";
|
||||
}
|
||||
else{//Air
|
||||
$lightChunk .= "\x00";
|
||||
$chunk .= "\x00";
|
||||
}
|
||||
}
|
||||
$chunk .= str_repeat("\x00", 16); //meta
|
||||
$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);
|
||||
}
|
||||
$this->level->level->setBiomeIdArrayForChunk($chunkX, $chunkZ, str_repeat(chr(BIOME_END), 256));
|
||||
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()
|
||||
{}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue