0
0
mirror of https://github.com/pmmp/BedrockProtocol.git synced 2025-02-23 13:56:14 +00:00
BedrockProtocol/tools/generate-entity-ids.php
2022-06-21 20:12:08 +01:00

90 lines
2.5 KiB
PHP

<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\tools\generate_entity_ids;
if(count($argv) !== 2){
fwrite(STDERR, "Required arguments: path to entity ID mapping file\n");
exit(1);
}
$jsonRaw = file_get_contents($argv[1]);
if($jsonRaw === false){
fwrite(STDERR, "Failed to read entity ID mapping file\n");
exit(1);
}
$list = json_decode($jsonRaw, true, flags: JSON_THROW_ON_ERROR);
if(!is_array($list)){
fwrite(STDERR, "Failed to decode entity ID mapping file, expected a JSON object\n");
exit(1);
}
ksort($list, SORT_STRING);
$output = fopen(dirname(__DIR__) . "/src/types/entity/EntityIds.php", "wb");
if($output === false){
throw new \RuntimeException("Failed to open output file");
}
fwrite($output, <<<'CODE'
<?php
/*
* This file is part of BedrockProtocol.
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
*
* BedrockProtocol is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types\entity;
/**
* This file is directly generated from the entity definitions provided by the client. The entities listed in this file
* are expected to always have the same IDs.
*
* This file is automatically generated; do NOT edit it by hand.
*/
final class EntityIds{
private function __construct(){
//NOOP
}
CODE);
foreach($list as $stringId => $legacyId){
$constantName = strtoupper(explode(":", $stringId, 2)[1]);
fwrite($output, "\tpublic const $constantName = \"$stringId\";\n");
}
fwrite($output, "}\n");
fclose($output);
echo "Successfully regenerated EntityIds" . PHP_EOL;