$structure * @phpstan-param array|true> $extraOptions */ public function __construct( private array $structure, private int $biomeId, private array $extraOptions = [] ){} /** * @return int[] * @phpstan-return array */ public function getStructure() : array{ return $this->structure; } public function getBiomeId() : int{ return $this->biomeId; } /** * @return mixed[] * @phpstan-return array|true> */ public function getExtraOptions() : array{ return $this->extraOptions; } /** * @return int[] * @phpstan-return array * * @throws InvalidGeneratorOptionsException */ public static function parseLayers(string $layers) : array{ $result = []; $split = array_map('\trim', explode(',', $layers)); $y = 0; $itemParser = LegacyStringToItemParser::getInstance(); foreach($split as $line){ if(preg_match('#^(?:(\d+)[x|*])?(.+)$#', $line, $matches) !== 1){ throw new InvalidGeneratorOptionsException("Invalid preset layer \"$line\""); } $cnt = $matches[1] !== "" ? (int) $matches[1] : 1; try{ $b = $itemParser->parse($matches[2])->getBlock(); }catch(LegacyStringToItemParserException $e){ throw new InvalidGeneratorOptionsException("Invalid preset layer \"$line\": " . $e->getMessage(), 0, $e); } for($cY = $y, $y += $cnt; $cY < $y; ++$cY){ $result[$cY] = $b->getStateId(); } } return $result; } /** * @throws InvalidGeneratorOptionsException */ public static function parsePreset(string $presetString) : self{ $preset = explode(";", $presetString); $blocks = $preset[1] ?? ""; $biomeId = (int) ($preset[2] ?? BiomeIds::PLAINS); $optionsString = $preset[3] ?? ""; $structure = self::parseLayers($blocks); $options = []; //TODO: more error checking preg_match_all('#(([0-9a-z_]{1,})\(?([0-9a-z_ =:]{0,})\)?),?#', $optionsString, $matches); foreach($matches[2] as $i => $option){ $params = true; if($matches[3][$i] !== ""){ $params = []; $p = explode(" ", $matches[3][$i]); foreach($p as $k){ $k = explode("=", $k); if(isset($k[1])){ $params[$k[0]] = $k[1]; } } } $options[(string) $option] = $params; } return new self($structure, $biomeId, $options); } }