-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
100 lines (85 loc) · 2.77 KB
/
index.php
File metadata and controls
100 lines (85 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
* ______ _ __ ___ ____
* | ___ \ | | \/ / __ \
* | |_/ /___ __| | . . | / \/
* | // _ \/ _` | |\/| | |
* | |\ \ __/ (_| | | | | \__/\
* \_| \_\___|\__,_\_| |_/\____/
*
* Copyright (C) RedMC Network, Inc - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the MIT license, which unfortunately won't be
* written for another century.
*
* Written by xerenahmed <eren@redmc.me>, 2023
*
* @author RedMC Team
* @link https://www.redmc.me/
*/
declare(strict_types=1);
define('pocketmine\BEDROCK_DATA_PATH', './vendor/pocketmine/bedrock-data/');
require_once 'vendor/autoload.php';
use pocketmine\data\bedrock\LegacyItemIdToStringIdMap;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
use pocketmine\network\mcpe\convert\ItemTranslator;
$tr_names = json_decode(file_get_contents('./resources/item-names-TR.json'), true);
$en_names = json_decode(file_get_contents('./resources/item-names-EN.json'), true);
$allItems = ItemFactory::getInstance()->getAllRegistered();
$output = [];
foreach ($allItems as $item) {
$output[] = itemToData($item);
}
usort($output, function ($a, $b) {
return $a['network']['id'] <=> $b['network']['id'];
});
file_put_contents('./generated.json', json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
function itemToData(Item $item): array {
$legacyId = $item->getId();
$legacyMeta = $item->getMeta();
$map = LegacyItemIdToStringIdMap::getInstance();
$baseIdentifier = $map->legacyToString($legacyId, $legacyMeta);
$dictionary = GlobalItemTypeDictionary::getInstance()->getDictionary();
[$netId, $netMeta] = ItemTranslator::getInstance()->toNetworkId($legacyId, $legacyMeta);
$dictionaryIdentifier = $dictionary->fromIntId($netId);
return [
'identifier' => [
'base' => $baseIdentifier,
'dictionary' => $dictionaryIdentifier
],
'legacy' => [
'id' => $legacyId,
'meta' => $legacyMeta,
],
'network' => [
'id' => $netId,
'meta' => $netMeta,
],
'name' => [
'pocketmine' => $item->getName(),
'en' => nameForLang('en', [$dictionaryIdentifier, $baseIdentifier], $netMeta),
'tr' => nameForLang('tr', [$dictionaryIdentifier, $baseIdentifier], $netMeta),
]
];
}
function nameForLang(string $lang, array $identifiers, int $meta): string {
global $tr_names, $en_names;
$table = match ($lang) {
'tr' => $tr_names,
'en' => $en_names,
default =>
throw new \InvalidArgumentException('Invalid language')
};
foreach ($identifiers as $identifier) {
$entry = array_filter($table, fn($entry) => $entry['id'] === $identifier && (
($entry['meta'] ?? 0) === $meta
));
if (count($entry) === 0) {
continue;
}
return array_values($entry)[0]['name'];
}
return 'Unknown';
}