13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol\tools\generate_entity_ids;
17use
function array_flip;
21use
function file_get_contents;
25use
function json_decode;
27use
function str_replace;
28use
function strtoupper;
30if(count($argv) !== 2){
31 fwrite(STDERR,
"Required arguments: path to level sound event ID mapping file\n");
32 fwrite(STDERR,
"Hint: Input file is a JSON file like level_sound_id_map.json in pmmp/BedrockData\n");
36$jsonRaw = file_get_contents($argv[1]);
37if($jsonRaw ===
false){
38 fwrite(STDERR,
"Failed to read level sound event ID mapping file\n");
42$list = json_decode($jsonRaw,
true, flags: JSON_THROW_ON_ERROR);
44 fwrite(STDERR,
"Failed to decode level sound event ID mapping file, expected a JSON object\n");
47$list = array_flip($list);
51 151 =>
"imitate.endermite",
52 195 =>
"lt.reaction.glow_stick",
53 196 =>
"lt.reaction.glow_stick_2",
54 197 =>
"lt.reaction.luminol",
55 198 =>
"lt.reaction.salt",
59 "POWER_ON_SCULK_SENSOR" => [
60 "SCULK_SENSOR_POWER_ON"
62 "POWER_OFF_SCULK_SENSOR" => [
63 "SCULK_SENSOR_POWER_OFF"
65 "CAULDRON_DRIP_WATER_POINTED_DRIPSTONE" => [
66 "POINTED_DRIPSTONE_CAULDRON_DRIP_WATER"
68 "CAULDRON_DRIP_LAVA_POINTED_DRIPSTONE" => [
69 "POINTED_DRIPSTONE_CAULDRON_DRIP_LAVA"
71 "DRIP_WATER_POINTED_DRIPSTONE" => [
72 "POINTED_DRIPSTONE_DRIP_WATER"
74 "DRIP_LAVA_POINTED_DRIPSTONE" => [
75 "POINTED_DRIPSTONE_DRIP_LAVA"
77 "PICK_BERRIES_CAVE_VINES" => [
78 "CAVE_VINES_PICK_BERRIES"
80 "TILT_DOWN_BIG_DRIPLEAF" => [
81 "BIG_DRIPLEAF_TILT_DOWN"
83 "TILT_UP_BIG_DRIPLEAF" => [
84 "BIG_DRIPLEAF_TILT_UP"
86 "MOB_PLAYER_HURT_DROWN" => [
89 "MOB_PLAYER_HURT_ON_FIRE" => [
92 "MOB_PLAYER_HURT_FREEZE" => [
95 "ITEM_SPYGLASS_USE" => [
98 "ITEM_SPYGLASS_STOP_USING" => [
101 "CHIME_AMETHYST_BLOCK" => [
102 "AMETHYST_BLOCK_CHIME"
104 "BLOCK_SCULK_CATALYST_BLOOM" => [
105 "SCULK_CATALYST_BLOOM"
107 "BLOCK_SCULK_SHRIEKER_SHRIEK" => [
108 "SCULK_SHRIEKER_SHRIEK"
111 "WARDEN_NEARBY_CLOSE"
114 "WARDEN_NEARBY_CLOSER"
116 "NEARBY_CLOSEST" => [
117 "WARDEN_NEARBY_CLOSEST"
120 "WARDEN_SLIGHTLY_ANGRY"
124foreach(MISSING as $id => $name){
125 if(!isset($list[$id])){
127 }elseif($list[$id] !== $name){
128 echo
"WARNING: Mismatch of expected name for ID $id: expected $name, got {$list[$id]}\n";
131ksort($list, SORT_NUMERIC);
133$output = fopen(dirname(__DIR__) .
"/src/types/LevelSoundEvent.php",
"wb");
134if($output ===
false){
135 throw new \RuntimeException(
"Failed to open output file");
138fwrite($output, <<<
'CODE'
151declare(strict_types=1);
153namespace pocketmine\network\mcpe\protocol\types;
159final class LevelSoundEvent{
160 private function __construct(){
167foreach($list as $id => $name){
168 $constantName = strtoupper(str_replace(
".",
"_", $name));
169 if($id !== $prev + 1){
170 fwrite($output,
"\n");
173 fwrite($output,
"\tpublic const $constantName = $id;\n");
175fwrite($output,
"\n");
176fwrite($output,
"\t//The following aliases are kept for backwards compatibility only\n");
177foreach(ALIASES as $origin => $aliases){
178 foreach($aliases as $alias){
179 fwrite($output,
"\tpublic const $alias = self::$origin;\n");
183fwrite($output,
"}\n");
186echo
"Successfully regenerated LevelSoundEvent enum" . PHP_EOL;