diff --git a/build/generate-biome-ids.php b/build/generate-biome-ids.php new file mode 100644 index 000000000..f36591fe4 --- /dev/null +++ b/build/generate-biome-ids.php @@ -0,0 +1,133 @@ + $map + */ +function generate(array $map, string $outputFile) : void{ + $file = safe_fopen($outputFile, 'wb'); + fwrite($file, HEADER); + fwrite($file, <<<'CLASSHEADER' +namespace pocketmine\data\bedrock; + +final class BiomeIds{ + + private function __construct(){ + //NOOP + } + + +CLASSHEADER +); + $list = $map; + asort($list, SORT_NUMERIC); + $lastId = -1; + foreach(Utils::stringifyKeys($list) as $name => $id){ + if($name === ""){ + continue; + } + if($id !== $lastId + 1){ + fwrite($file, "\n"); + } + $lastId = $id; + fwrite($file, "\tpublic const " . make_const_name($name) . ' = ' . $id . ';' . "\n"); + } + fwrite($file, "}\n"); + fclose($file); +} + +$ids = json_decode(Filesystem::fileGetContents(BedrockDataFiles::BIOME_ID_MAP_JSON), true); +if(!is_array($ids)){ + throw new \RuntimeException("Invalid biome ID map, expected array for root JSON object"); +} +$cleanedIds = []; +foreach($ids as $name => $id){ + if(!is_string($name) || !is_int($id)){ + throw new \RuntimeException("Invalid biome ID map, expected string => int map"); + } + $cleanedIds[$name] = $id; +} +generate($cleanedIds, dirname(__DIR__) . '/src/data/bedrock/BiomeIds.php'); + +echo "Done. Don't forget to run CS fixup after generating code.\n";