Clean up generator preset handling

This commit is contained in:
Dylan K. Taylor 2021-04-13 20:19:53 +01:00
parent bfa1b4384b
commit 6ce15854af
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
8 changed files with 23 additions and 51 deletions

View File

@ -105,7 +105,7 @@ class FormatConverter{
$this->logger->info("Found previous conversion attempt, deleting...");
Filesystem::recursiveUnlink($convertedOutput);
}
$this->newProvider::generate($convertedOutput, $data->getName(), $data->getSeed(), GeneratorManager::getInstance()->getGenerator($data->getGenerator()), $data->getGeneratorOptions());
$this->newProvider::generate($convertedOutput, $data->getName(), $data->getSeed(), GeneratorManager::getInstance()->getGenerator($data->getGenerator()), ["preset" => $data->getGeneratorOptions()]);
/**
* @see WritableWorldProvider::__construct()

View File

@ -39,11 +39,7 @@ interface WorldData{
*/
public function getGenerator() : string;
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
public function getGeneratorOptions() : array;
public function getGeneratorOptions() : string;
public function getSeed() : int;

View File

@ -116,8 +116,8 @@ abstract class BaseNbtWorldData implements WorldData{
return $this->compoundTag->getString("generatorName", "DEFAULT");
}
public function getGeneratorOptions() : array{
return ["preset" => $this->compoundTag->getString("generatorOptions", "")];
public function getGeneratorOptions() : string{
return $this->compoundTag->getString("generatorOptions", "");
}
public function getSeed() : int{

View File

@ -48,25 +48,18 @@ class Flat extends Generator{
private $structure;
/** @var int */
private $biome;
/** @var string */
private $preset;
/**
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
*
* @var mixed[]
* @phpstan-var array<string, mixed>
*/
private array $options = [];
/**
* @throws InvalidGeneratorOptionsException
*/
public function __construct(int $seed, array $options = []){
parent::__construct($seed, $options);
if(isset($this->options["preset"]) and $this->options["preset"] != ""){
$this->preset = $this->options["preset"];
}else{
$this->preset = "2;bedrock,2xdirt,grass;1;";
//$this->preset = "2;bedrock,59xstone,3xdirt,grass;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=45)";
}
public function __construct(int $seed, string $preset){
parent::__construct($seed, $preset !== "" ? $preset : "2;bedrock,2xdirt,grass;1;");
$this->parsePreset();
if(isset($this->options["decoration"])){

View File

@ -50,22 +50,15 @@ abstract class Generator{
/** @var int */
protected $seed;
/**
* @var mixed[]
* @phpstan-var array<string, mixed>
*/
protected $options;
protected string $preset;
/** @var Random */
protected $random;
/**
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
*/
public function __construct(int $seed, array $options = []){
public function __construct(int $seed, string $preset){
$this->seed = $seed;
$this->options = $options;
$this->preset = $preset;
$this->random = new Random($seed);
}

View File

@ -25,8 +25,6 @@ namespace pocketmine\world\generator;
use pocketmine\scheduler\AsyncTask;
use pocketmine\world\World;
use function igbinary_serialize;
use function igbinary_unserialize;
class GeneratorRegisterTask extends AsyncTask{
@ -47,13 +45,11 @@ class GeneratorRegisterTask extends AsyncTask{
public $worldMaxY;
/**
* @param mixed[] $generatorSettings
* @phpstan-param class-string<Generator> $generatorClass
* @phpstan-param array<string, mixed> $generatorSettings
*/
public function __construct(World $world, string $generatorClass, array $generatorSettings = []){
public function __construct(World $world, string $generatorClass, string $generatorSettings){
$this->generatorClass = $generatorClass;
$this->settings = igbinary_serialize($generatorSettings);
$this->settings = $generatorSettings;
$this->seed = $world->getSeed();
$this->worldId = $world->getId();
$this->worldMinY = $world->getMinY();
@ -65,7 +61,7 @@ class GeneratorRegisterTask extends AsyncTask{
* @var Generator $generator
* @see Generator::__construct()
*/
$generator = new $this->generatorClass($this->seed, igbinary_unserialize($this->settings));
$generator = new $this->generatorClass($this->seed, $this->settings);
ThreadLocalGeneratorContext::register(new ThreadLocalGeneratorContext($generator, $this->worldMinY, $this->worldMaxY), $this->worldId);
}
}

View File

@ -54,13 +54,10 @@ class Nether extends Generator{
private $noiseBase;
/**
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
*
* @throws InvalidGeneratorOptionsException
*/
public function __construct(int $seed, array $options = []){
parent::__construct($seed, $options);
public function __construct(int $seed, string $preset){
parent::__construct($seed, $preset);
$this->noiseBase = new Simplex($this->random, 4, 1 / 4, 1 / 64);
$this->random->setSeed($this->seed);

View File

@ -58,13 +58,10 @@ class Normal extends Generator{
private $gaussian;
/**
* @param mixed[] $options
* @phpstan-param array<string, mixed> $options
*
* @throws InvalidGeneratorOptionsException
*/
public function __construct(int $seed, array $options = []){
parent::__construct($seed, $options);
public function __construct(int $seed, string $preset){
parent::__construct($seed, $preset);
$this->gaussian = new Gaussian(2);