PocketMine-MP 5.37.1 git-cef37e7835c666594588f957a47b27d521c6a58e
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];
58
59foreach(MISSING as $id => $name){
60 if(!isset($list[$id])){
61 $list[$id] = $name;
62 }elseif($list[$id] !== $name){
63 echo "WARNING: Mismatch of expected name for ID $id: expected $name, got {$list[$id]}\n";
64 }
65}
66ksort($list, SORT_NUMERIC);
67
68$output = fopen(dirname(__DIR__) . "/src/types/LevelSoundEvent.php", "wb");
69if($output === false){
70 throw new \RuntimeException("Failed to open output file");
71}
72
73fwrite($output, <<<'CODE'
74<?php
75
76/*
77 * This file is part of BedrockProtocol.
78 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
79 *
80 * BedrockProtocol is free software: you can redistribute it and/or modify
81 * it under the terms of the GNU Lesser General Public License as published by
82 * the Free Software Foundation, either version 3 of the License, or
83 * (at your option) any later version.
84 */
85
86declare(strict_types=1);
87
88namespace pocketmine\network\mcpe\protocol\types;
89
94final class LevelSoundEvent{
95 private function __construct(){
96 //NOOP
97 }
98
99CODE);
100
101$prev = 0;
102foreach($list as $id => $name){
103 $constantName = strtoupper(str_replace(".", "_", $name));
104 if($id !== $prev + 1){
105 fwrite($output, "\n");
106 }
107 $prev = $id;
108 fwrite($output, "\tpublic const $constantName = $id;\n");
109}
110fwrite($output, "\n");
111
112fwrite($output, "}\n");
113fclose($output);
114
115echo "Successfully regenerated LevelSoundEvent enum" . PHP_EOL;