PocketMine-MP 5.32.2 git-1ebd7d3960d713d56f77f610fe0c15cdee201069
Loading...
Searching...
No Matches
ItemSerializerDeserializerRegistrar.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\data\bedrock\item;
25
29use pocketmine\block\tile\Banner as TileBanner;
30use pocketmine\block\utils\CopperOxidation;
31use pocketmine\block\utils\DyeColor;
51
53
54 public function __construct(
55 private ?ItemDeserializer $deserializer,
56 private ?ItemSerializer $serializer
57 ){
58 $this->register1to1BlockMappings();
59 $this->register1to1ItemMappings();
60 $this->register1to1BlockWithMetaMappings();
61 $this->register1to1ItemWithMetaMappings();
62 $this->register1ToNItemMappings();
63 $this->registerMiscBlockMappings();
64 $this->registerMiscItemMappings();
65 }
66
67 public function map1to1Item(string $id, Item $item) : void{
68 $this->deserializer?->map($id, fn() => clone $item);
69 $this->serializer?->map($item, fn() => new Data($id));
70 }
71
78 public function map1to1ItemWithMeta(string $id, Item $item, \Closure $deserializeMeta, \Closure $serializeMeta) : void{
79 $this->deserializer?->map($id, function(Data $data) use ($item, $deserializeMeta) : Item{
80 $result = clone $item;
81 $deserializeMeta($result, $data->getMeta());
82 return $result;
83 });
84 $this->serializer?->map($item, function(Item $item) use ($id, $serializeMeta) : Data{
86 $meta = $serializeMeta($item);
87 return new Data($id, $meta);
88 });
89 }
90
91 public function map1to1Block(string $id, Block $block) : void{
92 $this->deserializer?->mapBlock($id, fn() => $block);
93 $this->serializer?->mapBlock($block, fn() => new Data($id));
94 }
95
102 public function map1to1BlockWithMeta(string $id, Block $block, \Closure $deserializeMeta, \Closure $serializeMeta) : void{
103 $this->deserializer?->mapBlock($id, function(Data $data) use ($block, $deserializeMeta) : Block{
104 $result = clone $block;
105 $deserializeMeta($result, $data->getMeta());
106 return $result;
107 });
108 $this->serializer?->mapBlock($block, function(Block $block) use ($id, $serializeMeta) : Data{
109 $meta = $serializeMeta($block);
110 return new Data($id, $meta);
111 });
112 }
113
118 public function map1ToNItem(string $id, array $items) : void{
119 $this->deserializer?->map($id, function(Data $data) use ($items) : Item{
120 $result = $items[$data->getMeta()] ?? null;
121 if($result === null){
122 throw new ItemTypeDeserializeException("Unhandled meta value " . $data->getMeta() . " for item ID " . $data->getName());
123 }
124 return clone $result;
125 });
126 foreach($items as $meta => $item){
127 $this->serializer?->map($item, fn() => new Data($id, $meta));
128 }
129 }
130
136 private function register1to1BlockMappings() : void{
137 $this->map1to1Block(Ids::ACACIA_DOOR, Blocks::ACACIA_DOOR());
138 $this->map1to1Block(Ids::BIRCH_DOOR, Blocks::BIRCH_DOOR());
139 $this->map1to1Block(Ids::BREWING_STAND, Blocks::BREWING_STAND());
140 $this->map1to1Block(Ids::CAKE, Blocks::CAKE());
141 $this->map1to1Block(Ids::CAMPFIRE, Blocks::CAMPFIRE());
142 $this->map1to1Block(Ids::CAULDRON, Blocks::CAULDRON());
143 $this->map1to1Block(Ids::CHAIN, Blocks::CHAIN());
144 $this->map1to1Block(Ids::CHERRY_DOOR, Blocks::CHERRY_DOOR());
145 $this->map1to1Block(Ids::COMPARATOR, Blocks::REDSTONE_COMPARATOR());
146 $this->map1to1Block(Ids::CRIMSON_DOOR, Blocks::CRIMSON_DOOR());
147 $this->map1to1Block(Ids::DARK_OAK_DOOR, Blocks::DARK_OAK_DOOR());
148 $this->map1to1Block(Ids::FLOWER_POT, Blocks::FLOWER_POT());
149 $this->map1to1Block(Ids::FRAME, Blocks::ITEM_FRAME());
150 $this->map1to1Block(Ids::GLOW_FRAME, Blocks::GLOWING_ITEM_FRAME());
151 $this->map1to1Block(Ids::HOPPER, Blocks::HOPPER());
152 $this->map1to1Block(Ids::IRON_DOOR, Blocks::IRON_DOOR());
153 $this->map1to1Block(Ids::JUNGLE_DOOR, Blocks::JUNGLE_DOOR());
154 $this->map1to1Block(Ids::MANGROVE_DOOR, Blocks::MANGROVE_DOOR());
155 $this->map1to1Block(Ids::NETHER_WART, Blocks::NETHER_WART());
156 $this->map1to1Block(Ids::PALE_OAK_DOOR, Blocks::PALE_OAK_DOOR());
157 $this->map1to1Block(Ids::REPEATER, Blocks::REDSTONE_REPEATER());
158 $this->map1to1Block(Ids::SOUL_CAMPFIRE, Blocks::SOUL_CAMPFIRE());
159 $this->map1to1Block(Ids::SPRUCE_DOOR, Blocks::SPRUCE_DOOR());
160 $this->map1to1Block(Ids::SUGAR_CANE, Blocks::SUGARCANE());
161 $this->map1to1Block(Ids::WARPED_DOOR, Blocks::WARPED_DOOR());
162 $this->map1to1Block(Ids::WOODEN_DOOR, Blocks::OAK_DOOR());
163 }
164
168 private function register1to1ItemMappings() : void{
169 $this->map1to1Item(Ids::ACACIA_BOAT, Items::ACACIA_BOAT());
170 $this->map1to1Item(Ids::ACACIA_HANGING_SIGN, Items::ACACIA_HANGING_SIGN());
171 $this->map1to1Item(Ids::ACACIA_SIGN, Items::ACACIA_SIGN());
172 $this->map1to1Item(Ids::AMETHYST_SHARD, Items::AMETHYST_SHARD());
173 $this->map1to1Item(Ids::APPLE, Items::APPLE());
174 $this->map1to1Item(Ids::BAKED_POTATO, Items::BAKED_POTATO());
175 $this->map1to1Item(Ids::BEEF, Items::RAW_BEEF());
176 $this->map1to1Item(Ids::BEETROOT, Items::BEETROOT());
177 $this->map1to1Item(Ids::BEETROOT_SEEDS, Items::BEETROOT_SEEDS());
178 $this->map1to1Item(Ids::BEETROOT_SOUP, Items::BEETROOT_SOUP());
179 $this->map1to1Item(Ids::BIRCH_BOAT, Items::BIRCH_BOAT());
180 $this->map1to1Item(Ids::BIRCH_HANGING_SIGN, Items::BIRCH_HANGING_SIGN());
181 $this->map1to1Item(Ids::BIRCH_SIGN, Items::BIRCH_SIGN());
182 $this->map1to1Item(Ids::BLAZE_POWDER, Items::BLAZE_POWDER());
183 $this->map1to1Item(Ids::BLAZE_ROD, Items::BLAZE_ROD());
184 $this->map1to1Item(Ids::BLEACH, Items::BLEACH());
185 $this->map1to1Item(Ids::BONE, Items::BONE());
186 $this->map1to1Item(Ids::BONE_MEAL, Items::BONE_MEAL());
187 $this->map1to1Item(Ids::BOOK, Items::BOOK());
188 $this->map1to1Item(Ids::BOW, Items::BOW());
189 $this->map1to1Item(Ids::BOWL, Items::BOWL());
190 $this->map1to1Item(Ids::BREAD, Items::BREAD());
191 $this->map1to1Item(Ids::BRICK, Items::BRICK());
192 $this->map1to1Item(Ids::BUCKET, Items::BUCKET());
193 $this->map1to1Item(Ids::CARROT, Items::CARROT());
194 $this->map1to1Item(Ids::CHAINMAIL_BOOTS, Items::CHAINMAIL_BOOTS());
195 $this->map1to1Item(Ids::CHAINMAIL_CHESTPLATE, Items::CHAINMAIL_CHESTPLATE());
196 $this->map1to1Item(Ids::CHAINMAIL_HELMET, Items::CHAINMAIL_HELMET());
197 $this->map1to1Item(Ids::CHAINMAIL_LEGGINGS, Items::CHAINMAIL_LEGGINGS());
198 $this->map1to1Item(Ids::CHARCOAL, Items::CHARCOAL());
199 $this->map1to1Item(Ids::CHERRY_HANGING_SIGN, Items::CHERRY_HANGING_SIGN());
200 $this->map1to1Item(Ids::CHERRY_SIGN, Items::CHERRY_SIGN());
201 $this->map1to1Item(Ids::CHICKEN, Items::RAW_CHICKEN());
202 $this->map1to1Item(Ids::CHORUS_FRUIT, Items::CHORUS_FRUIT());
203 $this->map1to1Item(Ids::CLAY_BALL, Items::CLAY());
204 $this->map1to1Item(Ids::CLOCK, Items::CLOCK());
205 $this->map1to1Item(Ids::COAL, Items::COAL());
206 $this->map1to1Item(Ids::COAST_ARMOR_TRIM_SMITHING_TEMPLATE, Items::COAST_ARMOR_TRIM_SMITHING_TEMPLATE());
207 $this->map1to1Item(Ids::COCOA_BEANS, Items::COCOA_BEANS());
208 $this->map1to1Item(Ids::COD, Items::RAW_FISH());
209 $this->map1to1Item(Ids::COMPASS, Items::COMPASS());
210 $this->map1to1Item(Ids::COOKED_BEEF, Items::STEAK());
211 $this->map1to1Item(Ids::COOKED_CHICKEN, Items::COOKED_CHICKEN());
212 $this->map1to1Item(Ids::COOKED_COD, Items::COOKED_FISH());
213 $this->map1to1Item(Ids::COOKED_MUTTON, Items::COOKED_MUTTON());
214 $this->map1to1Item(Ids::COOKED_PORKCHOP, Items::COOKED_PORKCHOP());
215 $this->map1to1Item(Ids::COOKED_RABBIT, Items::COOKED_RABBIT());
216 $this->map1to1Item(Ids::COOKED_SALMON, Items::COOKED_SALMON());
217 $this->map1to1Item(Ids::COOKIE, Items::COOKIE());
218 $this->map1to1Item(Ids::COPPER_INGOT, Items::COPPER_INGOT());
219 $this->map1to1Item(Ids::CRIMSON_HANGING_SIGN, Items::CRIMSON_HANGING_SIGN());
220 $this->map1to1Item(Ids::CRIMSON_SIGN, Items::CRIMSON_SIGN());
221 $this->map1to1Item(Ids::DARK_OAK_BOAT, Items::DARK_OAK_BOAT());
222 $this->map1to1Item(Ids::DARK_OAK_HANGING_SIGN, Items::DARK_OAK_HANGING_SIGN());
223 $this->map1to1Item(Ids::DARK_OAK_SIGN, Items::DARK_OAK_SIGN());
224 $this->map1to1Item(Ids::DIAMOND, Items::DIAMOND());
225 $this->map1to1Item(Ids::DIAMOND_AXE, Items::DIAMOND_AXE());
226 $this->map1to1Item(Ids::DIAMOND_BOOTS, Items::DIAMOND_BOOTS());
227 $this->map1to1Item(Ids::DIAMOND_CHESTPLATE, Items::DIAMOND_CHESTPLATE());
228 $this->map1to1Item(Ids::DIAMOND_HELMET, Items::DIAMOND_HELMET());
229 $this->map1to1Item(Ids::DIAMOND_HOE, Items::DIAMOND_HOE());
230 $this->map1to1Item(Ids::DIAMOND_LEGGINGS, Items::DIAMOND_LEGGINGS());
231 $this->map1to1Item(Ids::DIAMOND_PICKAXE, Items::DIAMOND_PICKAXE());
232 $this->map1to1Item(Ids::DIAMOND_SHOVEL, Items::DIAMOND_SHOVEL());
233 $this->map1to1Item(Ids::DIAMOND_SWORD, Items::DIAMOND_SWORD());
234 $this->map1to1Item(Ids::DISC_FRAGMENT_5, Items::DISC_FRAGMENT_5());
235 $this->map1to1Item(Ids::DRAGON_BREATH, Items::DRAGON_BREATH());
236 $this->map1to1Item(Ids::DRIED_KELP, Items::DRIED_KELP());
237 $this->map1to1Item(Ids::DUNE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::DUNE_ARMOR_TRIM_SMITHING_TEMPLATE());
238 $this->map1to1Item(Ids::ECHO_SHARD, Items::ECHO_SHARD());
239 $this->map1to1Item(Ids::EGG, Items::EGG());
240 $this->map1to1Item(Ids::EMERALD, Items::EMERALD());
241 $this->map1to1Item(Ids::ENCHANTED_BOOK, Items::ENCHANTED_BOOK());
242 $this->map1to1Item(Ids::ENCHANTED_GOLDEN_APPLE, Items::ENCHANTED_GOLDEN_APPLE());
243 $this->map1to1Item(Ids::END_CRYSTAL, Items::END_CRYSTAL());
244 $this->map1to1Item(Ids::ENDER_PEARL, Items::ENDER_PEARL());
245 $this->map1to1Item(Ids::EXPERIENCE_BOTTLE, Items::EXPERIENCE_BOTTLE());
246 $this->map1to1Item(Ids::EYE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::EYE_ARMOR_TRIM_SMITHING_TEMPLATE());
247 $this->map1to1Item(Ids::FEATHER, Items::FEATHER());
248 $this->map1to1Item(Ids::FERMENTED_SPIDER_EYE, Items::FERMENTED_SPIDER_EYE());
249 $this->map1to1Item(Ids::FIRE_CHARGE, Items::FIRE_CHARGE());
250 $this->map1to1Item(Ids::FISHING_ROD, Items::FISHING_ROD());
251 $this->map1to1Item(Ids::FLINT, Items::FLINT());
252 $this->map1to1Item(Ids::FLINT_AND_STEEL, Items::FLINT_AND_STEEL());
253 $this->map1to1Item(Ids::GHAST_TEAR, Items::GHAST_TEAR());
254 $this->map1to1Item(Ids::GLASS_BOTTLE, Items::GLASS_BOTTLE());
255 $this->map1to1Item(Ids::GLISTERING_MELON_SLICE, Items::GLISTERING_MELON());
256 $this->map1to1Item(Ids::GLOW_BERRIES, Items::GLOW_BERRIES());
257 $this->map1to1Item(Ids::GLOW_INK_SAC, Items::GLOW_INK_SAC());
258 $this->map1to1Item(Ids::GLOWSTONE_DUST, Items::GLOWSTONE_DUST());
259 $this->map1to1Item(Ids::GOLD_INGOT, Items::GOLD_INGOT());
260 $this->map1to1Item(Ids::GOLD_NUGGET, Items::GOLD_NUGGET());
261 $this->map1to1Item(Ids::GOLDEN_APPLE, Items::GOLDEN_APPLE());
262 $this->map1to1Item(Ids::GOLDEN_AXE, Items::GOLDEN_AXE());
263 $this->map1to1Item(Ids::GOLDEN_BOOTS, Items::GOLDEN_BOOTS());
264 $this->map1to1Item(Ids::GOLDEN_CARROT, Items::GOLDEN_CARROT());
265 $this->map1to1Item(Ids::GOLDEN_CHESTPLATE, Items::GOLDEN_CHESTPLATE());
266 $this->map1to1Item(Ids::GOLDEN_HELMET, Items::GOLDEN_HELMET());
267 $this->map1to1Item(Ids::GOLDEN_HOE, Items::GOLDEN_HOE());
268 $this->map1to1Item(Ids::GOLDEN_LEGGINGS, Items::GOLDEN_LEGGINGS());
269 $this->map1to1Item(Ids::GOLDEN_PICKAXE, Items::GOLDEN_PICKAXE());
270 $this->map1to1Item(Ids::GOLDEN_SHOVEL, Items::GOLDEN_SHOVEL());
271 $this->map1to1Item(Ids::GOLDEN_SWORD, Items::GOLDEN_SWORD());
272 $this->map1to1Item(Ids::GUNPOWDER, Items::GUNPOWDER());
273 $this->map1to1Item(Ids::HEART_OF_THE_SEA, Items::HEART_OF_THE_SEA());
274 $this->map1to1Item(Ids::HONEY_BOTTLE, Items::HONEY_BOTTLE());
275 $this->map1to1Item(Ids::HONEYCOMB, Items::HONEYCOMB());
276 $this->map1to1Item(Ids::HOST_ARMOR_TRIM_SMITHING_TEMPLATE, Items::HOST_ARMOR_TRIM_SMITHING_TEMPLATE());
277 $this->map1to1Item(Ids::ICE_BOMB, Items::ICE_BOMB());
278 $this->map1to1Item(Ids::INK_SAC, Items::INK_SAC());
279 $this->map1to1Item(Ids::IRON_AXE, Items::IRON_AXE());
280 $this->map1to1Item(Ids::IRON_BOOTS, Items::IRON_BOOTS());
281 $this->map1to1Item(Ids::IRON_CHESTPLATE, Items::IRON_CHESTPLATE());
282 $this->map1to1Item(Ids::IRON_HELMET, Items::IRON_HELMET());
283 $this->map1to1Item(Ids::IRON_HOE, Items::IRON_HOE());
284 $this->map1to1Item(Ids::IRON_INGOT, Items::IRON_INGOT());
285 $this->map1to1Item(Ids::IRON_LEGGINGS, Items::IRON_LEGGINGS());
286 $this->map1to1Item(Ids::IRON_NUGGET, Items::IRON_NUGGET());
287 $this->map1to1Item(Ids::IRON_PICKAXE, Items::IRON_PICKAXE());
288 $this->map1to1Item(Ids::IRON_SHOVEL, Items::IRON_SHOVEL());
289 $this->map1to1Item(Ids::IRON_SWORD, Items::IRON_SWORD());
290 $this->map1to1Item(Ids::JUNGLE_BOAT, Items::JUNGLE_BOAT());
291 $this->map1to1Item(Ids::JUNGLE_HANGING_SIGN, Items::JUNGLE_HANGING_SIGN());
292 $this->map1to1Item(Ids::JUNGLE_SIGN, Items::JUNGLE_SIGN());
293 $this->map1to1Item(Ids::LAPIS_LAZULI, Items::LAPIS_LAZULI());
294 $this->map1to1Item(Ids::LAVA_BUCKET, Items::LAVA_BUCKET());
295 $this->map1to1Item(Ids::LEATHER, Items::LEATHER());
296 $this->map1to1Item(Ids::LEATHER_BOOTS, Items::LEATHER_BOOTS());
297 $this->map1to1Item(Ids::LEATHER_CHESTPLATE, Items::LEATHER_TUNIC());
298 $this->map1to1Item(Ids::LEATHER_HELMET, Items::LEATHER_CAP());
299 $this->map1to1Item(Ids::LEATHER_LEGGINGS, Items::LEATHER_PANTS());
300 $this->map1to1Item(Ids::MAGMA_CREAM, Items::MAGMA_CREAM());
301 $this->map1to1Item(Ids::MANGROVE_BOAT, Items::MANGROVE_BOAT());
302 $this->map1to1Item(Ids::MANGROVE_HANGING_SIGN, Items::MANGROVE_HANGING_SIGN());
303 $this->map1to1Item(Ids::MANGROVE_SIGN, Items::MANGROVE_SIGN());
304 $this->map1to1Item(Ids::MELON_SEEDS, Items::MELON_SEEDS());
305 $this->map1to1Item(Ids::MELON_SLICE, Items::MELON());
306 $this->map1to1Item(Ids::MILK_BUCKET, Items::MILK_BUCKET());
307 $this->map1to1Item(Ids::MINECART, Items::MINECART());
308 $this->map1to1Item(Ids::MUSHROOM_STEW, Items::MUSHROOM_STEW());
309 $this->map1to1Item(Ids::MUSIC_DISC_11, Items::RECORD_11());
310 $this->map1to1Item(Ids::MUSIC_DISC_13, Items::RECORD_13());
311 $this->map1to1Item(Ids::MUSIC_DISC_5, Items::RECORD_5());
312 $this->map1to1Item(Ids::MUSIC_DISC_BLOCKS, Items::RECORD_BLOCKS());
313 $this->map1to1Item(Ids::MUSIC_DISC_CAT, Items::RECORD_CAT());
314 $this->map1to1Item(Ids::MUSIC_DISC_CHIRP, Items::RECORD_CHIRP());
315 $this->map1to1Item(Ids::MUSIC_DISC_CREATOR, Items::RECORD_CREATOR());
316 $this->map1to1Item(Ids::MUSIC_DISC_CREATOR_MUSIC_BOX, Items::RECORD_CREATOR_MUSIC_BOX());
317 $this->map1to1Item(Ids::MUSIC_DISC_FAR, Items::RECORD_FAR());
318 $this->map1to1Item(Ids::MUSIC_DISC_MALL, Items::RECORD_MALL());
319 $this->map1to1Item(Ids::MUSIC_DISC_MELLOHI, Items::RECORD_MELLOHI());
320 $this->map1to1Item(Ids::MUSIC_DISC_OTHERSIDE, Items::RECORD_OTHERSIDE());
321 $this->map1to1Item(Ids::MUSIC_DISC_PIGSTEP, Items::RECORD_PIGSTEP());
322 $this->map1to1Item(Ids::MUSIC_DISC_PRECIPICE, Items::RECORD_PRECIPICE());
323 $this->map1to1Item(Ids::MUSIC_DISC_RELIC, Items::RECORD_RELIC());
324 $this->map1to1Item(Ids::MUSIC_DISC_STAL, Items::RECORD_STAL());
325 $this->map1to1Item(Ids::MUSIC_DISC_STRAD, Items::RECORD_STRAD());
326 $this->map1to1Item(Ids::MUSIC_DISC_WAIT, Items::RECORD_WAIT());
327 $this->map1to1Item(Ids::MUSIC_DISC_WARD, Items::RECORD_WARD());
328 $this->map1to1Item(Ids::MUTTON, Items::RAW_MUTTON());
329 $this->map1to1Item(Ids::NAME_TAG, Items::NAME_TAG());
330 $this->map1to1Item(Ids::NAUTILUS_SHELL, Items::NAUTILUS_SHELL());
331 $this->map1to1Item(Ids::NETHER_STAR, Items::NETHER_STAR());
332 $this->map1to1Item(Ids::NETHERBRICK, Items::NETHER_BRICK());
333 $this->map1to1Item(Ids::NETHERITE_AXE, Items::NETHERITE_AXE());
334 $this->map1to1Item(Ids::NETHERITE_BOOTS, Items::NETHERITE_BOOTS());
335 $this->map1to1Item(Ids::NETHERITE_CHESTPLATE, Items::NETHERITE_CHESTPLATE());
336 $this->map1to1Item(Ids::NETHERITE_HELMET, Items::NETHERITE_HELMET());
337 $this->map1to1Item(Ids::NETHERITE_HOE, Items::NETHERITE_HOE());
338 $this->map1to1Item(Ids::NETHERITE_INGOT, Items::NETHERITE_INGOT());
339 $this->map1to1Item(Ids::NETHERITE_LEGGINGS, Items::NETHERITE_LEGGINGS());
340 $this->map1to1Item(Ids::NETHERITE_PICKAXE, Items::NETHERITE_PICKAXE());
341 $this->map1to1Item(Ids::NETHERITE_SCRAP, Items::NETHERITE_SCRAP());
342 $this->map1to1Item(Ids::NETHERITE_SHOVEL, Items::NETHERITE_SHOVEL());
343 $this->map1to1Item(Ids::NETHERITE_SWORD, Items::NETHERITE_SWORD());
344 $this->map1to1Item(Ids::NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items::NETHERITE_UPGRADE_SMITHING_TEMPLATE());
345 $this->map1to1Item(Ids::OAK_BOAT, Items::OAK_BOAT());
346 $this->map1to1Item(Ids::OAK_HANGING_SIGN, Items::OAK_HANGING_SIGN());
347 $this->map1to1Item(Ids::OAK_SIGN, Items::OAK_SIGN());
348 $this->map1to1Item(Ids::PAINTING, Items::PAINTING());
349 $this->map1to1Item(Ids::PALE_OAK_HANGING_SIGN, Items::PALE_OAK_HANGING_SIGN());
350 $this->map1to1Item(Ids::PALE_OAK_SIGN, Items::PALE_OAK_SIGN());
351 $this->map1to1Item(Ids::PAPER, Items::PAPER());
352 $this->map1to1Item(Ids::PHANTOM_MEMBRANE, Items::PHANTOM_MEMBRANE());
353 $this->map1to1Item(Ids::PITCHER_POD, Items::PITCHER_POD());
354 $this->map1to1Item(Ids::POISONOUS_POTATO, Items::POISONOUS_POTATO());
355 $this->map1to1Item(Ids::POPPED_CHORUS_FRUIT, Items::POPPED_CHORUS_FRUIT());
356 $this->map1to1Item(Ids::PORKCHOP, Items::RAW_PORKCHOP());
357 $this->map1to1Item(Ids::POTATO, Items::POTATO());
358 $this->map1to1Item(Ids::PRISMARINE_CRYSTALS, Items::PRISMARINE_CRYSTALS());
359 $this->map1to1Item(Ids::PRISMARINE_SHARD, Items::PRISMARINE_SHARD());
360 $this->map1to1Item(Ids::PUFFERFISH, Items::PUFFERFISH());
361 $this->map1to1Item(Ids::PUMPKIN_PIE, Items::PUMPKIN_PIE());
362 $this->map1to1Item(Ids::PUMPKIN_SEEDS, Items::PUMPKIN_SEEDS());
363 $this->map1to1Item(Ids::QUARTZ, Items::NETHER_QUARTZ());
364 $this->map1to1Item(Ids::RABBIT, Items::RAW_RABBIT());
365 $this->map1to1Item(Ids::RABBIT_FOOT, Items::RABBIT_FOOT());
366 $this->map1to1Item(Ids::RABBIT_HIDE, Items::RABBIT_HIDE());
367 $this->map1to1Item(Ids::RABBIT_STEW, Items::RABBIT_STEW());
368 $this->map1to1Item(Ids::RAISER_ARMOR_TRIM_SMITHING_TEMPLATE, Items::RAISER_ARMOR_TRIM_SMITHING_TEMPLATE());
369 $this->map1to1Item(Ids::RAW_COPPER, Items::RAW_COPPER());
370 $this->map1to1Item(Ids::RAW_GOLD, Items::RAW_GOLD());
371 $this->map1to1Item(Ids::RAW_IRON, Items::RAW_IRON());
372 $this->map1to1Item(Ids::RECOVERY_COMPASS, Items::RECOVERY_COMPASS());
373 $this->map1to1Item(Ids::REDSTONE, Items::REDSTONE_DUST());
374 $this->map1to1Item(Ids::RESIN_BRICK, Items::RESIN_BRICK());
375 $this->map1to1Item(Ids::RIB_ARMOR_TRIM_SMITHING_TEMPLATE, Items::RIB_ARMOR_TRIM_SMITHING_TEMPLATE());
376 $this->map1to1Item(Ids::ROTTEN_FLESH, Items::ROTTEN_FLESH());
377 $this->map1to1Item(Ids::SALMON, Items::RAW_SALMON());
378 $this->map1to1Item(Ids::TURTLE_SCUTE, Items::SCUTE());
379 $this->map1to1Item(Ids::SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE());
380 $this->map1to1Item(Ids::SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE());
381 $this->map1to1Item(Ids::SHEARS, Items::SHEARS());
382 $this->map1to1Item(Ids::SHULKER_SHELL, Items::SHULKER_SHELL());
383 $this->map1to1Item(Ids::SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE());
384 $this->map1to1Item(Ids::SLIME_BALL, Items::SLIMEBALL());
385 $this->map1to1Item(Ids::SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE());
386 $this->map1to1Item(Ids::SNOWBALL, Items::SNOWBALL());
387 $this->map1to1Item(Ids::SPIDER_EYE, Items::SPIDER_EYE());
388 $this->map1to1Item(Ids::SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE());
389 $this->map1to1Item(Ids::SPRUCE_BOAT, Items::SPRUCE_BOAT());
390 $this->map1to1Item(Ids::SPRUCE_HANGING_SIGN, Items::SPRUCE_HANGING_SIGN());
391 $this->map1to1Item(Ids::SPRUCE_SIGN, Items::SPRUCE_SIGN());
392 $this->map1to1Item(Ids::SPYGLASS, Items::SPYGLASS());
393 $this->map1to1Item(Ids::SQUID_SPAWN_EGG, Items::SQUID_SPAWN_EGG());
394 $this->map1to1Item(Ids::STICK, Items::STICK());
395 $this->map1to1Item(Ids::STONE_AXE, Items::STONE_AXE());
396 $this->map1to1Item(Ids::STONE_HOE, Items::STONE_HOE());
397 $this->map1to1Item(Ids::STONE_PICKAXE, Items::STONE_PICKAXE());
398 $this->map1to1Item(Ids::STONE_SHOVEL, Items::STONE_SHOVEL());
399 $this->map1to1Item(Ids::STONE_SWORD, Items::STONE_SWORD());
400 $this->map1to1Item(Ids::STRING, Items::STRING());
401 $this->map1to1Item(Ids::SUGAR, Items::SUGAR());
402 $this->map1to1Item(Ids::SWEET_BERRIES, Items::SWEET_BERRIES());
403 $this->map1to1Item(Ids::TORCHFLOWER_SEEDS, Items::TORCHFLOWER_SEEDS());
404 $this->map1to1Item(Ids::TIDE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::TIDE_ARMOR_TRIM_SMITHING_TEMPLATE());
405 $this->map1to1Item(Ids::TOTEM_OF_UNDYING, Items::TOTEM());
406 $this->map1to1Item(Ids::TROPICAL_FISH, Items::CLOWNFISH());
407 $this->map1to1Item(Ids::TURTLE_HELMET, Items::TURTLE_HELMET());
408 $this->map1to1Item(Ids::VEX_ARMOR_TRIM_SMITHING_TEMPLATE, Items::VEX_ARMOR_TRIM_SMITHING_TEMPLATE());
409 $this->map1to1Item(Ids::VILLAGER_SPAWN_EGG, Items::VILLAGER_SPAWN_EGG());
410 $this->map1to1Item(Ids::WARD_ARMOR_TRIM_SMITHING_TEMPLATE, Items::WARD_ARMOR_TRIM_SMITHING_TEMPLATE());
411 $this->map1to1Item(Ids::WARPED_HANGING_SIGN, Items::WARPED_HANGING_SIGN());
412 $this->map1to1Item(Ids::WARPED_SIGN, Items::WARPED_SIGN());
413 $this->map1to1Item(Ids::WATER_BUCKET, Items::WATER_BUCKET());
414 $this->map1to1Item(Ids::WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE, Items::WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE());
415 $this->map1to1Item(Ids::WHEAT, Items::WHEAT());
416 $this->map1to1Item(Ids::WHEAT_SEEDS, Items::WHEAT_SEEDS());
417 $this->map1to1Item(Ids::WILD_ARMOR_TRIM_SMITHING_TEMPLATE, Items::WILD_ARMOR_TRIM_SMITHING_TEMPLATE());
418 $this->map1to1Item(Ids::WOODEN_AXE, Items::WOODEN_AXE());
419 $this->map1to1Item(Ids::WOODEN_HOE, Items::WOODEN_HOE());
420 $this->map1to1Item(Ids::WOODEN_PICKAXE, Items::WOODEN_PICKAXE());
421 $this->map1to1Item(Ids::WOODEN_SHOVEL, Items::WOODEN_SHOVEL());
422 $this->map1to1Item(Ids::WOODEN_SWORD, Items::WOODEN_SWORD());
423 $this->map1to1Item(Ids::WRITABLE_BOOK, Items::WRITABLE_BOOK());
424 $this->map1to1Item(Ids::WRITTEN_BOOK, Items::WRITTEN_BOOK());
425 $this->map1to1Item(Ids::ZOMBIE_SPAWN_EGG, Items::ZOMBIE_SPAWN_EGG());
426 }
427
434 private function register1ToNItemMappings() : void{
435 $this->map1ToNItem(Ids::ARROW, [
436 0 => Items::ARROW(),
437 //TODO: tipped arrows
438 ]);
439 $this->map1ToNItem(Ids::COMPOUND, [
440 CompoundTypeIds::SALT => Items::CHEMICAL_SALT(),
441 CompoundTypeIds::SODIUM_OXIDE => Items::CHEMICAL_SODIUM_OXIDE(),
442 CompoundTypeIds::SODIUM_HYDROXIDE => Items::CHEMICAL_SODIUM_HYDROXIDE(),
443 CompoundTypeIds::MAGNESIUM_NITRATE => Items::CHEMICAL_MAGNESIUM_NITRATE(),
444 CompoundTypeIds::IRON_SULPHIDE => Items::CHEMICAL_IRON_SULPHIDE(),
445 CompoundTypeIds::LITHIUM_HYDRIDE => Items::CHEMICAL_LITHIUM_HYDRIDE(),
446 CompoundTypeIds::SODIUM_HYDRIDE => Items::CHEMICAL_SODIUM_HYDRIDE(),
447 CompoundTypeIds::CALCIUM_BROMIDE => Items::CHEMICAL_CALCIUM_BROMIDE(),
448 CompoundTypeIds::MAGNESIUM_OXIDE => Items::CHEMICAL_MAGNESIUM_OXIDE(),
449 CompoundTypeIds::SODIUM_ACETATE => Items::CHEMICAL_SODIUM_ACETATE(),
450 CompoundTypeIds::LUMINOL => Items::CHEMICAL_LUMINOL(),
451 CompoundTypeIds::CHARCOAL => Items::CHEMICAL_CHARCOAL(),
452 CompoundTypeIds::SUGAR => Items::CHEMICAL_SUGAR(),
453 CompoundTypeIds::ALUMINIUM_OXIDE => Items::CHEMICAL_ALUMINIUM_OXIDE(),
454 CompoundTypeIds::BORON_TRIOXIDE => Items::CHEMICAL_BORON_TRIOXIDE(),
455 CompoundTypeIds::SOAP => Items::CHEMICAL_SOAP(),
456 CompoundTypeIds::POLYETHYLENE => Items::CHEMICAL_POLYETHYLENE(),
457 CompoundTypeIds::RUBBISH => Items::CHEMICAL_RUBBISH(),
458 CompoundTypeIds::MAGNESIUM_SALTS => Items::CHEMICAL_MAGNESIUM_SALTS(),
459 CompoundTypeIds::SULPHATE => Items::CHEMICAL_SULPHATE(),
460 CompoundTypeIds::BARIUM_SULPHATE => Items::CHEMICAL_BARIUM_SULPHATE(),
461 CompoundTypeIds::POTASSIUM_CHLORIDE => Items::CHEMICAL_POTASSIUM_CHLORIDE(),
462 CompoundTypeIds::MERCURIC_CHLORIDE => Items::CHEMICAL_MERCURIC_CHLORIDE(),
463 CompoundTypeIds::CERIUM_CHLORIDE => Items::CHEMICAL_CERIUM_CHLORIDE(),
464 CompoundTypeIds::TUNGSTEN_CHLORIDE => Items::CHEMICAL_TUNGSTEN_CHLORIDE(),
465 CompoundTypeIds::CALCIUM_CHLORIDE => Items::CHEMICAL_CALCIUM_CHLORIDE(),
466 CompoundTypeIds::WATER => Items::CHEMICAL_WATER(),
467 CompoundTypeIds::GLUE => Items::CHEMICAL_GLUE(),
468 CompoundTypeIds::HYPOCHLORITE => Items::CHEMICAL_HYPOCHLORITE(),
469 CompoundTypeIds::CRUDE_OIL => Items::CHEMICAL_CRUDE_OIL(),
470 CompoundTypeIds::LATEX => Items::CHEMICAL_LATEX(),
471 CompoundTypeIds::POTASSIUM_IODIDE => Items::CHEMICAL_POTASSIUM_IODIDE(),
472 CompoundTypeIds::SODIUM_FLUORIDE => Items::CHEMICAL_SODIUM_FLUORIDE(),
473 CompoundTypeIds::BENZENE => Items::CHEMICAL_BENZENE(),
474 CompoundTypeIds::INK => Items::CHEMICAL_INK(),
475 CompoundTypeIds::HYDROGEN_PEROXIDE => Items::CHEMICAL_HYDROGEN_PEROXIDE(),
476 CompoundTypeIds::AMMONIA => Items::CHEMICAL_AMMONIA(),
477 CompoundTypeIds::SODIUM_HYPOCHLORITE => Items::CHEMICAL_SODIUM_HYPOCHLORITE(),
478 ]);
479 }
480
486 private function register1to1BlockWithMetaMappings() : void{
487 $this->map1to1BlockWithMeta(
488 Ids::BED,
489 Blocks::BED(),
490 function(Bed $block, int $meta) : void{
491 $block->setColor(DyeColorIdMap::getInstance()->fromId($meta) ?? throw new ItemTypeDeserializeException("Unknown bed color ID $meta"));
492 },
493 fn(Bed $block) => DyeColorIdMap::getInstance()->toId($block->getColor())
494 );
495 }
496
502 private function register1to1ItemWithMetaMappings() : void{
503 $this->map1to1ItemWithMeta(
504 Ids::GOAT_HORN,
505 Items::GOAT_HORN(),
506 function(GoatHorn $item, int $meta) : void{
507 $item->setHornType(GoatHornTypeIdMap::getInstance()->fromId($meta) ?? throw new ItemTypeDeserializeException("Unknown goat horn type ID $meta"));
508 },
509 fn(GoatHorn $item) => GoatHornTypeIdMap::getInstance()->toId($item->getHornType())
510 );
511 $this->map1to1ItemWithMeta(
512 Ids::MEDICINE,
513 Items::MEDICINE(),
514 function(Medicine $item, int $meta) : void{
515 $item->setType(MedicineTypeIdMap::getInstance()->fromId($meta) ?? throw new ItemTypeDeserializeException("Unknown medicine type ID $meta"));
516 },
517 fn(Medicine $item) => MedicineTypeIdMap::getInstance()->toId($item->getType())
518 );
519 $this->map1to1ItemWithMeta(
520 Ids::POTION,
521 Items::POTION(),
522 function(Potion $item, int $meta) : void{
523 $item->setType(PotionTypeIdMap::getInstance()->fromId($meta) ?? throw new ItemTypeDeserializeException("Unknown potion type ID $meta"));
524 },
525 fn(Potion $item) => PotionTypeIdMap::getInstance()->toId($item->getType())
526 );
527 $this->map1to1ItemWithMeta(
528 Ids::SPLASH_POTION,
529 Items::SPLASH_POTION(),
530 function(SplashPotion $item, int $meta) : void{
531 $item->setType(PotionTypeIdMap::getInstance()->fromId($meta) ?? throw new ItemTypeDeserializeException("Unknown potion type ID $meta"));
532 },
533 fn(SplashPotion $item) => PotionTypeIdMap::getInstance()->toId($item->getType())
534 );
535 $this->map1to1ItemWithMeta(
536 Ids::SUSPICIOUS_STEW,
537 Items::SUSPICIOUS_STEW(),
538 function(SuspiciousStew $item, int $meta) : void{
539 $item->setType(SuspiciousStewTypeIdMap::getInstance()->fromId($meta) ?? throw new ItemTypeDeserializeException("Unknown suspicious stew type ID $meta"));
540 },
541 fn(SuspiciousStew $item) => SuspiciousStewTypeIdMap::getInstance()->toId($item->getType())
542 );
543 }
544
552 private function registerMiscItemMappings() : void{
553 foreach(DyeColor::cases() as $color){
554 $id = DyeColorIdMap::getInstance()->toItemId($color);
555 $this->deserializer?->map($id, fn() => Items::DYE()->setColor($color));
556 }
557 $this->serializer?->map(Items::DYE(), fn(Dye $item) => new Data(DyeColorIdMap::getInstance()->toItemId($item->getColor())));
558
559 $this->deserializer?->map(Ids::BANNER, function(Data $data) : Item{
560 $type = $data->getTag()?->getInt(TileBanner::TAG_TYPE, TileBanner::TYPE_NORMAL) ?? TileBanner::TYPE_NORMAL;
561 if($type === TileBanner::TYPE_OMINOUS){
562 return Items::OMINOUS_BANNER();
563 }
564 $color = DyeColorIdMap::getInstance()->fromInvertedId($data->getMeta()) ?? throw new ItemTypeDeserializeException("Unknown banner meta " . $data->getMeta());
565 return Items::BANNER()->setColor($color);
566 });
567 $this->serializer?->map(Items::OMINOUS_BANNER(), fn() => new Data(Ids::BANNER, tag: CompoundTag::create()
568 ->setInt(TileBanner::TAG_TYPE, TileBanner::TYPE_OMINOUS))
569 );
570 $this->serializer?->map(Items::BANNER(), function(Banner $item) : Data{
571 return new Data(Ids::BANNER, DyeColorIdMap::getInstance()->toInvertedId($item->getColor()));
572 });
573 }
574
582 private function registerMiscBlockMappings() : void{
583 $copperDoorStateIdMap = [];
584 foreach ([
585 [Ids::COPPER_DOOR, CopperOxidation::NONE, false],
586 [Ids::EXPOSED_COPPER_DOOR, CopperOxidation::EXPOSED, false],
587 [Ids::WEATHERED_COPPER_DOOR, CopperOxidation::WEATHERED, false],
588 [Ids::OXIDIZED_COPPER_DOOR, CopperOxidation::OXIDIZED, false],
589 [Ids::WAXED_COPPER_DOOR, CopperOxidation::NONE, true],
590 [Ids::WAXED_EXPOSED_COPPER_DOOR, CopperOxidation::EXPOSED, true],
591 [Ids::WAXED_WEATHERED_COPPER_DOOR, CopperOxidation::WEATHERED, true],
592 [Ids::WAXED_OXIDIZED_COPPER_DOOR, CopperOxidation::OXIDIZED, true]
593 ] as [$id, $oxidation, $waxed]) {
594 $copperDoorStateIdMap[$oxidation->value][$waxed ? 1 : 0] = $id;
595 $this->deserializer?->mapBlock($id, fn() => Blocks::COPPER_DOOR()->setOxidation($oxidation)->setWaxed($waxed));
596 }
597 $this->serializer?->mapBlock(Blocks::COPPER_DOOR(), fn(CopperDoor $block) => new Data($copperDoorStateIdMap[$block->getOxidation()->value][$block->isWaxed() ? 1 : 0]));
598 }
599}
map1to1BlockWithMeta(string $id, Block $block, \Closure $deserializeMeta, \Closure $serializeMeta)
map1to1ItemWithMeta(string $id, Item $item, \Closure $deserializeMeta, \Closure $serializeMeta)