PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
generate-level-sound-ids.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol\tools\generate_entity_ids;
16
17use function array_flip;
18use function count;
19use function dirname;
20use function fclose;
21use function file_get_contents;
22use function fopen;
23use function fwrite;
24use function is_array;
25use function json_decode;
26use function ksort;
27use function str_replace;
28use function strtoupper;
29
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");
33 exit(1);
34}
35
36$jsonRaw = file_get_contents($argv[1]);
37if($jsonRaw === false){
38 fwrite(STDERR, "Failed to read level sound event ID mapping file\n");
39 exit(1);
40}
41
42$list = json_decode($jsonRaw, true, flags: JSON_THROW_ON_ERROR);
43if(!is_array($list)){
44 fwrite(STDERR, "Failed to decode level sound event ID mapping file, expected a JSON object\n");
45 exit(1);
46}
47$list = array_flip($list);
48
49//TODO: these should probably be patched into the mapping mod
50const MISSING = [
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",
56 222 => "spawn.baby",
57];
58const ALIASES = [
59 "POWER_ON_SCULK_SENSOR" => [
60 "SCULK_SENSOR_POWER_ON"
61 ],
62 "POWER_OFF_SCULK_SENSOR" => [
63 "SCULK_SENSOR_POWER_OFF"
64 ],
65 "CAULDRON_DRIP_WATER_POINTED_DRIPSTONE" => [
66 "POINTED_DRIPSTONE_CAULDRON_DRIP_WATER"
67 ],
68 "CAULDRON_DRIP_LAVA_POINTED_DRIPSTONE" => [
69 "POINTED_DRIPSTONE_CAULDRON_DRIP_LAVA"
70 ],
71 "DRIP_WATER_POINTED_DRIPSTONE" => [
72 "POINTED_DRIPSTONE_DRIP_WATER"
73 ],
74 "DRIP_LAVA_POINTED_DRIPSTONE" => [
75 "POINTED_DRIPSTONE_DRIP_LAVA"
76 ],
77 "PICK_BERRIES_CAVE_VINES" => [
78 "CAVE_VINES_PICK_BERRIES"
79 ],
80 "TILT_DOWN_BIG_DRIPLEAF" => [
81 "BIG_DRIPLEAF_TILT_DOWN"
82 ],
83 "TILT_UP_BIG_DRIPLEAF" => [
84 "BIG_DRIPLEAF_TILT_UP"
85 ],
86 "MOB_PLAYER_HURT_DROWN" => [
87 "PLAYER_HURT_DROWN"
88 ],
89 "MOB_PLAYER_HURT_ON_FIRE" => [
90 "PLAYER_HURT_ON_FIRE"
91 ],
92 "MOB_PLAYER_HURT_FREEZE" => [
93 "PLAYER_HURT_FREEZE"
94 ],
95 "ITEM_SPYGLASS_USE" => [
96 "USE_SPYGLASS"
97 ],
98 "ITEM_SPYGLASS_STOP_USING" => [
99 "STOP_USING_SPYGLASS"
100 ],
101 "CHIME_AMETHYST_BLOCK" => [
102 "AMETHYST_BLOCK_CHIME"
103 ],
104 "BLOCK_SCULK_CATALYST_BLOOM" => [
105 "SCULK_CATALYST_BLOOM"
106 ],
107 "BLOCK_SCULK_SHRIEKER_SHRIEK" => [
108 "SCULK_SHRIEKER_SHRIEK"
109 ],
110 "NEARBY_CLOSE" => [
111 "WARDEN_NEARBY_CLOSE"
112 ],
113 "NEARBY_CLOSER" => [
114 "WARDEN_NEARBY_CLOSER"
115 ],
116 "NEARBY_CLOSEST" => [
117 "WARDEN_NEARBY_CLOSEST"
118 ],
119 "AGITATED" => [
120 "WARDEN_SLIGHTLY_ANGRY"
121 ]
122];
123
124foreach(MISSING as $id => $name){
125 if(!isset($list[$id])){
126 $list[$id] = $name;
127 }elseif($list[$id] !== $name){
128 echo "WARNING: Mismatch of expected name for ID $id: expected $name, got {$list[$id]}\n";
129 }
130}
131ksort($list, SORT_NUMERIC);
132
133$output = fopen(dirname(__DIR__) . "/src/types/LevelSoundEvent.php", "wb");
134if($output === false){
135 throw new \RuntimeException("Failed to open output file");
136}
137
138fwrite($output, <<<'CODE'
139<?php
140
141/*
142 * This file is part of BedrockProtocol.
143 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
144 *
145 * BedrockProtocol is free software: you can redistribute it and/or modify
146 * it under the terms of the GNU Lesser General Public License as published by
147 * the Free Software Foundation, either version 3 of the License, or
148 * (at your option) any later version.
149 */
150
151declare(strict_types=1);
152
153namespace pocketmine\network\mcpe\protocol\types;
154
159final class LevelSoundEvent{
160 private function __construct(){
161 //NOOP
162 }
163
164CODE);
165
166$prev = 0;
167foreach($list as $id => $name){
168 $constantName = strtoupper(str_replace(".", "_", $name));
169 if($id !== $prev + 1){
170 fwrite($output, "\n");
171 }
172 $prev = $id;
173 fwrite($output, "\tpublic const $constantName = $id;\n");
174}
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");
180 }
181}
182
183fwrite($output, "}\n");
184fclose($output);
185
186echo "Successfully regenerated LevelSoundEvent enum" . PHP_EOL;