13declare(strict_types=1);
 
   15namespace pocketmine\network\mcpe\protocol\tools\generate_entity_ids;
 
   21use 
function file_get_contents;
 
   25use 
function json_decode;
 
   27use 
function strtoupper;
 
   29if(count($argv) !== 2){
 
   30    fwrite(STDERR, 
"Required arguments: path to entity ID mapping file\n");
 
   31    fwrite(STDERR, 
"Hint: Input file is a JSON file like entity_id_map.json in pmmp/BedrockData\n");
 
   35$jsonRaw = file_get_contents($argv[1]);
 
   36if($jsonRaw === 
false){
 
   37    fwrite(STDERR, 
"Failed to read entity ID mapping file\n");
 
   41$list = json_decode($jsonRaw, 
true, flags: JSON_THROW_ON_ERROR);
 
   43    fwrite(STDERR, 
"Failed to decode entity ID mapping file, expected a JSON object\n");
 
   46ksort($list, SORT_STRING);
 
   48$output = fopen(dirname(__DIR__) . 
"/src/types/entity/EntityIds.php", 
"wb");
 
   50    throw new \RuntimeException(
"Failed to open output file");
 
   53fwrite($output, <<<
'CODE' 
   66declare(strict_types=1);
 
   68namespace pocketmine\network\mcpe\protocol\types\entity;
 
   76    private function __construct(){
 
   83foreach($list as $stringId => $legacyId){
 
   84    $constantName = strtoupper(explode(
":", $stringId, 2)[1]);
 
   85    fwrite($output, 
"\tpublic const $constantName = \"$stringId\";\n");
 
   88fwrite($output, 
"}\n");
 
   91echo 
"Successfully regenerated EntityIds" . PHP_EOL;