diff --git a/src/world/generator/GeneratorManager.php b/src/world/generator/GeneratorManager.php index 180450b72..291ea91de 100644 --- a/src/world/generator/GeneratorManager.php +++ b/src/world/generator/GeneratorManager.php @@ -52,9 +52,9 @@ final class GeneratorManager{ } }); $this->addGenerator(Normal::class, "normal", fn() => null); - $this->addGenerator(Normal::class, "default", fn() => null); - $this->addGenerator(Nether::class, "hell", fn() => null); + $this->addAlias("normal", "default"); $this->addGenerator(Nether::class, "nether", fn() => null); + $this->addAlias("nether", "hell"); } /** @@ -80,6 +80,22 @@ final class GeneratorManager{ $this->list[$name] = new GeneratorManagerEntry($class, $presetValidator); } + /** + * Aliases an already-registered generator name to another name. Useful if you want to map a generator name to an + * existing generator without having to replicate the parameters. + */ + public function addAlias(string $name, string $alias) : void{ + $name = strtolower($name); + $alias = strtolower($alias); + if(!isset($this->list[$name])){ + throw new \InvalidArgumentException("Alias \"$name\" is not assigned"); + } + if(isset($this->list[$alias])){ + throw new \InvalidArgumentException("Alias \"$alias\" is already assigned"); + } + $this->list[$alias] = $this->list[$name]; + } + /** * Returns a list of names for registered generators. *