PocketMine-MP 5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
Loading...
Searching...
No Matches
BlockObjectToStateSerializer.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\block\convert;
25
154use pocketmine\block\utils\BrewingStandSlot;
155use pocketmine\block\utils\CoralType;
156use pocketmine\block\utils\DirtType;
157use pocketmine\block\utils\DripleafState;
158use pocketmine\block\utils\DyeColor;
159use pocketmine\block\utils\FroglightType;
160use pocketmine\block\utils\LeverFacing;
161use pocketmine\block\utils\MobHeadType;
189use function get_class;
190
199 private array $serializers = [];
200
205 private array $cache = [];
206
207 public function __construct(){
208 $this->registerCandleSerializers();
209 $this->registerFlatColorBlockSerializers();
210 $this->registerFlatCoralSerializers();
211 $this->registerCauldronSerializers();
212 $this->registerFlatWoodBlockSerializers();
213 $this->registerLeavesSerializers();
214 $this->registerSaplingSerializers();
215 $this->registerMobHeadSerializers();
216 $this->registerSimpleSerializers();
217 $this->registerSerializers();
218 }
219
220 public function serialize(int $stateId) : BlockStateData{
221 //TODO: singleton usage not ideal
222 //TODO: we may want to deduplicate cache entries to avoid wasting memory
223 return $this->cache[$stateId] ??= $this->serializeBlock(RuntimeBlockStateRegistry::getInstance()->fromStateId($stateId));
224 }
225
231 public function map(Block $block, \Closure $serializer) : void{
232 if(isset($this->serializers[$block->getTypeId()])){
233 throw new \InvalidArgumentException("Block type ID " . $block->getTypeId() . " already has a serializer registered");
234 }
235 $this->serializers[$block->getTypeId()] = $serializer;
236 }
237
238 public function mapSimple(Block $block, string $id) : void{
239 $this->map($block, fn() => Writer::create($id));
240 }
241
242 public function mapSlab(Slab $block, string $singleId, string $doubleId) : void{
243 $this->map($block, fn(Slab $block) => Helper::encodeSlab($block, $singleId, $doubleId));
244 }
245
246 public function mapStairs(Stair $block, string $id) : void{
247 $this->map($block, fn(Stair $block) => Helper::encodeStairs($block, Writer::create($id)));
248 }
249
250 public function mapLog(Wood $block, string $unstrippedId, string $strippedId) : void{
251 $this->map($block, fn(Wood $block) => Helper::encodeLog($block, $unstrippedId, $strippedId));
252 }
253
260 public function serializeBlock(Block $blockState) : BlockStateData{
261 $typeId = $blockState->getTypeId();
262
263 $locatedSerializer = $this->serializers[$typeId] ?? null;
264 if($locatedSerializer === null){
265 throw new BlockStateSerializeException("No serializer registered for " . get_class($blockState) . " with type ID $typeId");
266 }
267
276 $serializer = $locatedSerializer;
277
279 $writer = $serializer($blockState);
280 return $writer->getBlockStateData();
281 }
282
283 private function registerCandleSerializers() : void{
284 $this->map(Blocks::CANDLE(), fn(Candle $block) => Helper::encodeCandle($block, new Writer(Ids::CANDLE)));
285 $this->map(Blocks::DYED_CANDLE(), fn(DyedCandle $block) => Helper::encodeCandle($block, new Writer(match($block->getColor()){
286 DyeColor::BLACK => Ids::BLACK_CANDLE,
287 DyeColor::BLUE => Ids::BLUE_CANDLE,
288 DyeColor::BROWN => Ids::BROWN_CANDLE,
289 DyeColor::CYAN => Ids::CYAN_CANDLE,
290 DyeColor::GRAY => Ids::GRAY_CANDLE,
291 DyeColor::GREEN => Ids::GREEN_CANDLE,
292 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CANDLE,
293 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CANDLE,
294 DyeColor::LIME => Ids::LIME_CANDLE,
295 DyeColor::MAGENTA => Ids::MAGENTA_CANDLE,
296 DyeColor::ORANGE => Ids::ORANGE_CANDLE,
297 DyeColor::PINK => Ids::PINK_CANDLE,
298 DyeColor::PURPLE => Ids::PURPLE_CANDLE,
299 DyeColor::RED => Ids::RED_CANDLE,
300 DyeColor::WHITE => Ids::WHITE_CANDLE,
301 DyeColor::YELLOW => Ids::YELLOW_CANDLE,
302 })));
303 $this->map(Blocks::CAKE_WITH_CANDLE(), fn(CakeWithCandle $block) => Writer::create(Ids::CANDLE_CAKE)
304 ->writeBool(StateNames::LIT, $block->isLit()));
305 $this->map(Blocks::CAKE_WITH_DYED_CANDLE(), fn(CakeWithDyedCandle $block) => Writer::create(match($block->getColor()){
306 DyeColor::BLACK => Ids::BLACK_CANDLE_CAKE,
307 DyeColor::BLUE => Ids::BLUE_CANDLE_CAKE,
308 DyeColor::BROWN => Ids::BROWN_CANDLE_CAKE,
309 DyeColor::CYAN => Ids::CYAN_CANDLE_CAKE,
310 DyeColor::GRAY => Ids::GRAY_CANDLE_CAKE,
311 DyeColor::GREEN => Ids::GREEN_CANDLE_CAKE,
312 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CANDLE_CAKE,
313 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CANDLE_CAKE,
314 DyeColor::LIME => Ids::LIME_CANDLE_CAKE,
315 DyeColor::MAGENTA => Ids::MAGENTA_CANDLE_CAKE,
316 DyeColor::ORANGE => Ids::ORANGE_CANDLE_CAKE,
317 DyeColor::PINK => Ids::PINK_CANDLE_CAKE,
318 DyeColor::PURPLE => Ids::PURPLE_CANDLE_CAKE,
319 DyeColor::RED => Ids::RED_CANDLE_CAKE,
320 DyeColor::WHITE => Ids::WHITE_CANDLE_CAKE,
321 DyeColor::YELLOW => Ids::YELLOW_CANDLE_CAKE,
322 })->writeBool(StateNames::LIT, $block->isLit()));
323 }
324
325 public function registerFlatColorBlockSerializers() : void{
326 $this->map(Blocks::STAINED_HARDENED_GLASS(), fn(StainedHardenedGlass $block) => Writer::create(match($block->getColor()){
327 DyeColor::BLACK => Ids::HARD_BLACK_STAINED_GLASS,
328 DyeColor::BLUE => Ids::HARD_BLUE_STAINED_GLASS,
329 DyeColor::BROWN => Ids::HARD_BROWN_STAINED_GLASS,
330 DyeColor::CYAN => Ids::HARD_CYAN_STAINED_GLASS,
331 DyeColor::GRAY => Ids::HARD_GRAY_STAINED_GLASS,
332 DyeColor::GREEN => Ids::HARD_GREEN_STAINED_GLASS,
333 DyeColor::LIGHT_BLUE => Ids::HARD_LIGHT_BLUE_STAINED_GLASS,
334 DyeColor::LIGHT_GRAY => Ids::HARD_LIGHT_GRAY_STAINED_GLASS,
335 DyeColor::LIME => Ids::HARD_LIME_STAINED_GLASS,
336 DyeColor::MAGENTA => Ids::HARD_MAGENTA_STAINED_GLASS,
337 DyeColor::ORANGE => Ids::HARD_ORANGE_STAINED_GLASS,
338 DyeColor::PINK => Ids::HARD_PINK_STAINED_GLASS,
339 DyeColor::PURPLE => Ids::HARD_PURPLE_STAINED_GLASS,
340 DyeColor::RED => Ids::HARD_RED_STAINED_GLASS,
341 DyeColor::WHITE => Ids::HARD_WHITE_STAINED_GLASS,
342 DyeColor::YELLOW => Ids::HARD_YELLOW_STAINED_GLASS,
343 }));
344
345 $this->map(Blocks::STAINED_HARDENED_GLASS_PANE(), fn(StainedHardenedGlassPane $block) => Writer::create(match($block->getColor()){
346 DyeColor::BLACK => Ids::HARD_BLACK_STAINED_GLASS_PANE,
347 DyeColor::BLUE => Ids::HARD_BLUE_STAINED_GLASS_PANE,
348 DyeColor::BROWN => Ids::HARD_BROWN_STAINED_GLASS_PANE,
349 DyeColor::CYAN => Ids::HARD_CYAN_STAINED_GLASS_PANE,
350 DyeColor::GRAY => Ids::HARD_GRAY_STAINED_GLASS_PANE,
351 DyeColor::GREEN => Ids::HARD_GREEN_STAINED_GLASS_PANE,
352 DyeColor::LIGHT_BLUE => Ids::HARD_LIGHT_BLUE_STAINED_GLASS_PANE,
353 DyeColor::LIGHT_GRAY => Ids::HARD_LIGHT_GRAY_STAINED_GLASS_PANE,
354 DyeColor::LIME => Ids::HARD_LIME_STAINED_GLASS_PANE,
355 DyeColor::MAGENTA => Ids::HARD_MAGENTA_STAINED_GLASS_PANE,
356 DyeColor::ORANGE => Ids::HARD_ORANGE_STAINED_GLASS_PANE,
357 DyeColor::PINK => Ids::HARD_PINK_STAINED_GLASS_PANE,
358 DyeColor::PURPLE => Ids::HARD_PURPLE_STAINED_GLASS_PANE,
359 DyeColor::RED => Ids::HARD_RED_STAINED_GLASS_PANE,
360 DyeColor::WHITE => Ids::HARD_WHITE_STAINED_GLASS_PANE,
361 DyeColor::YELLOW => Ids::HARD_YELLOW_STAINED_GLASS_PANE,
362 }));
363
364 $this->map(Blocks::GLAZED_TERRACOTTA(), function(GlazedTerracotta $block) : Writer{
365 return Writer::create(match($block->getColor()){
366 DyeColor::BLACK => Ids::BLACK_GLAZED_TERRACOTTA,
367 DyeColor::BLUE => Ids::BLUE_GLAZED_TERRACOTTA,
368 DyeColor::BROWN => Ids::BROWN_GLAZED_TERRACOTTA,
369 DyeColor::CYAN => Ids::CYAN_GLAZED_TERRACOTTA,
370 DyeColor::GRAY => Ids::GRAY_GLAZED_TERRACOTTA,
371 DyeColor::GREEN => Ids::GREEN_GLAZED_TERRACOTTA,
372 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_GLAZED_TERRACOTTA,
373 DyeColor::LIGHT_GRAY => Ids::SILVER_GLAZED_TERRACOTTA,
374 DyeColor::LIME => Ids::LIME_GLAZED_TERRACOTTA,
375 DyeColor::MAGENTA => Ids::MAGENTA_GLAZED_TERRACOTTA,
376 DyeColor::ORANGE => Ids::ORANGE_GLAZED_TERRACOTTA,
377 DyeColor::PINK => Ids::PINK_GLAZED_TERRACOTTA,
378 DyeColor::PURPLE => Ids::PURPLE_GLAZED_TERRACOTTA,
379 DyeColor::RED => Ids::RED_GLAZED_TERRACOTTA,
380 DyeColor::WHITE => Ids::WHITE_GLAZED_TERRACOTTA,
381 DyeColor::YELLOW => Ids::YELLOW_GLAZED_TERRACOTTA,
382 })
383 ->writeHorizontalFacing($block->getFacing());
384 });
385
386 $this->map(Blocks::WOOL(), fn(Wool $block) => Writer::create(match($block->getColor()){
387 DyeColor::BLACK => Ids::BLACK_WOOL,
388 DyeColor::BLUE => Ids::BLUE_WOOL,
389 DyeColor::BROWN => Ids::BROWN_WOOL,
390 DyeColor::CYAN => Ids::CYAN_WOOL,
391 DyeColor::GRAY => Ids::GRAY_WOOL,
392 DyeColor::GREEN => Ids::GREEN_WOOL,
393 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_WOOL,
394 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_WOOL,
395 DyeColor::LIME => Ids::LIME_WOOL,
396 DyeColor::MAGENTA => Ids::MAGENTA_WOOL,
397 DyeColor::ORANGE => Ids::ORANGE_WOOL,
398 DyeColor::PINK => Ids::PINK_WOOL,
399 DyeColor::PURPLE => Ids::PURPLE_WOOL,
400 DyeColor::RED => Ids::RED_WOOL,
401 DyeColor::WHITE => Ids::WHITE_WOOL,
402 DyeColor::YELLOW => Ids::YELLOW_WOOL,
403 }));
404
405 $this->map(Blocks::CARPET(), fn(Carpet $block) => Writer::create(match($block->getColor()){
406 DyeColor::BLACK => Ids::BLACK_CARPET,
407 DyeColor::BLUE => Ids::BLUE_CARPET,
408 DyeColor::BROWN => Ids::BROWN_CARPET,
409 DyeColor::CYAN => Ids::CYAN_CARPET,
410 DyeColor::GRAY => Ids::GRAY_CARPET,
411 DyeColor::GREEN => Ids::GREEN_CARPET,
412 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CARPET,
413 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CARPET,
414 DyeColor::LIME => Ids::LIME_CARPET,
415 DyeColor::MAGENTA => Ids::MAGENTA_CARPET,
416 DyeColor::ORANGE => Ids::ORANGE_CARPET,
417 DyeColor::PINK => Ids::PINK_CARPET,
418 DyeColor::PURPLE => Ids::PURPLE_CARPET,
419 DyeColor::RED => Ids::RED_CARPET,
420 DyeColor::WHITE => Ids::WHITE_CARPET,
421 DyeColor::YELLOW => Ids::YELLOW_CARPET,
422 }));
423
424 $this->map(Blocks::DYED_SHULKER_BOX(), fn(DyedShulkerBox $block) => Writer::create(match($block->getColor()){
425 DyeColor::BLACK => Ids::BLACK_SHULKER_BOX,
426 DyeColor::BLUE => Ids::BLUE_SHULKER_BOX,
427 DyeColor::BROWN => Ids::BROWN_SHULKER_BOX,
428 DyeColor::CYAN => Ids::CYAN_SHULKER_BOX,
429 DyeColor::GRAY => Ids::GRAY_SHULKER_BOX,
430 DyeColor::GREEN => Ids::GREEN_SHULKER_BOX,
431 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_SHULKER_BOX,
432 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_SHULKER_BOX,
433 DyeColor::LIME => Ids::LIME_SHULKER_BOX,
434 DyeColor::MAGENTA => Ids::MAGENTA_SHULKER_BOX,
435 DyeColor::ORANGE => Ids::ORANGE_SHULKER_BOX,
436 DyeColor::PINK => Ids::PINK_SHULKER_BOX,
437 DyeColor::PURPLE => Ids::PURPLE_SHULKER_BOX,
438 DyeColor::RED => Ids::RED_SHULKER_BOX,
439 DyeColor::WHITE => Ids::WHITE_SHULKER_BOX,
440 DyeColor::YELLOW => Ids::YELLOW_SHULKER_BOX,
441 }));
442
443 $this->map(Blocks::CONCRETE(), fn(Concrete $block) => Writer::create(match($block->getColor()){
444 DyeColor::BLACK => Ids::BLACK_CONCRETE,
445 DyeColor::BLUE => Ids::BLUE_CONCRETE,
446 DyeColor::BROWN => Ids::BROWN_CONCRETE,
447 DyeColor::CYAN => Ids::CYAN_CONCRETE,
448 DyeColor::GRAY => Ids::GRAY_CONCRETE,
449 DyeColor::GREEN => Ids::GREEN_CONCRETE,
450 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CONCRETE,
451 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CONCRETE,
452 DyeColor::LIME => Ids::LIME_CONCRETE,
453 DyeColor::MAGENTA => Ids::MAGENTA_CONCRETE,
454 DyeColor::ORANGE => Ids::ORANGE_CONCRETE,
455 DyeColor::PINK => Ids::PINK_CONCRETE,
456 DyeColor::PURPLE => Ids::PURPLE_CONCRETE,
457 DyeColor::RED => Ids::RED_CONCRETE,
458 DyeColor::WHITE => Ids::WHITE_CONCRETE,
459 DyeColor::YELLOW => Ids::YELLOW_CONCRETE,
460 }));
461
462 $this->map(Blocks::CONCRETE_POWDER(), fn(ConcretePowder $block) => Writer::create(match($block->getColor()){
463 DyeColor::BLACK => Ids::BLACK_CONCRETE_POWDER,
464 DyeColor::BLUE => Ids::BLUE_CONCRETE_POWDER,
465 DyeColor::BROWN => Ids::BROWN_CONCRETE_POWDER,
466 DyeColor::CYAN => Ids::CYAN_CONCRETE_POWDER,
467 DyeColor::GRAY => Ids::GRAY_CONCRETE_POWDER,
468 DyeColor::GREEN => Ids::GREEN_CONCRETE_POWDER,
469 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CONCRETE_POWDER,
470 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CONCRETE_POWDER,
471 DyeColor::LIME => Ids::LIME_CONCRETE_POWDER,
472 DyeColor::MAGENTA => Ids::MAGENTA_CONCRETE_POWDER,
473 DyeColor::ORANGE => Ids::ORANGE_CONCRETE_POWDER,
474 DyeColor::PINK => Ids::PINK_CONCRETE_POWDER,
475 DyeColor::PURPLE => Ids::PURPLE_CONCRETE_POWDER,
476 DyeColor::RED => Ids::RED_CONCRETE_POWDER,
477 DyeColor::WHITE => Ids::WHITE_CONCRETE_POWDER,
478 DyeColor::YELLOW => Ids::YELLOW_CONCRETE_POWDER,
479 }));
480
481 $this->map(Blocks::STAINED_CLAY(), fn(StainedHardenedClay $block) => Writer::create(match($block->getColor()){
482 DyeColor::BLACK => Ids::BLACK_TERRACOTTA,
483 DyeColor::BLUE => Ids::BLUE_TERRACOTTA,
484 DyeColor::BROWN => Ids::BROWN_TERRACOTTA,
485 DyeColor::CYAN => Ids::CYAN_TERRACOTTA,
486 DyeColor::GRAY => Ids::GRAY_TERRACOTTA,
487 DyeColor::GREEN => Ids::GREEN_TERRACOTTA,
488 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_TERRACOTTA,
489 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_TERRACOTTA,
490 DyeColor::LIME => Ids::LIME_TERRACOTTA,
491 DyeColor::MAGENTA => Ids::MAGENTA_TERRACOTTA,
492 DyeColor::ORANGE => Ids::ORANGE_TERRACOTTA,
493 DyeColor::PINK => Ids::PINK_TERRACOTTA,
494 DyeColor::PURPLE => Ids::PURPLE_TERRACOTTA,
495 DyeColor::RED => Ids::RED_TERRACOTTA,
496 DyeColor::WHITE => Ids::WHITE_TERRACOTTA,
497 DyeColor::YELLOW => Ids::YELLOW_TERRACOTTA,
498 }));
499
500 $this->map(Blocks::STAINED_GLASS(), fn(StainedGlass $block) => Writer::create(match($block->getColor()){
501 DyeColor::BLACK => Ids::BLACK_STAINED_GLASS,
502 DyeColor::BLUE => Ids::BLUE_STAINED_GLASS,
503 DyeColor::BROWN => Ids::BROWN_STAINED_GLASS,
504 DyeColor::CYAN => Ids::CYAN_STAINED_GLASS,
505 DyeColor::GRAY => Ids::GRAY_STAINED_GLASS,
506 DyeColor::GREEN => Ids::GREEN_STAINED_GLASS,
507 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_STAINED_GLASS,
508 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_STAINED_GLASS,
509 DyeColor::LIME => Ids::LIME_STAINED_GLASS,
510 DyeColor::MAGENTA => Ids::MAGENTA_STAINED_GLASS,
511 DyeColor::ORANGE => Ids::ORANGE_STAINED_GLASS,
512 DyeColor::PINK => Ids::PINK_STAINED_GLASS,
513 DyeColor::PURPLE => Ids::PURPLE_STAINED_GLASS,
514 DyeColor::RED => Ids::RED_STAINED_GLASS,
515 DyeColor::WHITE => Ids::WHITE_STAINED_GLASS,
516 DyeColor::YELLOW => Ids::YELLOW_STAINED_GLASS,
517 }));
518
519 $this->map(Blocks::STAINED_GLASS_PANE(), fn(StainedGlassPane $block) => Writer::create(match($block->getColor()){
520 DyeColor::BLACK => Ids::BLACK_STAINED_GLASS_PANE,
521 DyeColor::BLUE => Ids::BLUE_STAINED_GLASS_PANE,
522 DyeColor::BROWN => Ids::BROWN_STAINED_GLASS_PANE,
523 DyeColor::CYAN => Ids::CYAN_STAINED_GLASS_PANE,
524 DyeColor::GRAY => Ids::GRAY_STAINED_GLASS_PANE,
525 DyeColor::GREEN => Ids::GREEN_STAINED_GLASS_PANE,
526 DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_STAINED_GLASS_PANE,
527 DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_STAINED_GLASS_PANE,
528 DyeColor::LIME => Ids::LIME_STAINED_GLASS_PANE,
529 DyeColor::MAGENTA => Ids::MAGENTA_STAINED_GLASS_PANE,
530 DyeColor::ORANGE => Ids::ORANGE_STAINED_GLASS_PANE,
531 DyeColor::PINK => Ids::PINK_STAINED_GLASS_PANE,
532 DyeColor::PURPLE => Ids::PURPLE_STAINED_GLASS_PANE,
533 DyeColor::RED => Ids::RED_STAINED_GLASS_PANE,
534 DyeColor::WHITE => Ids::WHITE_STAINED_GLASS_PANE,
535 DyeColor::YELLOW => Ids::YELLOW_STAINED_GLASS_PANE,
536 }));
537 }
538
539 private function registerFlatCoralSerializers() : void{
540 $this->map(Blocks::CORAL(), fn(Coral $block) => Writer::create(
541 match($block->getCoralType()){
542 CoralType::BRAIN => $block->isDead() ? Ids::DEAD_BRAIN_CORAL : Ids::BRAIN_CORAL,
543 CoralType::BUBBLE => $block->isDead() ? Ids::DEAD_BUBBLE_CORAL : Ids::BUBBLE_CORAL,
544 CoralType::FIRE => $block->isDead() ? Ids::DEAD_FIRE_CORAL : Ids::FIRE_CORAL,
545 CoralType::HORN => $block->isDead() ? Ids::DEAD_HORN_CORAL : Ids::HORN_CORAL,
546 CoralType::TUBE => $block->isDead() ? Ids::DEAD_TUBE_CORAL : Ids::TUBE_CORAL,
547 }
548 ));
549
550 $this->map(Blocks::CORAL_FAN(), fn(FloorCoralFan $block) => Writer::create(
551 match($block->getCoralType()){
552 CoralType::BRAIN => $block->isDead() ? Ids::DEAD_BRAIN_CORAL_FAN : Ids::BRAIN_CORAL_FAN,
553 CoralType::BUBBLE => $block->isDead() ? Ids::DEAD_BUBBLE_CORAL_FAN : Ids::BUBBLE_CORAL_FAN,
554 CoralType::FIRE => $block->isDead() ? Ids::DEAD_FIRE_CORAL_FAN : Ids::FIRE_CORAL_FAN,
555 CoralType::HORN => $block->isDead() ? Ids::DEAD_HORN_CORAL_FAN : Ids::HORN_CORAL_FAN,
556 CoralType::TUBE => $block->isDead() ? Ids::DEAD_TUBE_CORAL_FAN : Ids::TUBE_CORAL_FAN,
557 })
558 ->writeInt(StateNames::CORAL_FAN_DIRECTION, match($axis = $block->getAxis()){
559 Axis::X => 0,
560 Axis::Z => 1,
561 default => throw new BlockStateSerializeException("Invalid axis {$axis}"),
562 }));
563
564 $this->map(Blocks::CORAL_BLOCK(), fn(CoralBlock $block) => Writer::create(
565 match($block->getCoralType()){
566 CoralType::BRAIN => $block->isDead() ? Ids::DEAD_BRAIN_CORAL_BLOCK : Ids::BRAIN_CORAL_BLOCK,
567 CoralType::BUBBLE => $block->isDead() ? Ids::DEAD_BUBBLE_CORAL_BLOCK : Ids::BUBBLE_CORAL_BLOCK,
568 CoralType::FIRE => $block->isDead() ? Ids::DEAD_FIRE_CORAL_BLOCK : Ids::FIRE_CORAL_BLOCK,
569 CoralType::HORN => $block->isDead() ? Ids::DEAD_HORN_CORAL_BLOCK : Ids::HORN_CORAL_BLOCK,
570 CoralType::TUBE => $block->isDead() ? Ids::DEAD_TUBE_CORAL_BLOCK : Ids::TUBE_CORAL_BLOCK,
571 }
572 ));
573
574 $this->map(Blocks::WALL_CORAL_FAN(), fn(WallCoralFan $block) => Writer::create(
575 match($block->getCoralType()){
576 CoralType::TUBE => $block->isDead() ? Ids::DEAD_TUBE_CORAL_WALL_FAN : Ids::TUBE_CORAL_WALL_FAN,
577 CoralType::BRAIN => $block->isDead() ? Ids::DEAD_BRAIN_CORAL_WALL_FAN : Ids::BRAIN_CORAL_WALL_FAN,
578 CoralType::BUBBLE => $block->isDead() ? Ids::DEAD_BUBBLE_CORAL_WALL_FAN : Ids::BUBBLE_CORAL_WALL_FAN,
579 CoralType::FIRE => $block->isDead() ? Ids::DEAD_FIRE_CORAL_WALL_FAN : Ids::FIRE_CORAL_WALL_FAN,
580 CoralType::HORN => $block->isDead() ? Ids::DEAD_HORN_CORAL_WALL_FAN : Ids::HORN_CORAL_WALL_FAN,
581 })
582 ->writeCoralFacing($block->getFacing())
583 );
584 }
585
586 private function registerCauldronSerializers() : void{
587 $this->map(Blocks::CAULDRON(), fn() => Helper::encodeCauldron(StringValues::CAULDRON_LIQUID_WATER, 0));
588 $this->map(Blocks::LAVA_CAULDRON(), fn(FillableCauldron $b) => Helper::encodeCauldron(StringValues::CAULDRON_LIQUID_LAVA, $b->getFillLevel()));
589 //potion cauldrons store their real information in the block actor data
590 $this->map(Blocks::POTION_CAULDRON(), fn(FillableCauldron $b) => Helper::encodeCauldron(StringValues::CAULDRON_LIQUID_WATER, $b->getFillLevel()));
591 $this->map(Blocks::WATER_CAULDRON(), fn(FillableCauldron $b) => Helper::encodeCauldron(StringValues::CAULDRON_LIQUID_WATER, $b->getFillLevel()));
592 }
593
594 private function registerFlatWoodBlockSerializers() : void{
595 $this->map(Blocks::ACACIA_BUTTON(), fn(WoodenButton $block) => Helper::encodeButton($block, new Writer(Ids::ACACIA_BUTTON)));
596 $this->map(Blocks::ACACIA_DOOR(), fn(WoodenDoor $block) => Helper::encodeDoor($block, new Writer(Ids::ACACIA_DOOR)));
597 $this->map(Blocks::ACACIA_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::ACACIA_FENCE_GATE)));
598 $this->map(Blocks::ACACIA_PRESSURE_PLATE(), fn(WoodenPressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::ACACIA_PRESSURE_PLATE)));
599 $this->map(Blocks::ACACIA_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::ACACIA_STANDING_SIGN)));
600 $this->map(Blocks::ACACIA_STAIRS(), fn(WoodenStairs $block) => Helper::encodeStairs($block, new Writer(Ids::ACACIA_STAIRS)));
601 $this->map(Blocks::ACACIA_TRAPDOOR(), fn(WoodenTrapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::ACACIA_TRAPDOOR)));
602 $this->map(Blocks::ACACIA_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::ACACIA_WALL_SIGN)));
603 $this->mapLog(Blocks::ACACIA_LOG(), Ids::ACACIA_LOG, Ids::STRIPPED_ACACIA_LOG);
604 $this->mapLog(Blocks::ACACIA_WOOD(), Ids::ACACIA_WOOD, Ids::STRIPPED_ACACIA_WOOD);
605 $this->mapSimple(Blocks::ACACIA_FENCE(), Ids::ACACIA_FENCE);
606 $this->mapSimple(Blocks::ACACIA_PLANKS(), Ids::ACACIA_PLANKS);
607 $this->mapSlab(Blocks::ACACIA_SLAB(), Ids::ACACIA_SLAB, Ids::ACACIA_DOUBLE_SLAB);
608
609 $this->map(Blocks::BIRCH_BUTTON(), fn(WoodenButton $block) => Helper::encodeButton($block, new Writer(Ids::BIRCH_BUTTON)));
610 $this->map(Blocks::BIRCH_DOOR(), fn(WoodenDoor $block) => Helper::encodeDoor($block, new Writer(Ids::BIRCH_DOOR)));
611 $this->map(Blocks::BIRCH_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::BIRCH_FENCE_GATE)));
612 $this->map(Blocks::BIRCH_PRESSURE_PLATE(), fn(WoodenPressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::BIRCH_PRESSURE_PLATE)));
613 $this->map(Blocks::BIRCH_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::BIRCH_STANDING_SIGN)));
614 $this->map(Blocks::BIRCH_TRAPDOOR(), fn(WoodenTrapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::BIRCH_TRAPDOOR)));
615 $this->map(Blocks::BIRCH_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::BIRCH_WALL_SIGN)));
616 $this->mapLog(Blocks::BIRCH_LOG(), Ids::BIRCH_LOG, Ids::STRIPPED_BIRCH_LOG);
617 $this->mapLog(Blocks::BIRCH_WOOD(), Ids::BIRCH_WOOD, Ids::STRIPPED_BIRCH_WOOD);
618 $this->mapSimple(Blocks::BIRCH_FENCE(), Ids::BIRCH_FENCE);
619 $this->mapSimple(Blocks::BIRCH_PLANKS(), Ids::BIRCH_PLANKS);
620 $this->mapSlab(Blocks::BIRCH_SLAB(), Ids::BIRCH_SLAB, Ids::BIRCH_DOUBLE_SLAB);
621 $this->mapStairs(Blocks::BIRCH_STAIRS(), Ids::BIRCH_STAIRS);
622
623 $this->map(Blocks::CHERRY_BUTTON(), fn(Button $block) => Helper::encodeButton($block, new Writer(Ids::CHERRY_BUTTON)));
624 $this->map(Blocks::CHERRY_DOOR(), fn(Door $block) => Helper::encodeDoor($block, new Writer(Ids::CHERRY_DOOR)));
625 $this->map(Blocks::CHERRY_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::CHERRY_FENCE_GATE)));
626 $this->map(Blocks::CHERRY_LOG(), fn(Wood $block) => Helper::encodeLog($block, Ids::CHERRY_LOG, Ids::STRIPPED_CHERRY_LOG));
627 $this->map(Blocks::CHERRY_PRESSURE_PLATE(), fn(SimplePressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::CHERRY_PRESSURE_PLATE)));
628 $this->map(Blocks::CHERRY_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::CHERRY_STANDING_SIGN)));
629 $this->map(Blocks::CHERRY_TRAPDOOR(), fn(Trapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::CHERRY_TRAPDOOR)));
630 $this->map(Blocks::CHERRY_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::CHERRY_WALL_SIGN)));
631 $this->mapSimple(Blocks::CHERRY_FENCE(), Ids::CHERRY_FENCE);
632 $this->mapSimple(Blocks::CHERRY_PLANKS(), Ids::CHERRY_PLANKS);
633 $this->mapSlab(Blocks::CHERRY_SLAB(), Ids::CHERRY_SLAB, Ids::CHERRY_DOUBLE_SLAB);
634 $this->mapStairs(Blocks::CHERRY_STAIRS(), Ids::CHERRY_STAIRS);
635 $this->mapLog(Blocks::CHERRY_WOOD(), Ids::CHERRY_WOOD, Ids::STRIPPED_CHERRY_WOOD);
636
637 $this->map(Blocks::CRIMSON_BUTTON(), fn(Button $block) => Helper::encodeButton($block, new Writer(Ids::CRIMSON_BUTTON)));
638 $this->map(Blocks::CRIMSON_DOOR(), fn(Door $block) => Helper::encodeDoor($block, new Writer(Ids::CRIMSON_DOOR)));
639 $this->map(Blocks::CRIMSON_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::CRIMSON_FENCE_GATE)));
640 $this->map(Blocks::CRIMSON_HYPHAE(), fn(Wood $block) => Helper::encodeLog($block, Ids::CRIMSON_HYPHAE, Ids::STRIPPED_CRIMSON_HYPHAE));
641 $this->map(Blocks::CRIMSON_PRESSURE_PLATE(), fn(SimplePressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::CRIMSON_PRESSURE_PLATE)));
642 $this->map(Blocks::CRIMSON_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::CRIMSON_STANDING_SIGN)));
643 $this->map(Blocks::CRIMSON_STEM(), fn(Wood $block) => Helper::encodeLog($block, Ids::CRIMSON_STEM, Ids::STRIPPED_CRIMSON_STEM));
644 $this->map(Blocks::CRIMSON_TRAPDOOR(), fn(Trapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::CRIMSON_TRAPDOOR)));
645 $this->map(Blocks::CRIMSON_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::CRIMSON_WALL_SIGN)));
646 $this->mapSimple(Blocks::CRIMSON_FENCE(), Ids::CRIMSON_FENCE);
647 $this->mapSimple(Blocks::CRIMSON_PLANKS(), Ids::CRIMSON_PLANKS);
648 $this->mapSlab(Blocks::CRIMSON_SLAB(), Ids::CRIMSON_SLAB, Ids::CRIMSON_DOUBLE_SLAB);
649 $this->mapStairs(Blocks::CRIMSON_STAIRS(), Ids::CRIMSON_STAIRS);
650
651 $this->map(Blocks::DARK_OAK_BUTTON(), fn(WoodenButton $block) => Helper::encodeButton($block, new Writer(Ids::DARK_OAK_BUTTON)));
652 $this->map(Blocks::DARK_OAK_DOOR(), fn(WoodenDoor $block) => Helper::encodeDoor($block, new Writer(Ids::DARK_OAK_DOOR)));
653 $this->map(Blocks::DARK_OAK_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::DARK_OAK_FENCE_GATE)));
654 $this->map(Blocks::DARK_OAK_PRESSURE_PLATE(), fn(WoodenPressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::DARK_OAK_PRESSURE_PLATE)));
655 $this->map(Blocks::DARK_OAK_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::DARKOAK_STANDING_SIGN)));
656 $this->map(Blocks::DARK_OAK_TRAPDOOR(), fn(WoodenTrapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::DARK_OAK_TRAPDOOR)));
657 $this->map(Blocks::DARK_OAK_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::DARKOAK_WALL_SIGN)));
658 $this->mapLog(Blocks::DARK_OAK_LOG(), Ids::DARK_OAK_LOG, Ids::STRIPPED_DARK_OAK_LOG);
659 $this->mapLog(Blocks::DARK_OAK_WOOD(), Ids::DARK_OAK_WOOD, Ids::STRIPPED_DARK_OAK_WOOD);
660 $this->mapSimple(Blocks::DARK_OAK_FENCE(), Ids::DARK_OAK_FENCE);
661 $this->mapSimple(Blocks::DARK_OAK_PLANKS(), Ids::DARK_OAK_PLANKS);
662 $this->mapSlab(Blocks::DARK_OAK_SLAB(), Ids::DARK_OAK_SLAB, Ids::DARK_OAK_DOUBLE_SLAB);
663 $this->mapStairs(Blocks::DARK_OAK_STAIRS(), Ids::DARK_OAK_STAIRS);
664
665 $this->map(Blocks::JUNGLE_BUTTON(), fn(WoodenButton $block) => Helper::encodeButton($block, new Writer(Ids::JUNGLE_BUTTON)));
666 $this->map(Blocks::JUNGLE_DOOR(), fn(WoodenDoor $block) => Helper::encodeDoor($block, new Writer(Ids::JUNGLE_DOOR)));
667 $this->map(Blocks::JUNGLE_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::JUNGLE_FENCE_GATE)));
668 $this->map(Blocks::JUNGLE_PRESSURE_PLATE(), fn(WoodenPressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::JUNGLE_PRESSURE_PLATE)));
669 $this->map(Blocks::JUNGLE_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::JUNGLE_STANDING_SIGN)));
670 $this->map(Blocks::JUNGLE_TRAPDOOR(), fn(WoodenTrapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::JUNGLE_TRAPDOOR)));
671 $this->map(Blocks::JUNGLE_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::JUNGLE_WALL_SIGN)));
672 $this->mapLog(Blocks::JUNGLE_LOG(), Ids::JUNGLE_LOG, Ids::STRIPPED_JUNGLE_LOG);
673 $this->mapLog(Blocks::JUNGLE_WOOD(), Ids::JUNGLE_WOOD, Ids::STRIPPED_JUNGLE_WOOD);
674 $this->mapSimple(Blocks::JUNGLE_FENCE(), Ids::JUNGLE_FENCE);
675 $this->mapSimple(Blocks::JUNGLE_PLANKS(), Ids::JUNGLE_PLANKS);
676 $this->mapSlab(Blocks::JUNGLE_SLAB(), Ids::JUNGLE_SLAB, Ids::JUNGLE_DOUBLE_SLAB);
677 $this->mapStairs(Blocks::JUNGLE_STAIRS(), Ids::JUNGLE_STAIRS);
678
679 $this->map(Blocks::MANGROVE_BUTTON(), fn(Button $block) => Helper::encodeButton($block, new Writer(Ids::MANGROVE_BUTTON)));
680 $this->map(Blocks::MANGROVE_DOOR(), fn(Door $block) => Helper::encodeDoor($block, new Writer(Ids::MANGROVE_DOOR)));
681 $this->map(Blocks::MANGROVE_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::MANGROVE_FENCE_GATE)));
682 $this->map(Blocks::MANGROVE_LOG(), fn(Wood $block) => Helper::encodeLog($block, Ids::MANGROVE_LOG, Ids::STRIPPED_MANGROVE_LOG));
683 $this->map(Blocks::MANGROVE_PRESSURE_PLATE(), fn(SimplePressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::MANGROVE_PRESSURE_PLATE)));
684 $this->map(Blocks::MANGROVE_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::MANGROVE_STANDING_SIGN)));
685 $this->map(Blocks::MANGROVE_TRAPDOOR(), fn(Trapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::MANGROVE_TRAPDOOR)));
686 $this->map(Blocks::MANGROVE_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::MANGROVE_WALL_SIGN)));
687 $this->mapSimple(Blocks::MANGROVE_FENCE(), Ids::MANGROVE_FENCE);
688 $this->mapSimple(Blocks::MANGROVE_PLANKS(), Ids::MANGROVE_PLANKS);
689 $this->mapSlab(Blocks::MANGROVE_SLAB(), Ids::MANGROVE_SLAB, Ids::MANGROVE_DOUBLE_SLAB);
690 $this->mapStairs(Blocks::MANGROVE_STAIRS(), Ids::MANGROVE_STAIRS);
691 $this->mapLog(Blocks::MANGROVE_WOOD(), Ids::MANGROVE_WOOD, Ids::STRIPPED_MANGROVE_WOOD);
692
693 $this->map(Blocks::OAK_BUTTON(), fn(WoodenButton $block) => Helper::encodeButton($block, new Writer(Ids::WOODEN_BUTTON)));
694 $this->map(Blocks::OAK_DOOR(), fn(WoodenDoor $block) => Helper::encodeDoor($block, new Writer(Ids::WOODEN_DOOR)));
695 $this->map(Blocks::OAK_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::FENCE_GATE)));
696 $this->map(Blocks::OAK_PRESSURE_PLATE(), fn(WoodenPressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::WOODEN_PRESSURE_PLATE)));
697 $this->map(Blocks::OAK_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::STANDING_SIGN)));
698 $this->map(Blocks::OAK_TRAPDOOR(), fn(WoodenTrapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::TRAPDOOR)));
699 $this->map(Blocks::OAK_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::WALL_SIGN)));
700 $this->mapLog(Blocks::OAK_LOG(), Ids::OAK_LOG, Ids::STRIPPED_OAK_LOG);
701 $this->mapLog(Blocks::OAK_WOOD(), Ids::OAK_WOOD, Ids::STRIPPED_OAK_WOOD);
702 $this->mapSimple(Blocks::OAK_FENCE(), Ids::OAK_FENCE);
703 $this->mapSimple(Blocks::OAK_PLANKS(), Ids::OAK_PLANKS);
704 $this->mapSlab(Blocks::OAK_SLAB(), Ids::OAK_SLAB, Ids::OAK_DOUBLE_SLAB);
705 $this->mapStairs(Blocks::OAK_STAIRS(), Ids::OAK_STAIRS);
706
707 $this->map(Blocks::PALE_OAK_BUTTON(), fn(WoodenButton $block) => Helper::encodeButton($block, new Writer(Ids::PALE_OAK_BUTTON)));
708 $this->map(Blocks::PALE_OAK_DOOR(), fn(WoodenDoor $block) => Helper::encodeDoor($block, new Writer(Ids::PALE_OAK_DOOR)));
709 $this->map(Blocks::PALE_OAK_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::PALE_OAK_FENCE_GATE)));
710 $this->map(Blocks::PALE_OAK_PRESSURE_PLATE(), fn(WoodenPressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::PALE_OAK_PRESSURE_PLATE)));
711 $this->map(Blocks::PALE_OAK_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::PALE_OAK_STANDING_SIGN)));
712 $this->map(Blocks::PALE_OAK_TRAPDOOR(), fn(WoodenTrapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::PALE_OAK_TRAPDOOR)));
713 $this->map(Blocks::PALE_OAK_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::PALE_OAK_WALL_SIGN)));
714 $this->mapLog(Blocks::PALE_OAK_LOG(), Ids::PALE_OAK_LOG, Ids::STRIPPED_PALE_OAK_LOG);
715 $this->mapLog(Blocks::PALE_OAK_WOOD(), Ids::PALE_OAK_WOOD, Ids::STRIPPED_PALE_OAK_WOOD);
716 $this->mapSimple(Blocks::PALE_OAK_FENCE(), Ids::PALE_OAK_FENCE);
717 $this->mapSimple(Blocks::PALE_OAK_PLANKS(), Ids::PALE_OAK_PLANKS);
718 $this->mapSlab(Blocks::PALE_OAK_SLAB(), Ids::PALE_OAK_SLAB, Ids::PALE_OAK_DOUBLE_SLAB);
719 $this->mapStairs(Blocks::PALE_OAK_STAIRS(), Ids::PALE_OAK_STAIRS);
720
721 $this->map(Blocks::SPRUCE_BUTTON(), fn(WoodenButton $block) => Helper::encodeButton($block, new Writer(Ids::SPRUCE_BUTTON)));
722 $this->map(Blocks::SPRUCE_DOOR(), fn(WoodenDoor $block) => Helper::encodeDoor($block, new Writer(Ids::SPRUCE_DOOR)));
723 $this->map(Blocks::SPRUCE_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::SPRUCE_FENCE_GATE)));
724 $this->map(Blocks::SPRUCE_PRESSURE_PLATE(), fn(WoodenPressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::SPRUCE_PRESSURE_PLATE)));
725 $this->map(Blocks::SPRUCE_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::SPRUCE_STANDING_SIGN)));
726 $this->map(Blocks::SPRUCE_TRAPDOOR(), fn(WoodenTrapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::SPRUCE_TRAPDOOR)));
727 $this->map(Blocks::SPRUCE_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::SPRUCE_WALL_SIGN)));
728 $this->mapLog(Blocks::SPRUCE_LOG(), Ids::SPRUCE_LOG, Ids::STRIPPED_SPRUCE_LOG);
729 $this->mapLog(Blocks::SPRUCE_WOOD(), Ids::SPRUCE_WOOD, Ids::STRIPPED_SPRUCE_WOOD);
730 $this->mapSimple(Blocks::SPRUCE_FENCE(), Ids::SPRUCE_FENCE);
731 $this->mapSimple(Blocks::SPRUCE_PLANKS(), Ids::SPRUCE_PLANKS);
732 $this->mapSlab(Blocks::SPRUCE_SLAB(), Ids::SPRUCE_SLAB, Ids::SPRUCE_DOUBLE_SLAB);
733 $this->mapStairs(Blocks::SPRUCE_STAIRS(), Ids::SPRUCE_STAIRS);
734 //wood and slabs still use the old way of storing wood type
735
736 $this->map(Blocks::WARPED_BUTTON(), fn(Button $block) => Helper::encodeButton($block, new Writer(Ids::WARPED_BUTTON)));
737 $this->map(Blocks::WARPED_DOOR(), fn(Door $block) => Helper::encodeDoor($block, new Writer(Ids::WARPED_DOOR)));
738 $this->map(Blocks::WARPED_FENCE_GATE(), fn(FenceGate $block) => Helper::encodeFenceGate($block, new Writer(Ids::WARPED_FENCE_GATE)));
739 $this->map(Blocks::WARPED_HYPHAE(), fn(Wood $block) => Helper::encodeLog($block, Ids::WARPED_HYPHAE, Ids::STRIPPED_WARPED_HYPHAE));
740 $this->map(Blocks::WARPED_PRESSURE_PLATE(), fn(SimplePressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::WARPED_PRESSURE_PLATE)));
741 $this->map(Blocks::WARPED_SIGN(), fn(FloorSign $block) => Helper::encodeFloorSign($block, new Writer(Ids::WARPED_STANDING_SIGN)));
742 $this->map(Blocks::WARPED_STEM(), fn(Wood $block) => Helper::encodeLog($block, Ids::WARPED_STEM, Ids::STRIPPED_WARPED_STEM));
743 $this->map(Blocks::WARPED_TRAPDOOR(), fn(Trapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::WARPED_TRAPDOOR)));
744 $this->map(Blocks::WARPED_WALL_SIGN(), fn(WallSign $block) => Helper::encodeWallSign($block, new Writer(Ids::WARPED_WALL_SIGN)));
745 $this->mapSimple(Blocks::WARPED_FENCE(), Ids::WARPED_FENCE);
746 $this->mapSimple(Blocks::WARPED_PLANKS(), Ids::WARPED_PLANKS);
747 $this->mapSlab(Blocks::WARPED_SLAB(), Ids::WARPED_SLAB, Ids::WARPED_DOUBLE_SLAB);
748 $this->mapStairs(Blocks::WARPED_STAIRS(), Ids::WARPED_STAIRS);
749 }
750
751 private function registerLeavesSerializers() : void{
752 //flattened IDs
753 $this->map(Blocks::AZALEA_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::AZALEA_LEAVES)));
754 $this->map(Blocks::CHERRY_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::CHERRY_LEAVES)));
755 $this->map(Blocks::FLOWERING_AZALEA_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::AZALEA_LEAVES_FLOWERED)));
756 $this->map(Blocks::MANGROVE_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::MANGROVE_LEAVES)));
757 $this->map(Blocks::PALE_OAK_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::PALE_OAK_LEAVES)));
758
759 //legacy mess
760 $this->map(Blocks::ACACIA_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::ACACIA_LEAVES)));
761 $this->map(Blocks::BIRCH_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::BIRCH_LEAVES)));
762 $this->map(Blocks::DARK_OAK_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::DARK_OAK_LEAVES)));
763 $this->map(Blocks::JUNGLE_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::JUNGLE_LEAVES)));
764 $this->map(Blocks::OAK_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::OAK_LEAVES)));
765 $this->map(Blocks::SPRUCE_LEAVES(), fn(Leaves $block) => Helper::encodeLeaves($block, new Writer(Ids::SPRUCE_LEAVES)));
766 }
767
768 private function registerSaplingSerializers() : void{
769 foreach([
770 Ids::ACACIA_SAPLING => Blocks::ACACIA_SAPLING(),
771 Ids::BIRCH_SAPLING => Blocks::BIRCH_SAPLING(),
772 Ids::DARK_OAK_SAPLING => Blocks::DARK_OAK_SAPLING(),
773 Ids::JUNGLE_SAPLING => Blocks::JUNGLE_SAPLING(),
774 Ids::OAK_SAPLING => Blocks::OAK_SAPLING(),
775 Ids::SPRUCE_SAPLING => Blocks::SPRUCE_SAPLING(),
776 ] as $id => $block){
777 $this->map($block, fn(Sapling $block) => Helper::encodeSapling($block, new Writer($id)));
778 }
779 }
780
781 private function registerMobHeadSerializers() : void{
782 $this->map(Blocks::MOB_HEAD(), fn(MobHead $block) => Writer::create(match ($block->getMobHeadType()){
783 MobHeadType::CREEPER => Ids::CREEPER_HEAD,
784 MobHeadType::DRAGON => Ids::DRAGON_HEAD,
785 MobHeadType::PIGLIN => Ids::PIGLIN_HEAD,
786 MobHeadType::PLAYER => Ids::PLAYER_HEAD,
787 MobHeadType::SKELETON => Ids::SKELETON_SKULL,
788 MobHeadType::WITHER_SKELETON => Ids::WITHER_SKELETON_SKULL,
789 MobHeadType::ZOMBIE => Ids::ZOMBIE_HEAD,
790 })->writeFacingWithoutDown($block->getFacing()));
791 }
792
793 private function registerSimpleSerializers() : void{
794 $this->mapSimple(Blocks::AIR(), Ids::AIR);
795 $this->mapSimple(Blocks::AMETHYST(), Ids::AMETHYST_BLOCK);
796 $this->mapSimple(Blocks::ANCIENT_DEBRIS(), Ids::ANCIENT_DEBRIS);
797 $this->mapSimple(Blocks::ANDESITE(), Ids::ANDESITE);
798 $this->mapSimple(Blocks::BARRIER(), Ids::BARRIER);
799 $this->mapSimple(Blocks::BEACON(), Ids::BEACON);
800 $this->mapSimple(Blocks::BLACKSTONE(), Ids::BLACKSTONE);
801 $this->mapSimple(Blocks::BLUE_ICE(), Ids::BLUE_ICE);
802 $this->mapSimple(Blocks::BOOKSHELF(), Ids::BOOKSHELF);
803 $this->mapSimple(Blocks::BRICKS(), Ids::BRICK_BLOCK);
804 $this->mapSimple(Blocks::BROWN_MUSHROOM(), Ids::BROWN_MUSHROOM);
805 $this->mapSimple(Blocks::BUDDING_AMETHYST(), Ids::BUDDING_AMETHYST);
806 $this->mapSimple(Blocks::CALCITE(), Ids::CALCITE);
807 $this->mapSimple(Blocks::CARTOGRAPHY_TABLE(), Ids::CARTOGRAPHY_TABLE);
808 $this->mapSimple(Blocks::CHEMICAL_HEAT(), Ids::CHEMICAL_HEAT);
809 $this->mapSimple(Blocks::CHISELED_DEEPSLATE(), Ids::CHISELED_DEEPSLATE);
810 $this->mapSimple(Blocks::CHISELED_NETHER_BRICKS(), Ids::CHISELED_NETHER_BRICKS);
811 $this->mapSimple(Blocks::CHISELED_POLISHED_BLACKSTONE(), Ids::CHISELED_POLISHED_BLACKSTONE);
812 $this->mapSimple(Blocks::CHISELED_RED_SANDSTONE(), Ids::CHISELED_RED_SANDSTONE);
813 $this->mapSimple(Blocks::CHISELED_RESIN_BRICKS(), Ids::CHISELED_RESIN_BRICKS);
814 $this->mapSimple(Blocks::CHISELED_SANDSTONE(), Ids::CHISELED_SANDSTONE);
815 $this->mapSimple(Blocks::CHISELED_STONE_BRICKS(), Ids::CHISELED_STONE_BRICKS);
816 $this->mapSimple(Blocks::CHISELED_TUFF(), Ids::CHISELED_TUFF);
817 $this->mapSimple(Blocks::CHISELED_TUFF_BRICKS(), Ids::CHISELED_TUFF_BRICKS);
818 $this->mapSimple(Blocks::CHORUS_PLANT(), Ids::CHORUS_PLANT);
819 $this->mapSimple(Blocks::CLAY(), Ids::CLAY);
820 $this->mapSimple(Blocks::COAL(), Ids::COAL_BLOCK);
821 $this->mapSimple(Blocks::COAL_ORE(), Ids::COAL_ORE);
822 $this->mapSimple(Blocks::COBBLED_DEEPSLATE(), Ids::COBBLED_DEEPSLATE);
823 $this->mapSimple(Blocks::COBBLESTONE(), Ids::COBBLESTONE);
824 $this->mapSimple(Blocks::COBWEB(), Ids::WEB);
825 $this->mapSimple(Blocks::COPPER_ORE(), Ids::COPPER_ORE);
826 $this->mapSimple(Blocks::CRACKED_DEEPSLATE_BRICKS(), Ids::CRACKED_DEEPSLATE_BRICKS);
827 $this->mapSimple(Blocks::CRACKED_DEEPSLATE_TILES(), Ids::CRACKED_DEEPSLATE_TILES);
828 $this->mapSimple(Blocks::CRACKED_NETHER_BRICKS(), Ids::CRACKED_NETHER_BRICKS);
829 $this->mapSimple(Blocks::CRACKED_POLISHED_BLACKSTONE_BRICKS(), Ids::CRACKED_POLISHED_BLACKSTONE_BRICKS);
830 $this->mapSimple(Blocks::CRACKED_STONE_BRICKS(), Ids::CRACKED_STONE_BRICKS);
831 $this->mapSimple(Blocks::CRAFTING_TABLE(), Ids::CRAFTING_TABLE);
832 $this->mapSimple(Blocks::CRIMSON_ROOTS(), Ids::CRIMSON_ROOTS);
833 $this->mapSimple(Blocks::CRYING_OBSIDIAN(), Ids::CRYING_OBSIDIAN);
834 $this->mapSimple(Blocks::DANDELION(), Ids::DANDELION);
835 $this->mapSimple(Blocks::CUT_RED_SANDSTONE(), Ids::CUT_RED_SANDSTONE);
836 $this->mapSimple(Blocks::CUT_SANDSTONE(), Ids::CUT_SANDSTONE);
837 $this->mapSimple(Blocks::DARK_PRISMARINE(), Ids::DARK_PRISMARINE);
838 $this->mapSimple(Blocks::DEAD_BUSH(), Ids::DEADBUSH);
839 $this->mapSimple(Blocks::DEEPSLATE_BRICKS(), Ids::DEEPSLATE_BRICKS);
840 $this->mapSimple(Blocks::DEEPSLATE_COAL_ORE(), Ids::DEEPSLATE_COAL_ORE);
841 $this->mapSimple(Blocks::DEEPSLATE_COPPER_ORE(), Ids::DEEPSLATE_COPPER_ORE);
842 $this->mapSimple(Blocks::DEEPSLATE_DIAMOND_ORE(), Ids::DEEPSLATE_DIAMOND_ORE);
843 $this->mapSimple(Blocks::DEEPSLATE_EMERALD_ORE(), Ids::DEEPSLATE_EMERALD_ORE);
844 $this->mapSimple(Blocks::DEEPSLATE_GOLD_ORE(), Ids::DEEPSLATE_GOLD_ORE);
845 $this->mapSimple(Blocks::DEEPSLATE_IRON_ORE(), Ids::DEEPSLATE_IRON_ORE);
846 $this->mapSimple(Blocks::DEEPSLATE_LAPIS_LAZULI_ORE(), Ids::DEEPSLATE_LAPIS_ORE);
847 $this->mapSimple(Blocks::DEEPSLATE_TILES(), Ids::DEEPSLATE_TILES);
848 $this->mapSimple(Blocks::DIAMOND(), Ids::DIAMOND_BLOCK);
849 $this->mapSimple(Blocks::DIAMOND_ORE(), Ids::DIAMOND_ORE);
850 $this->mapSimple(Blocks::DIORITE(), Ids::DIORITE);
851 $this->mapSimple(Blocks::DRAGON_EGG(), Ids::DRAGON_EGG);
852 $this->mapSimple(Blocks::DRIED_KELP(), Ids::DRIED_KELP_BLOCK);
853 $this->mapSimple(Blocks::ELEMENT_ACTINIUM(), Ids::ELEMENT_89);
854 $this->mapSimple(Blocks::ELEMENT_ALUMINUM(), Ids::ELEMENT_13);
855 $this->mapSimple(Blocks::ELEMENT_AMERICIUM(), Ids::ELEMENT_95);
856 $this->mapSimple(Blocks::ELEMENT_ANTIMONY(), Ids::ELEMENT_51);
857 $this->mapSimple(Blocks::ELEMENT_ARGON(), Ids::ELEMENT_18);
858 $this->mapSimple(Blocks::ELEMENT_ARSENIC(), Ids::ELEMENT_33);
859 $this->mapSimple(Blocks::ELEMENT_ASTATINE(), Ids::ELEMENT_85);
860 $this->mapSimple(Blocks::ELEMENT_BARIUM(), Ids::ELEMENT_56);
861 $this->mapSimple(Blocks::ELEMENT_BERKELIUM(), Ids::ELEMENT_97);
862 $this->mapSimple(Blocks::ELEMENT_BERYLLIUM(), Ids::ELEMENT_4);
863 $this->mapSimple(Blocks::ELEMENT_BISMUTH(), Ids::ELEMENT_83);
864 $this->mapSimple(Blocks::ELEMENT_BOHRIUM(), Ids::ELEMENT_107);
865 $this->mapSimple(Blocks::ELEMENT_BORON(), Ids::ELEMENT_5);
866 $this->mapSimple(Blocks::ELEMENT_BROMINE(), Ids::ELEMENT_35);
867 $this->mapSimple(Blocks::ELEMENT_CADMIUM(), Ids::ELEMENT_48);
868 $this->mapSimple(Blocks::ELEMENT_CALCIUM(), Ids::ELEMENT_20);
869 $this->mapSimple(Blocks::ELEMENT_CALIFORNIUM(), Ids::ELEMENT_98);
870 $this->mapSimple(Blocks::ELEMENT_CARBON(), Ids::ELEMENT_6);
871 $this->mapSimple(Blocks::ELEMENT_CERIUM(), Ids::ELEMENT_58);
872 $this->mapSimple(Blocks::ELEMENT_CESIUM(), Ids::ELEMENT_55);
873 $this->mapSimple(Blocks::ELEMENT_CHLORINE(), Ids::ELEMENT_17);
874 $this->mapSimple(Blocks::ELEMENT_CHROMIUM(), Ids::ELEMENT_24);
875 $this->mapSimple(Blocks::ELEMENT_COBALT(), Ids::ELEMENT_27);
876 $this->mapSimple(Blocks::ELEMENT_COPERNICIUM(), Ids::ELEMENT_112);
877 $this->mapSimple(Blocks::ELEMENT_COPPER(), Ids::ELEMENT_29);
878 $this->mapSimple(Blocks::ELEMENT_CURIUM(), Ids::ELEMENT_96);
879 $this->mapSimple(Blocks::ELEMENT_DARMSTADTIUM(), Ids::ELEMENT_110);
880 $this->mapSimple(Blocks::ELEMENT_DUBNIUM(), Ids::ELEMENT_105);
881 $this->mapSimple(Blocks::ELEMENT_DYSPROSIUM(), Ids::ELEMENT_66);
882 $this->mapSimple(Blocks::ELEMENT_EINSTEINIUM(), Ids::ELEMENT_99);
883 $this->mapSimple(Blocks::ELEMENT_ERBIUM(), Ids::ELEMENT_68);
884 $this->mapSimple(Blocks::ELEMENT_EUROPIUM(), Ids::ELEMENT_63);
885 $this->mapSimple(Blocks::ELEMENT_FERMIUM(), Ids::ELEMENT_100);
886 $this->mapSimple(Blocks::ELEMENT_FLEROVIUM(), Ids::ELEMENT_114);
887 $this->mapSimple(Blocks::ELEMENT_FLUORINE(), Ids::ELEMENT_9);
888 $this->mapSimple(Blocks::ELEMENT_FRANCIUM(), Ids::ELEMENT_87);
889 $this->mapSimple(Blocks::ELEMENT_GADOLINIUM(), Ids::ELEMENT_64);
890 $this->mapSimple(Blocks::ELEMENT_GALLIUM(), Ids::ELEMENT_31);
891 $this->mapSimple(Blocks::ELEMENT_GERMANIUM(), Ids::ELEMENT_32);
892 $this->mapSimple(Blocks::ELEMENT_GOLD(), Ids::ELEMENT_79);
893 $this->mapSimple(Blocks::ELEMENT_HAFNIUM(), Ids::ELEMENT_72);
894 $this->mapSimple(Blocks::ELEMENT_HASSIUM(), Ids::ELEMENT_108);
895 $this->mapSimple(Blocks::ELEMENT_HELIUM(), Ids::ELEMENT_2);
896 $this->mapSimple(Blocks::ELEMENT_HOLMIUM(), Ids::ELEMENT_67);
897 $this->mapSimple(Blocks::ELEMENT_HYDROGEN(), Ids::ELEMENT_1);
898 $this->mapSimple(Blocks::ELEMENT_INDIUM(), Ids::ELEMENT_49);
899 $this->mapSimple(Blocks::ELEMENT_IODINE(), Ids::ELEMENT_53);
900 $this->mapSimple(Blocks::ELEMENT_IRIDIUM(), Ids::ELEMENT_77);
901 $this->mapSimple(Blocks::ELEMENT_IRON(), Ids::ELEMENT_26);
902 $this->mapSimple(Blocks::ELEMENT_KRYPTON(), Ids::ELEMENT_36);
903 $this->mapSimple(Blocks::ELEMENT_LANTHANUM(), Ids::ELEMENT_57);
904 $this->mapSimple(Blocks::ELEMENT_LAWRENCIUM(), Ids::ELEMENT_103);
905 $this->mapSimple(Blocks::ELEMENT_LEAD(), Ids::ELEMENT_82);
906 $this->mapSimple(Blocks::ELEMENT_LITHIUM(), Ids::ELEMENT_3);
907 $this->mapSimple(Blocks::ELEMENT_LIVERMORIUM(), Ids::ELEMENT_116);
908 $this->mapSimple(Blocks::ELEMENT_LUTETIUM(), Ids::ELEMENT_71);
909 $this->mapSimple(Blocks::ELEMENT_MAGNESIUM(), Ids::ELEMENT_12);
910 $this->mapSimple(Blocks::ELEMENT_MANGANESE(), Ids::ELEMENT_25);
911 $this->mapSimple(Blocks::ELEMENT_MEITNERIUM(), Ids::ELEMENT_109);
912 $this->mapSimple(Blocks::ELEMENT_MENDELEVIUM(), Ids::ELEMENT_101);
913 $this->mapSimple(Blocks::ELEMENT_MERCURY(), Ids::ELEMENT_80);
914 $this->mapSimple(Blocks::ELEMENT_MOLYBDENUM(), Ids::ELEMENT_42);
915 $this->mapSimple(Blocks::ELEMENT_MOSCOVIUM(), Ids::ELEMENT_115);
916 $this->mapSimple(Blocks::ELEMENT_NEODYMIUM(), Ids::ELEMENT_60);
917 $this->mapSimple(Blocks::ELEMENT_NEON(), Ids::ELEMENT_10);
918 $this->mapSimple(Blocks::ELEMENT_NEPTUNIUM(), Ids::ELEMENT_93);
919 $this->mapSimple(Blocks::ELEMENT_NICKEL(), Ids::ELEMENT_28);
920 $this->mapSimple(Blocks::ELEMENT_NIHONIUM(), Ids::ELEMENT_113);
921 $this->mapSimple(Blocks::ELEMENT_NIOBIUM(), Ids::ELEMENT_41);
922 $this->mapSimple(Blocks::ELEMENT_NITROGEN(), Ids::ELEMENT_7);
923 $this->mapSimple(Blocks::ELEMENT_NOBELIUM(), Ids::ELEMENT_102);
924 $this->mapSimple(Blocks::ELEMENT_OGANESSON(), Ids::ELEMENT_118);
925 $this->mapSimple(Blocks::ELEMENT_OSMIUM(), Ids::ELEMENT_76);
926 $this->mapSimple(Blocks::ELEMENT_OXYGEN(), Ids::ELEMENT_8);
927 $this->mapSimple(Blocks::ELEMENT_PALLADIUM(), Ids::ELEMENT_46);
928 $this->mapSimple(Blocks::ELEMENT_PHOSPHORUS(), Ids::ELEMENT_15);
929 $this->mapSimple(Blocks::ELEMENT_PLATINUM(), Ids::ELEMENT_78);
930 $this->mapSimple(Blocks::ELEMENT_PLUTONIUM(), Ids::ELEMENT_94);
931 $this->mapSimple(Blocks::ELEMENT_POLONIUM(), Ids::ELEMENT_84);
932 $this->mapSimple(Blocks::ELEMENT_POTASSIUM(), Ids::ELEMENT_19);
933 $this->mapSimple(Blocks::ELEMENT_PRASEODYMIUM(), Ids::ELEMENT_59);
934 $this->mapSimple(Blocks::ELEMENT_PROMETHIUM(), Ids::ELEMENT_61);
935 $this->mapSimple(Blocks::ELEMENT_PROTACTINIUM(), Ids::ELEMENT_91);
936 $this->mapSimple(Blocks::ELEMENT_RADIUM(), Ids::ELEMENT_88);
937 $this->mapSimple(Blocks::ELEMENT_RADON(), Ids::ELEMENT_86);
938 $this->mapSimple(Blocks::ELEMENT_RHENIUM(), Ids::ELEMENT_75);
939 $this->mapSimple(Blocks::ELEMENT_RHODIUM(), Ids::ELEMENT_45);
940 $this->mapSimple(Blocks::ELEMENT_ROENTGENIUM(), Ids::ELEMENT_111);
941 $this->mapSimple(Blocks::ELEMENT_RUBIDIUM(), Ids::ELEMENT_37);
942 $this->mapSimple(Blocks::ELEMENT_RUTHENIUM(), Ids::ELEMENT_44);
943 $this->mapSimple(Blocks::ELEMENT_RUTHERFORDIUM(), Ids::ELEMENT_104);
944 $this->mapSimple(Blocks::ELEMENT_SAMARIUM(), Ids::ELEMENT_62);
945 $this->mapSimple(Blocks::ELEMENT_SCANDIUM(), Ids::ELEMENT_21);
946 $this->mapSimple(Blocks::ELEMENT_SEABORGIUM(), Ids::ELEMENT_106);
947 $this->mapSimple(Blocks::ELEMENT_SELENIUM(), Ids::ELEMENT_34);
948 $this->mapSimple(Blocks::ELEMENT_SILICON(), Ids::ELEMENT_14);
949 $this->mapSimple(Blocks::ELEMENT_SILVER(), Ids::ELEMENT_47);
950 $this->mapSimple(Blocks::ELEMENT_SODIUM(), Ids::ELEMENT_11);
951 $this->mapSimple(Blocks::ELEMENT_STRONTIUM(), Ids::ELEMENT_38);
952 $this->mapSimple(Blocks::ELEMENT_SULFUR(), Ids::ELEMENT_16);
953 $this->mapSimple(Blocks::ELEMENT_TANTALUM(), Ids::ELEMENT_73);
954 $this->mapSimple(Blocks::ELEMENT_TECHNETIUM(), Ids::ELEMENT_43);
955 $this->mapSimple(Blocks::ELEMENT_TELLURIUM(), Ids::ELEMENT_52);
956 $this->mapSimple(Blocks::ELEMENT_TENNESSINE(), Ids::ELEMENT_117);
957 $this->mapSimple(Blocks::ELEMENT_TERBIUM(), Ids::ELEMENT_65);
958 $this->mapSimple(Blocks::ELEMENT_THALLIUM(), Ids::ELEMENT_81);
959 $this->mapSimple(Blocks::ELEMENT_THORIUM(), Ids::ELEMENT_90);
960 $this->mapSimple(Blocks::ELEMENT_THULIUM(), Ids::ELEMENT_69);
961 $this->mapSimple(Blocks::ELEMENT_TIN(), Ids::ELEMENT_50);
962 $this->mapSimple(Blocks::ELEMENT_TITANIUM(), Ids::ELEMENT_22);
963 $this->mapSimple(Blocks::ELEMENT_TUNGSTEN(), Ids::ELEMENT_74);
964 $this->mapSimple(Blocks::ELEMENT_URANIUM(), Ids::ELEMENT_92);
965 $this->mapSimple(Blocks::ELEMENT_VANADIUM(), Ids::ELEMENT_23);
966 $this->mapSimple(Blocks::ELEMENT_XENON(), Ids::ELEMENT_54);
967 $this->mapSimple(Blocks::ELEMENT_YTTERBIUM(), Ids::ELEMENT_70);
968 $this->mapSimple(Blocks::ELEMENT_YTTRIUM(), Ids::ELEMENT_39);
969 $this->mapSimple(Blocks::ELEMENT_ZERO(), Ids::ELEMENT_0);
970 $this->mapSimple(Blocks::ELEMENT_ZINC(), Ids::ELEMENT_30);
971 $this->mapSimple(Blocks::ELEMENT_ZIRCONIUM(), Ids::ELEMENT_40);
972 $this->mapSimple(Blocks::EMERALD(), Ids::EMERALD_BLOCK);
973 $this->mapSimple(Blocks::EMERALD_ORE(), Ids::EMERALD_ORE);
974 $this->mapSimple(Blocks::ENCHANTING_TABLE(), Ids::ENCHANTING_TABLE);
975 $this->mapSimple(Blocks::END_STONE(), Ids::END_STONE);
976 $this->mapSimple(Blocks::END_STONE_BRICKS(), Ids::END_BRICKS);
977 $this->mapSimple(Blocks::FERN(), Ids::FERN);
978 $this->mapSimple(Blocks::FLETCHING_TABLE(), Ids::FLETCHING_TABLE);
979 $this->mapSimple(Blocks::GILDED_BLACKSTONE(), Ids::GILDED_BLACKSTONE);
980 $this->mapSimple(Blocks::GLASS(), Ids::GLASS);
981 $this->mapSimple(Blocks::GLASS_PANE(), Ids::GLASS_PANE);
982 $this->mapSimple(Blocks::GLOWING_OBSIDIAN(), Ids::GLOWINGOBSIDIAN);
983 $this->mapSimple(Blocks::GLOWSTONE(), Ids::GLOWSTONE);
984 $this->mapSimple(Blocks::GOLD(), Ids::GOLD_BLOCK);
985 $this->mapSimple(Blocks::GOLD_ORE(), Ids::GOLD_ORE);
986 $this->mapSimple(Blocks::GRANITE(), Ids::GRANITE);
987 $this->mapSimple(Blocks::GRASS(), Ids::GRASS_BLOCK);
988 $this->mapSimple(Blocks::GRASS_PATH(), Ids::GRASS_PATH);
989 $this->mapSimple(Blocks::GRAVEL(), Ids::GRAVEL);
990 $this->mapSimple(Blocks::HANGING_ROOTS(), Ids::HANGING_ROOTS);
991 $this->mapSimple(Blocks::HARDENED_CLAY(), Ids::HARDENED_CLAY);
992 $this->mapSimple(Blocks::HARDENED_GLASS(), Ids::HARD_GLASS);
993 $this->mapSimple(Blocks::HARDENED_GLASS_PANE(), Ids::HARD_GLASS_PANE);
994 $this->mapSimple(Blocks::HONEYCOMB(), Ids::HONEYCOMB_BLOCK);
995 $this->mapSimple(Blocks::ICE(), Ids::ICE);
996 $this->mapSimple(Blocks::INFESTED_CHISELED_STONE_BRICK(), Ids::INFESTED_CHISELED_STONE_BRICKS);
997 $this->mapSimple(Blocks::INFESTED_COBBLESTONE(), Ids::INFESTED_COBBLESTONE);
998 $this->mapSimple(Blocks::INFESTED_CRACKED_STONE_BRICK(), Ids::INFESTED_CRACKED_STONE_BRICKS);
999 $this->mapSimple(Blocks::INFESTED_MOSSY_STONE_BRICK(), Ids::INFESTED_MOSSY_STONE_BRICKS);
1000 $this->mapSimple(Blocks::INFESTED_STONE(), Ids::INFESTED_STONE);
1001 $this->mapSimple(Blocks::INFESTED_STONE_BRICK(), Ids::INFESTED_STONE_BRICKS);
1002 $this->mapSimple(Blocks::INFO_UPDATE(), Ids::INFO_UPDATE);
1003 $this->mapSimple(Blocks::INFO_UPDATE2(), Ids::INFO_UPDATE2);
1004 $this->mapSimple(Blocks::INVISIBLE_BEDROCK(), Ids::INVISIBLE_BEDROCK);
1005 $this->mapSimple(Blocks::IRON(), Ids::IRON_BLOCK);
1006 $this->mapSimple(Blocks::IRON_BARS(), Ids::IRON_BARS);
1007 $this->mapSimple(Blocks::IRON_ORE(), Ids::IRON_ORE);
1008 $this->mapSimple(Blocks::JUKEBOX(), Ids::JUKEBOX);
1009 $this->mapSimple(Blocks::LAPIS_LAZULI(), Ids::LAPIS_BLOCK);
1010 $this->mapSimple(Blocks::LAPIS_LAZULI_ORE(), Ids::LAPIS_ORE);
1011 $this->mapSimple(Blocks::LEGACY_STONECUTTER(), Ids::STONECUTTER);
1012 $this->mapSimple(Blocks::LILY_PAD(), Ids::WATERLILY);
1013 $this->mapSimple(Blocks::MAGMA(), Ids::MAGMA);
1014 $this->mapSimple(Blocks::MANGROVE_ROOTS(), Ids::MANGROVE_ROOTS);
1015 $this->mapSimple(Blocks::MELON(), Ids::MELON_BLOCK);
1016 $this->mapSimple(Blocks::MONSTER_SPAWNER(), Ids::MOB_SPAWNER);
1017 $this->mapSimple(Blocks::MOSSY_COBBLESTONE(), Ids::MOSSY_COBBLESTONE);
1018 $this->mapSimple(Blocks::MOSSY_STONE_BRICKS(), Ids::MOSSY_STONE_BRICKS);
1019 $this->mapSimple(Blocks::MUD(), Ids::MUD);
1020 $this->mapSimple(Blocks::MUD_BRICKS(), Ids::MUD_BRICKS);
1021 $this->mapSimple(Blocks::MYCELIUM(), Ids::MYCELIUM);
1022 $this->mapSimple(Blocks::NETHERITE(), Ids::NETHERITE_BLOCK);
1023 $this->mapSimple(Blocks::NETHERRACK(), Ids::NETHERRACK);
1024 $this->mapSimple(Blocks::NETHER_BRICKS(), Ids::NETHER_BRICK);
1025 $this->mapSimple(Blocks::NETHER_BRICK_FENCE(), Ids::NETHER_BRICK_FENCE);
1026 $this->mapSimple(Blocks::NETHER_GOLD_ORE(), Ids::NETHER_GOLD_ORE);
1027 $this->mapSimple(Blocks::NETHER_QUARTZ_ORE(), Ids::QUARTZ_ORE);
1028 $this->mapSimple(Blocks::NETHER_REACTOR_CORE(), Ids::NETHERREACTOR);
1029 $this->mapSimple(Blocks::NETHER_WART_BLOCK(), Ids::NETHER_WART_BLOCK);
1030 $this->mapSimple(Blocks::NOTE_BLOCK(), Ids::NOTEBLOCK);
1031 $this->mapSimple(Blocks::OBSIDIAN(), Ids::OBSIDIAN);
1032 $this->mapSimple(Blocks::PACKED_ICE(), Ids::PACKED_ICE);
1033 $this->mapSimple(Blocks::PACKED_MUD(), Ids::PACKED_MUD);
1034 $this->mapSimple(Blocks::PODZOL(), Ids::PODZOL);
1035 $this->mapSimple(Blocks::POLISHED_ANDESITE(), Ids::POLISHED_ANDESITE);
1036 $this->mapSimple(Blocks::POLISHED_BLACKSTONE(), Ids::POLISHED_BLACKSTONE);
1037 $this->mapSimple(Blocks::POLISHED_BLACKSTONE_BRICKS(), Ids::POLISHED_BLACKSTONE_BRICKS);
1038 $this->mapSimple(Blocks::POLISHED_DEEPSLATE(), Ids::POLISHED_DEEPSLATE);
1039 $this->mapSimple(Blocks::POLISHED_DIORITE(), Ids::POLISHED_DIORITE);
1040 $this->mapSimple(Blocks::POLISHED_GRANITE(), Ids::POLISHED_GRANITE);
1041 $this->mapSimple(Blocks::POLISHED_TUFF(), Ids::POLISHED_TUFF);
1042 $this->mapSimple(Blocks::PRISMARINE(), Ids::PRISMARINE);
1043 $this->mapSimple(Blocks::PRISMARINE_BRICKS(), Ids::PRISMARINE_BRICKS);
1044 $this->mapSimple(Blocks::QUARTZ_BRICKS(), Ids::QUARTZ_BRICKS);
1045 $this->mapSimple(Blocks::RAW_COPPER(), Ids::RAW_COPPER_BLOCK);
1046 $this->mapSimple(Blocks::RAW_GOLD(), Ids::RAW_GOLD_BLOCK);
1047 $this->mapSimple(Blocks::RAW_IRON(), Ids::RAW_IRON_BLOCK);
1048 $this->mapSimple(Blocks::REDSTONE(), Ids::REDSTONE_BLOCK);
1049 $this->mapSimple(Blocks::RED_MUSHROOM(), Ids::RED_MUSHROOM);
1050 $this->mapSimple(Blocks::RED_NETHER_BRICKS(), Ids::RED_NETHER_BRICK);
1051 $this->mapSimple(Blocks::RED_SAND(), Ids::RED_SAND);
1052 $this->mapSimple(Blocks::RED_SANDSTONE(), Ids::RED_SANDSTONE);
1053 $this->mapSimple(Blocks::REINFORCED_DEEPSLATE(), Ids::REINFORCED_DEEPSLATE);
1054 $this->mapSimple(Blocks::RESERVED6(), Ids::RESERVED6);
1055 $this->mapSimple(Blocks::RESIN(), Ids::RESIN_BLOCK);
1056 $this->mapSimple(Blocks::RESIN_BRICKS(), Ids::RESIN_BRICKS);
1057 $this->mapSimple(Blocks::SAND(), Ids::SAND);
1058 $this->mapSimple(Blocks::SANDSTONE(), Ids::SANDSTONE);
1059 $this->mapSimple(Blocks::SCULK(), Ids::SCULK);
1060 $this->mapSimple(Blocks::SEA_LANTERN(), Ids::SEA_LANTERN);
1061 $this->mapSimple(Blocks::SHROOMLIGHT(), Ids::SHROOMLIGHT);
1062 $this->mapSimple(Blocks::SHULKER_BOX(), Ids::UNDYED_SHULKER_BOX);
1063 $this->mapSimple(Blocks::SLIME(), Ids::SLIME);
1064 $this->mapSimple(Blocks::SMITHING_TABLE(), Ids::SMITHING_TABLE);
1065 $this->mapSimple(Blocks::SMOOTH_BASALT(), Ids::SMOOTH_BASALT);
1066 $this->mapSimple(Blocks::SMOOTH_RED_SANDSTONE(), Ids::SMOOTH_RED_SANDSTONE);
1067 $this->mapSimple(Blocks::SMOOTH_SANDSTONE(), Ids::SMOOTH_SANDSTONE);
1068 $this->mapSimple(Blocks::SMOOTH_STONE(), Ids::SMOOTH_STONE);
1069 $this->mapSimple(Blocks::SNOW(), Ids::SNOW);
1070 $this->mapSimple(Blocks::SOUL_SAND(), Ids::SOUL_SAND);
1071 $this->mapSimple(Blocks::SOUL_SOIL(), Ids::SOUL_SOIL);
1072 $this->mapSimple(Blocks::SPORE_BLOSSOM(), Ids::SPORE_BLOSSOM);
1073 $this->mapSimple(Blocks::STONE(), Ids::STONE);
1074 $this->mapSimple(Blocks::STONE_BRICKS(), Ids::STONE_BRICKS);
1075 $this->mapSimple(Blocks::TALL_GRASS(), Ids::SHORT_GRASS); //no, this is not a typo - tall_grass is now the double block, just to be confusing :(
1076 $this->mapSimple(Blocks::TINTED_GLASS(), Ids::TINTED_GLASS);
1077 $this->mapSimple(Blocks::TORCHFLOWER(), Ids::TORCHFLOWER);
1078 $this->mapSimple(Blocks::TUFF(), Ids::TUFF);
1079 $this->mapSimple(Blocks::TUFF_BRICKS(), Ids::TUFF_BRICKS);
1080 $this->mapSimple(Blocks::WARPED_WART_BLOCK(), Ids::WARPED_WART_BLOCK);
1081 $this->mapSimple(Blocks::WARPED_ROOTS(), Ids::WARPED_ROOTS);
1082 $this->mapSimple(Blocks::WITHER_ROSE(), Ids::WITHER_ROSE);
1083
1084 $this->mapSimple(Blocks::ALLIUM(), Ids::ALLIUM);
1085 $this->mapSimple(Blocks::CORNFLOWER(), Ids::CORNFLOWER);
1086 $this->mapSimple(Blocks::AZURE_BLUET(), Ids::AZURE_BLUET);
1087 $this->mapSimple(Blocks::LILY_OF_THE_VALLEY(), Ids::LILY_OF_THE_VALLEY);
1088 $this->mapSimple(Blocks::BLUE_ORCHID(), Ids::BLUE_ORCHID);
1089 $this->mapSimple(Blocks::OXEYE_DAISY(), Ids::OXEYE_DAISY);
1090 $this->mapSimple(Blocks::POPPY(), Ids::POPPY);
1091 $this->mapSimple(Blocks::ORANGE_TULIP(), Ids::ORANGE_TULIP);
1092 $this->mapSimple(Blocks::PINK_TULIP(), Ids::PINK_TULIP);
1093 $this->mapSimple(Blocks::RED_TULIP(), Ids::RED_TULIP);
1094 $this->mapSimple(Blocks::WHITE_TULIP(), Ids::WHITE_TULIP);
1095 }
1096
1097 private function registerSerializers() : void{
1098 $this->map(Blocks::ACTIVATOR_RAIL(), function(ActivatorRail $block) : Writer{
1099 return Writer::create(Ids::ACTIVATOR_RAIL)
1100 ->writeBool(StateNames::RAIL_DATA_BIT, $block->isPowered())
1101 ->writeInt(StateNames::RAIL_DIRECTION, $block->getShape());
1102 });
1103 $this->map(Blocks::ALL_SIDED_MUSHROOM_STEM(), fn() => Writer::create(Ids::MUSHROOM_STEM)
1104 ->writeInt(StateNames::HUGE_MUSHROOM_BITS, BlockLegacyMetadata::MUSHROOM_BLOCK_ALL_STEM));
1105 $this->map(Blocks::AMETHYST_CLUSTER(), fn(AmethystCluster $block) => Writer::create(
1106 match($stage = $block->getStage()){
1107 AmethystCluster::STAGE_SMALL_BUD => Ids::SMALL_AMETHYST_BUD,
1108 AmethystCluster::STAGE_MEDIUM_BUD => Ids::MEDIUM_AMETHYST_BUD,
1109 AmethystCluster::STAGE_LARGE_BUD => Ids::LARGE_AMETHYST_BUD,
1110 AmethystCluster::STAGE_CLUSTER => Ids::AMETHYST_CLUSTER,
1111 default => throw new BlockStateSerializeException("Invalid Amethyst Cluster stage $stage"),
1112 })
1113 ->writeBlockFace($block->getFacing())
1114 );
1115 $this->mapSlab(Blocks::ANDESITE_SLAB(), Ids::ANDESITE_SLAB, Ids::ANDESITE_DOUBLE_SLAB);
1116 $this->map(Blocks::ANDESITE_STAIRS(), fn(Stair $block) => Helper::encodeStairs($block, new Writer(Ids::ANDESITE_STAIRS)));
1117 $this->map(Blocks::ANDESITE_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::ANDESITE_WALL)));
1118 $this->map(Blocks::ANVIL(), fn(Anvil $block) : Writer => Writer::create(
1119 match($damage = $block->getDamage()){
1120 0 => Ids::ANVIL,
1121 1 => Ids::CHIPPED_ANVIL,
1122 2 => Ids::DAMAGED_ANVIL,
1123 default => throw new BlockStateSerializeException("Invalid Anvil damage {$damage}"),
1124 })
1125 ->writeCardinalHorizontalFacing($block->getFacing())
1126 );
1127 $this->map(Blocks::BAMBOO(), function(Bamboo $block) : Writer{
1128 return Writer::create(Ids::BAMBOO)
1129 ->writeBool(StateNames::AGE_BIT, $block->isReady())
1130 ->writeString(StateNames::BAMBOO_LEAF_SIZE, match($block->getLeafSize()){
1131 Bamboo::NO_LEAVES => StringValues::BAMBOO_LEAF_SIZE_NO_LEAVES,
1132 Bamboo::SMALL_LEAVES => StringValues::BAMBOO_LEAF_SIZE_SMALL_LEAVES,
1133 Bamboo::LARGE_LEAVES => StringValues::BAMBOO_LEAF_SIZE_LARGE_LEAVES,
1134 default => throw new BlockStateSerializeException("Invalid Bamboo leaf thickness " . $block->getLeafSize()),
1135 })
1136 ->writeString(StateNames::BAMBOO_STALK_THICKNESS, $block->isThick() ? StringValues::BAMBOO_STALK_THICKNESS_THICK : StringValues::BAMBOO_STALK_THICKNESS_THIN);
1137 });
1138 $this->map(Blocks::BAMBOO_SAPLING(), function(BambooSapling $block) : Writer{
1139 return Writer::create(Ids::BAMBOO_SAPLING)
1140 ->writeBool(StateNames::AGE_BIT, $block->isReady());
1141 });
1142 $this->map(Blocks::BANNER(), function(FloorBanner $block) : Writer{
1143 return Writer::create(Ids::STANDING_BANNER)
1144 ->writeInt(StateNames::GROUND_SIGN_DIRECTION, $block->getRotation());
1145 });
1146 $this->map(Blocks::BARREL(), function(Barrel $block) : Writer{
1147 return Writer::create(Ids::BARREL)
1148 ->writeBool(StateNames::OPEN_BIT, $block->isOpen())
1149 ->writeFacingDirection($block->getFacing());
1150 });
1151 $this->map(Blocks::BASALT(), function(SimplePillar $block) : Writer{
1152 return Writer::create(Ids::BASALT)
1153 ->writePillarAxis($block->getAxis());
1154 });
1155 $this->map(Blocks::BED(), function(Bed $block) : Writer{
1156 return Writer::create(Ids::BED)
1157 ->writeBool(StateNames::HEAD_PIECE_BIT, $block->isHeadPart())
1158 ->writeBool(StateNames::OCCUPIED_BIT, $block->isOccupied())
1159 ->writeLegacyHorizontalFacing($block->getFacing());
1160 });
1161 $this->map(Blocks::BEDROCK(), function(Block $block) : Writer{
1162 return Writer::create(Ids::BEDROCK)
1163 ->writeBool(StateNames::INFINIBURN_BIT, $block->burnsForever());
1164 });
1165 $this->map(Blocks::BEETROOTS(), fn(Beetroot $block) => Helper::encodeCrops($block, new Writer(Ids::BEETROOT)));
1166 $this->map(Blocks::BELL(), function(Bell $block) : Writer{
1167 return Writer::create(Ids::BELL)
1168 ->writeBellAttachmentType($block->getAttachmentType())
1169 ->writeBool(StateNames::TOGGLE_BIT, false) //we don't care about this; it's just to keep MCPE happy
1170 ->writeLegacyHorizontalFacing($block->getFacing());
1171
1172 });
1173 $this->map(Blocks::BIG_DRIPLEAF_HEAD(), function(BigDripleafHead $block) : Writer{
1174 return Writer::create(Ids::BIG_DRIPLEAF)
1175 ->writeCardinalHorizontalFacing($block->getFacing())
1176 ->writeString(StateNames::BIG_DRIPLEAF_TILT, match($block->getLeafState()){
1177 DripleafState::STABLE => StringValues::BIG_DRIPLEAF_TILT_NONE,
1178 DripleafState::UNSTABLE => StringValues::BIG_DRIPLEAF_TILT_UNSTABLE,
1179 DripleafState::PARTIAL_TILT => StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT,
1180 DripleafState::FULL_TILT => StringValues::BIG_DRIPLEAF_TILT_FULL_TILT,
1181 })
1182 ->writeBool(StateNames::BIG_DRIPLEAF_HEAD, true);
1183 });
1184 $this->map(Blocks::BIG_DRIPLEAF_STEM(), function(BigDripleafStem $block) : Writer{
1185 return Writer::create(Ids::BIG_DRIPLEAF)
1186 ->writeCardinalHorizontalFacing($block->getFacing())
1187 ->writeString(StateNames::BIG_DRIPLEAF_TILT, StringValues::BIG_DRIPLEAF_TILT_NONE)
1188 ->writeBool(StateNames::BIG_DRIPLEAF_HEAD, false);
1189 });
1190 $this->mapSlab(Blocks::BLACKSTONE_SLAB(), Ids::BLACKSTONE_SLAB, Ids::BLACKSTONE_DOUBLE_SLAB);
1191 $this->mapStairs(Blocks::BLACKSTONE_STAIRS(), Ids::BLACKSTONE_STAIRS);
1192 $this->map(Blocks::BLACKSTONE_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::BLACKSTONE_WALL)));
1193 $this->map(Blocks::BLAST_FURNACE(), fn(Furnace $block) => Helper::encodeFurnace($block, Ids::BLAST_FURNACE, Ids::LIT_BLAST_FURNACE));
1194 $this->map(Blocks::BLUE_TORCH(), fn(Torch $block) => Helper::encodeTorch($block, Writer::create(Ids::COLORED_TORCH_BLUE)));
1195 $this->map(Blocks::BONE_BLOCK(), function(BoneBlock $block) : Writer{
1196 return Writer::create(Ids::BONE_BLOCK)
1197 ->writeInt(StateNames::DEPRECATED, 0)
1198 ->writePillarAxis($block->getAxis());
1199 });
1200 $this->map(Blocks::BREWING_STAND(), function(BrewingStand $block) : Writer{
1201 return Writer::create(Ids::BREWING_STAND)
1202 ->writeBool(StateNames::BREWING_STAND_SLOT_A_BIT, $block->hasSlot(BrewingStandSlot::EAST))
1203 ->writeBool(StateNames::BREWING_STAND_SLOT_B_BIT, $block->hasSlot(BrewingStandSlot::SOUTHWEST))
1204 ->writeBool(StateNames::BREWING_STAND_SLOT_C_BIT, $block->hasSlot(BrewingStandSlot::NORTHWEST));
1205 });
1206 $this->mapSlab(Blocks::BRICK_SLAB(), Ids::BRICK_SLAB, Ids::BRICK_DOUBLE_SLAB);
1207 $this->mapStairs(Blocks::BRICK_STAIRS(), Ids::BRICK_STAIRS);
1208 $this->map(Blocks::BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::BRICK_WALL)));
1209 $this->map(Blocks::BROWN_MUSHROOM_BLOCK(), fn(BrownMushroomBlock $block) => Helper::encodeMushroomBlock($block, new Writer(Ids::BROWN_MUSHROOM_BLOCK)));
1210 $this->map(Blocks::CACTUS(), function(Cactus $block) : Writer{
1211 return Writer::create(Ids::CACTUS)
1212 ->writeInt(StateNames::AGE, $block->getAge());
1213 });
1214 $this->map(Blocks::CAKE(), function(Cake $block) : Writer{
1215 return Writer::create(Ids::CAKE)
1216 ->writeInt(StateNames::BITE_COUNTER, $block->getBites());
1217 });
1218 $this->map(Blocks::CAMPFIRE(), function(Campfire $block) : Writer{
1219 return Writer::create(Ids::CAMPFIRE)
1220 ->writeCardinalHorizontalFacing($block->getFacing())
1221 ->writeBool(StateNames::EXTINGUISHED, !$block->isLit());
1222 });
1223 $this->map(Blocks::CARROTS(), fn(Carrot $block) => Helper::encodeCrops($block, new Writer(Ids::CARROTS)));
1224 $this->map(Blocks::CARVED_PUMPKIN(), function(CarvedPumpkin $block) : Writer{
1225 return Writer::create(Ids::CARVED_PUMPKIN)
1226 ->writeCardinalHorizontalFacing($block->getFacing());
1227 });
1228 $this->map(Blocks::CAVE_VINES(), function(CaveVines $block) : Writer{
1229 //I have no idea why this only has 3 IDs - there are 4 in Java and 4 visually distinct states in Bedrock
1230 return Writer::create($block->hasBerries() ?
1231 ($block->isHead() ?
1232 Ids::CAVE_VINES_HEAD_WITH_BERRIES :
1233 Ids::CAVE_VINES_BODY_WITH_BERRIES
1234 ) :
1235 Ids::CAVE_VINES
1236 )
1237 ->writeInt(StateNames::GROWING_PLANT_AGE, $block->getAge());
1238 });
1239 $this->map(Blocks::CHAIN(), function(Chain $block) : Writer{
1240 return Writer::create(Ids::CHAIN)
1241 ->writePillarAxis($block->getAxis());
1242 });
1243 $this->map(Blocks::CHEST(), function(Chest $block) : Writer{
1244 return Writer::create(Ids::CHEST)
1245 ->writeCardinalHorizontalFacing($block->getFacing());
1246 });
1247 $this->map(Blocks::CHISELED_BOOKSHELF(), function(ChiseledBookshelf $block) : Writer{
1248 $flags = 0;
1249 foreach($block->getSlots() as $slot){
1250 $flags |= 1 << $slot->value;
1251 }
1252 return Writer::create(Ids::CHISELED_BOOKSHELF)
1253 ->writeLegacyHorizontalFacing($block->getFacing())
1254 ->writeInt(StateNames::BOOKS_STORED, $flags);
1255 });
1256 $this->map(Blocks::CHISELED_QUARTZ(), fn(SimplePillar $block) => Helper::encodeQuartz($block->getAxis(), Writer::create(Ids::CHISELED_QUARTZ_BLOCK)));
1257 $this->map(Blocks::CHORUS_FLOWER(), function(ChorusFlower $block) : Writer{
1258 return Writer::create(Ids::CHORUS_FLOWER)
1259 ->writeInt(StateNames::AGE, $block->getAge());
1260 });
1261 $this->mapSlab(Blocks::COBBLED_DEEPSLATE_SLAB(), Ids::COBBLED_DEEPSLATE_SLAB, Ids::COBBLED_DEEPSLATE_DOUBLE_SLAB);
1262 $this->mapStairs(Blocks::COBBLED_DEEPSLATE_STAIRS(), Ids::COBBLED_DEEPSLATE_STAIRS);
1263 $this->map(Blocks::COBBLED_DEEPSLATE_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::COBBLED_DEEPSLATE_WALL)));
1264 $this->mapSlab(Blocks::COBBLESTONE_SLAB(), Ids::COBBLESTONE_SLAB, Ids::COBBLESTONE_DOUBLE_SLAB);
1265 $this->mapStairs(Blocks::COBBLESTONE_STAIRS(), Ids::STONE_STAIRS);
1266 $this->map(Blocks::COBBLESTONE_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::COBBLESTONE_WALL)));
1267 $this->map(Blocks::COPPER(), function(Copper $block) : Writer{
1268 $oxidation = $block->getOxidation();
1269 return new Writer($block->isWaxed() ?
1270 Helper::selectCopperId($oxidation, Ids::WAXED_COPPER, Ids::WAXED_EXPOSED_COPPER, Ids::WAXED_WEATHERED_COPPER, Ids::WAXED_OXIDIZED_COPPER) :
1271 Helper::selectCopperId($oxidation, Ids::COPPER_BLOCK, Ids::EXPOSED_COPPER, Ids::WEATHERED_COPPER, Ids::OXIDIZED_COPPER)
1272 );
1273 });
1274 $this->map(Blocks::CHISELED_COPPER(), function(Copper $block) : Writer{
1275 $oxidation = $block->getOxidation();
1276 return new Writer($block->isWaxed() ?
1277 Helper::selectCopperId($oxidation,
1278 Ids::WAXED_CHISELED_COPPER,
1279 Ids::WAXED_EXPOSED_CHISELED_COPPER,
1280 Ids::WAXED_WEATHERED_CHISELED_COPPER,
1281 Ids::WAXED_OXIDIZED_CHISELED_COPPER
1282 ) :
1283 Helper::selectCopperId($oxidation,
1284 Ids::CHISELED_COPPER,
1285 Ids::EXPOSED_CHISELED_COPPER,
1286 Ids::WEATHERED_CHISELED_COPPER,
1287 Ids::OXIDIZED_CHISELED_COPPER
1288 )
1289 );
1290 });
1291 $this->map(Blocks::COPPER_GRATE(), function(CopperGrate $block) : Writer{
1292 $oxidation = $block->getOxidation();
1293 return new Writer($block->isWaxed() ?
1294 Helper::selectCopperId($oxidation,
1295 Ids::WAXED_COPPER_GRATE,
1296 Ids::WAXED_EXPOSED_COPPER_GRATE,
1297 Ids::WAXED_WEATHERED_COPPER_GRATE,
1298 Ids::WAXED_OXIDIZED_COPPER_GRATE
1299 ) :
1300 Helper::selectCopperId($oxidation,
1301 Ids::COPPER_GRATE,
1302 Ids::EXPOSED_COPPER_GRATE,
1303 Ids::WEATHERED_COPPER_GRATE,
1304 Ids::OXIDIZED_COPPER_GRATE
1305 )
1306 );
1307 });
1308 $this->map(Blocks::CUT_COPPER(), function(Copper $block) : Writer{
1309 $oxidation = $block->getOxidation();
1310 return new Writer($block->isWaxed() ?
1311 Helper::selectCopperId($oxidation, Ids::WAXED_CUT_COPPER, Ids::WAXED_EXPOSED_CUT_COPPER, Ids::WAXED_WEATHERED_CUT_COPPER, Ids::WAXED_OXIDIZED_CUT_COPPER) :
1312 Helper::selectCopperId($oxidation, Ids::CUT_COPPER, Ids::EXPOSED_CUT_COPPER, Ids::WEATHERED_CUT_COPPER, Ids::OXIDIZED_CUT_COPPER)
1313 );
1314 });
1315 $this->map(Blocks::CUT_COPPER_SLAB(), function(CopperSlab $block) : Writer{
1316 $oxidation = $block->getOxidation();
1317 return Helper::encodeSlab(
1318 $block,
1319 ($block->isWaxed() ?
1320 Helper::selectCopperId(
1321 $oxidation,
1322 Ids::WAXED_CUT_COPPER_SLAB,
1323 Ids::WAXED_EXPOSED_CUT_COPPER_SLAB,
1324 Ids::WAXED_WEATHERED_CUT_COPPER_SLAB,
1325 Ids::WAXED_OXIDIZED_CUT_COPPER_SLAB
1326 ) :
1327 Helper::selectCopperId(
1328 $oxidation,
1329 Ids::CUT_COPPER_SLAB,
1330 Ids::EXPOSED_CUT_COPPER_SLAB,
1331 Ids::WEATHERED_CUT_COPPER_SLAB,
1332 Ids::OXIDIZED_CUT_COPPER_SLAB
1333 )
1334 ),
1335 ($block->isWaxed() ?
1336 Helper::selectCopperId(
1337 $oxidation,
1338 Ids::WAXED_DOUBLE_CUT_COPPER_SLAB,
1339 Ids::WAXED_EXPOSED_DOUBLE_CUT_COPPER_SLAB,
1340 Ids::WAXED_WEATHERED_DOUBLE_CUT_COPPER_SLAB,
1341 Ids::WAXED_OXIDIZED_DOUBLE_CUT_COPPER_SLAB
1342 ) :
1343 Helper::selectCopperId(
1344 $oxidation,
1345 Ids::DOUBLE_CUT_COPPER_SLAB,
1346 Ids::EXPOSED_DOUBLE_CUT_COPPER_SLAB,
1347 Ids::WEATHERED_DOUBLE_CUT_COPPER_SLAB,
1348 Ids::OXIDIZED_DOUBLE_CUT_COPPER_SLAB
1349 )
1350 )
1351 );
1352 });
1353 $this->map(Blocks::CUT_COPPER_STAIRS(), function(CopperStairs $block) : Writer{
1354 $oxidation = $block->getOxidation();
1355 return Helper::encodeStairs(
1356 $block,
1357 new Writer($block->isWaxed() ?
1358 Helper::selectCopperId(
1359 $oxidation,
1360 Ids::WAXED_CUT_COPPER_STAIRS,
1361 Ids::WAXED_EXPOSED_CUT_COPPER_STAIRS,
1362 Ids::WAXED_WEATHERED_CUT_COPPER_STAIRS,
1363 Ids::WAXED_OXIDIZED_CUT_COPPER_STAIRS
1364 ) :
1365 Helper::selectCopperId(
1366 $oxidation,
1367 Ids::CUT_COPPER_STAIRS,
1368 Ids::EXPOSED_CUT_COPPER_STAIRS,
1369 Ids::WEATHERED_CUT_COPPER_STAIRS,
1370 Ids::OXIDIZED_CUT_COPPER_STAIRS
1371 )
1372 )
1373 );
1374 });
1375 $this->map(Blocks::COPPER_BULB(), function(CopperBulb $block) : Writer{
1376 $oxidation = $block->getOxidation();
1377 return Writer::create($block->isWaxed() ?
1378 Helper::selectCopperId($oxidation,
1379 Ids::WAXED_COPPER_BULB,
1380 Ids::WAXED_EXPOSED_COPPER_BULB,
1381 Ids::WAXED_WEATHERED_COPPER_BULB,
1382 Ids::WAXED_OXIDIZED_COPPER_BULB) :
1383 Helper::selectCopperId($oxidation,
1384 Ids::COPPER_BULB,
1385 Ids::EXPOSED_COPPER_BULB,
1386 Ids::WEATHERED_COPPER_BULB,
1387 Ids::OXIDIZED_COPPER_BULB
1388 ))
1389 ->writeBool(StateNames::LIT, $block->isLit())
1390 ->writeBool(StateNames::POWERED_BIT, $block->isPowered());
1391 });
1392 $this->map(Blocks::COPPER_DOOR(), function(CopperDoor $block) : Writer{
1393 $oxidation = $block->getOxidation();
1394 return Helper::encodeDoor(
1395 $block,
1396 new Writer($block->isWaxed() ?
1397 Helper::selectCopperId(
1398 $oxidation,
1399 Ids::WAXED_COPPER_DOOR,
1400 Ids::WAXED_EXPOSED_COPPER_DOOR,
1401 Ids::WAXED_WEATHERED_COPPER_DOOR,
1402 Ids::WAXED_OXIDIZED_COPPER_DOOR
1403 ) :
1404 Helper::selectCopperId(
1405 $oxidation,
1406 Ids::COPPER_DOOR,
1407 Ids::EXPOSED_COPPER_DOOR,
1408 Ids::WEATHERED_COPPER_DOOR,
1409 Ids::OXIDIZED_COPPER_DOOR
1410 )
1411 )
1412 );
1413 });
1414 $this->map(Blocks::COPPER_TRAPDOOR(), function(CopperTrapdoor $block) : Writer{
1415 $oxidation = $block->getOxidation();
1416 return Helper::encodeTrapdoor(
1417 $block,
1418 new Writer($block->isWaxed() ?
1419 Helper::selectCopperId(
1420 $oxidation,
1421 Ids::WAXED_COPPER_TRAPDOOR,
1422 Ids::WAXED_EXPOSED_COPPER_TRAPDOOR,
1423 Ids::WAXED_WEATHERED_COPPER_TRAPDOOR,
1424 Ids::WAXED_OXIDIZED_COPPER_TRAPDOOR
1425 ) :
1426 Helper::selectCopperId(
1427 $oxidation,
1428 Ids::COPPER_TRAPDOOR,
1429 Ids::EXPOSED_COPPER_TRAPDOOR,
1430 Ids::WEATHERED_COPPER_TRAPDOOR,
1431 Ids::OXIDIZED_COPPER_TRAPDOOR
1432 )
1433 )
1434 );
1435 });
1436 $this->map(Blocks::COCOA_POD(), function(CocoaBlock $block) : Writer{
1437 return Writer::create(Ids::COCOA)
1438 ->writeInt(StateNames::AGE, $block->getAge())
1439 ->writeLegacyHorizontalFacing(Facing::opposite($block->getFacing()));
1440 });
1441 $this->map(Blocks::COMPOUND_CREATOR(), fn(ChemistryTable $block) => Helper::encodeChemistryTable($block, Writer::create(Ids::COMPOUND_CREATOR)));
1442 $this->mapSlab(Blocks::CUT_RED_SANDSTONE_SLAB(), Ids::CUT_RED_SANDSTONE_SLAB, Ids::CUT_RED_SANDSTONE_DOUBLE_SLAB);
1443 $this->mapSlab(Blocks::CUT_SANDSTONE_SLAB(), Ids::CUT_SANDSTONE_SLAB, Ids::CUT_SANDSTONE_DOUBLE_SLAB);
1444 $this->mapSlab(Blocks::DARK_PRISMARINE_SLAB(), Ids::DARK_PRISMARINE_SLAB, Ids::DARK_PRISMARINE_DOUBLE_SLAB);
1445 $this->mapStairs(Blocks::DARK_PRISMARINE_STAIRS(), Ids::DARK_PRISMARINE_STAIRS);
1446 $this->map(Blocks::DAYLIGHT_SENSOR(), function(DaylightSensor $block) : Writer{
1447 return Writer::create($block->isInverted() ? Ids::DAYLIGHT_DETECTOR_INVERTED : Ids::DAYLIGHT_DETECTOR)
1448 ->writeInt(StateNames::REDSTONE_SIGNAL, $block->getOutputSignalStrength());
1449 });
1450 $this->map(Blocks::DEEPSLATE(), function(SimplePillar $block) : Writer{
1451 return Writer::create(Ids::DEEPSLATE)
1452 ->writePillarAxis($block->getAxis());
1453 });
1454 $this->mapSlab(Blocks::DEEPSLATE_BRICK_SLAB(), Ids::DEEPSLATE_BRICK_SLAB, Ids::DEEPSLATE_BRICK_DOUBLE_SLAB);
1455 $this->mapStairs(Blocks::DEEPSLATE_BRICK_STAIRS(), Ids::DEEPSLATE_BRICK_STAIRS);
1456 $this->map(Blocks::DEEPSLATE_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::DEEPSLATE_BRICK_WALL)));
1457 $this->map(Blocks::DEEPSLATE_REDSTONE_ORE(), fn(RedstoneOre $block) => new Writer($block->isLit() ? Ids::LIT_DEEPSLATE_REDSTONE_ORE : Ids::DEEPSLATE_REDSTONE_ORE));
1458 $this->mapSlab(Blocks::DEEPSLATE_TILE_SLAB(), Ids::DEEPSLATE_TILE_SLAB, Ids::DEEPSLATE_TILE_DOUBLE_SLAB);
1459 $this->mapStairs(Blocks::DEEPSLATE_TILE_STAIRS(), Ids::DEEPSLATE_TILE_STAIRS);
1460 $this->map(Blocks::DEEPSLATE_TILE_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::DEEPSLATE_TILE_WALL)));
1461 $this->map(Blocks::DETECTOR_RAIL(), function(DetectorRail $block) : Writer{
1462 return Writer::create(Ids::DETECTOR_RAIL)
1463 ->writeBool(StateNames::RAIL_DATA_BIT, $block->isActivated())
1464 ->writeInt(StateNames::RAIL_DIRECTION, $block->getShape());
1465 });
1466 $this->mapSlab(Blocks::DIORITE_SLAB(), Ids::DIORITE_SLAB, Ids::DIORITE_DOUBLE_SLAB);
1467 $this->mapStairs(Blocks::DIORITE_STAIRS(), Ids::DIORITE_STAIRS);
1468 $this->map(Blocks::DIORITE_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::DIORITE_WALL)));
1469 $this->map(Blocks::DIRT(), function(Dirt $block) : Writer{
1470 return Writer::create(match($block->getDirtType()){
1471 DirtType::NORMAL => Ids::DIRT,
1472 DirtType::COARSE => Ids::COARSE_DIRT,
1473 DirtType::ROOTED => Ids::DIRT_WITH_ROOTS,
1474 });
1475 });
1476 $this->map(Blocks::DOUBLE_TALLGRASS(), fn(DoubleTallGrass $block) => Helper::encodeDoublePlant($block, Writer::create(Ids::TALL_GRASS)));
1477 $this->map(Blocks::ELEMENT_CONSTRUCTOR(), fn(ChemistryTable $block) => Helper::encodeChemistryTable($block, Writer::create(Ids::ELEMENT_CONSTRUCTOR)));
1478 $this->map(Blocks::ENDER_CHEST(), function(EnderChest $block) : Writer{
1479 return Writer::create(Ids::ENDER_CHEST)
1480 ->writeCardinalHorizontalFacing($block->getFacing());
1481 });
1482 $this->map(Blocks::END_PORTAL_FRAME(), function(EndPortalFrame $block) : Writer{
1483 return Writer::create(Ids::END_PORTAL_FRAME)
1484 ->writeBool(StateNames::END_PORTAL_EYE_BIT, $block->hasEye())
1485 ->writeCardinalHorizontalFacing($block->getFacing());
1486 });
1487 $this->map(Blocks::END_ROD(), function(EndRod $block) : Writer{
1488 return Writer::create(Ids::END_ROD)
1489 ->writeEndRodFacingDirection($block->getFacing());
1490 });
1491 $this->mapSlab(Blocks::END_STONE_BRICK_SLAB(), Ids::END_STONE_BRICK_SLAB, Ids::END_STONE_BRICK_DOUBLE_SLAB);
1492 $this->mapStairs(Blocks::END_STONE_BRICK_STAIRS(), Ids::END_BRICK_STAIRS);
1493 $this->map(Blocks::END_STONE_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::END_STONE_BRICK_WALL)));
1494 $this->mapSlab(Blocks::FAKE_WOODEN_SLAB(), Ids::PETRIFIED_OAK_SLAB, Ids::PETRIFIED_OAK_DOUBLE_SLAB);
1495 $this->map(Blocks::FARMLAND(), function(Farmland $block) : Writer{
1496 return Writer::create(Ids::FARMLAND)
1497 ->writeInt(StateNames::MOISTURIZED_AMOUNT, $block->getWetness());
1498 });
1499 $this->map(Blocks::FIRE(), function(Fire $block) : Writer{
1500 return Writer::create(Ids::FIRE)
1501 ->writeInt(StateNames::AGE, $block->getAge());
1502 });
1503 $this->map(Blocks::FLOWER_POT(), function() : Writer{
1504 return Writer::create(Ids::FLOWER_POT)
1505 ->writeBool(StateNames::UPDATE_BIT, false); //to keep MCPE happy
1506 });
1507 $this->map(Blocks::FROGLIGHT(), function(Froglight $block){
1508 return Writer::create(match($block->getFroglightType()){
1509 FroglightType::OCHRE => Ids::OCHRE_FROGLIGHT,
1510 FroglightType::PEARLESCENT => Ids::PEARLESCENT_FROGLIGHT,
1511 FroglightType::VERDANT => Ids::VERDANT_FROGLIGHT,
1512 })
1513 ->writePillarAxis($block->getAxis());
1514 });
1515 $this->map(Blocks::FROSTED_ICE(), function(FrostedIce $block) : Writer{
1516 return Writer::create(Ids::FROSTED_ICE)
1517 ->writeInt(StateNames::AGE, $block->getAge());
1518 });
1519 $this->map(Blocks::FURNACE(), fn(Furnace $block) => Helper::encodeFurnace($block, Ids::FURNACE, Ids::LIT_FURNACE));
1520 $this->map(Blocks::GLOW_LICHEN(), function(GlowLichen $block) : Writer{
1521 return Writer::create(Ids::GLOW_LICHEN)
1522 ->writeFacingFlags($block->getFaces());
1523 });
1524 $this->map(Blocks::GLOWING_ITEM_FRAME(), fn(ItemFrame $block) => Helper::encodeItemFrame($block, Ids::GLOW_FRAME));
1525 $this->mapSlab(Blocks::GRANITE_SLAB(), Ids::GRANITE_SLAB, Ids::GRANITE_DOUBLE_SLAB);
1526 $this->mapStairs(Blocks::GRANITE_STAIRS(), Ids::GRANITE_STAIRS);
1527 $this->map(Blocks::GRANITE_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::GRANITE_WALL)));
1528 $this->map(Blocks::GREEN_TORCH(), fn(Torch $block) => Helper::encodeTorch($block, Writer::create(Ids::COLORED_TORCH_GREEN)));
1529 $this->map(Blocks::HAY_BALE(), function(HayBale $block) : Writer{
1530 return Writer::create(Ids::HAY_BLOCK)
1531 ->writeInt(StateNames::DEPRECATED, 0)
1532 ->writePillarAxis($block->getAxis());
1533 });
1534 $this->map(Blocks::HOPPER(), function(Hopper $block) : Writer{
1535 return Writer::create(Ids::HOPPER)
1536 ->writeBool(StateNames::TOGGLE_BIT, $block->isPowered())
1537 ->writeFacingWithoutUp($block->getFacing());
1538 });
1539 $this->map(Blocks::IRON_DOOR(), fn(Door $block) => Helper::encodeDoor($block, new Writer(Ids::IRON_DOOR)));
1540 $this->map(Blocks::IRON_TRAPDOOR(), fn(Trapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::IRON_TRAPDOOR)));
1541 $this->map(Blocks::ITEM_FRAME(), fn(ItemFrame $block) => Helper::encodeItemFrame($block, Ids::FRAME));
1542 $this->map(Blocks::LAB_TABLE(), fn(ChemistryTable $block) => Helper::encodeChemistryTable($block, Writer::create(Ids::LAB_TABLE)));
1543 $this->map(Blocks::LADDER(), function(Ladder $block) : Writer{
1544 return Writer::create(Ids::LADDER)
1545 ->writeHorizontalFacing($block->getFacing());
1546 });
1547 $this->map(Blocks::LANTERN(), function(Lantern $block) : Writer{
1548 return Writer::create(Ids::LANTERN)
1549 ->writeBool(StateNames::HANGING, $block->isHanging());
1550 });
1551 $this->map(Blocks::LARGE_FERN(), fn(DoubleTallGrass $block) => Helper::encodeDoublePlant($block, Writer::create(Ids::LARGE_FERN)));
1552 $this->map(Blocks::LAVA(), fn(Lava $block) => Helper::encodeLiquid($block, Ids::LAVA, Ids::FLOWING_LAVA));
1553 $this->map(Blocks::LECTERN(), function(Lectern $block) : Writer{
1554 return Writer::create(Ids::LECTERN)
1555 ->writeBool(StateNames::POWERED_BIT, $block->isProducingSignal())
1556 ->writeCardinalHorizontalFacing($block->getFacing());
1557 });
1558 $this->map(Blocks::LEVER(), function(Lever $block) : Writer{
1559 return Writer::create(Ids::LEVER)
1560 ->writeBool(StateNames::OPEN_BIT, $block->isActivated())
1561 ->writeString(StateNames::LEVER_DIRECTION, match($block->getFacing()){
1562 LeverFacing::DOWN_AXIS_Z => StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH,
1563 LeverFacing::DOWN_AXIS_X => StringValues::LEVER_DIRECTION_DOWN_EAST_WEST,
1564 LeverFacing::UP_AXIS_Z => StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH,
1565 LeverFacing::UP_AXIS_X => StringValues::LEVER_DIRECTION_UP_EAST_WEST,
1566 LeverFacing::NORTH => StringValues::LEVER_DIRECTION_NORTH,
1567 LeverFacing::SOUTH => StringValues::LEVER_DIRECTION_SOUTH,
1568 LeverFacing::WEST => StringValues::LEVER_DIRECTION_WEST,
1569 LeverFacing::EAST => StringValues::LEVER_DIRECTION_EAST,
1570 });
1571 });
1572 $this->map(Blocks::LIGHT(), function(Light $block) : Writer{
1573 return Writer::create(match($block->getLightLevel()){
1574 0 => Ids::LIGHT_BLOCK_0,
1575 1 => Ids::LIGHT_BLOCK_1,
1576 2 => Ids::LIGHT_BLOCK_2,
1577 3 => Ids::LIGHT_BLOCK_3,
1578 4 => Ids::LIGHT_BLOCK_4,
1579 5 => Ids::LIGHT_BLOCK_5,
1580 6 => Ids::LIGHT_BLOCK_6,
1581 7 => Ids::LIGHT_BLOCK_7,
1582 8 => Ids::LIGHT_BLOCK_8,
1583 9 => Ids::LIGHT_BLOCK_9,
1584 10 => Ids::LIGHT_BLOCK_10,
1585 11 => Ids::LIGHT_BLOCK_11,
1586 12 => Ids::LIGHT_BLOCK_12,
1587 13 => Ids::LIGHT_BLOCK_13,
1588 14 => Ids::LIGHT_BLOCK_14,
1589 15 => Ids::LIGHT_BLOCK_15,
1590 default => throw new BlockStateSerializeException("Invalid light level " . $block->getLightLevel()),
1591 });
1592 });
1593 $this->map(Blocks::LIGHTNING_ROD(), function(LightningRod $block) : Writer{
1594 return Writer::create(Ids::LIGHTNING_ROD)
1595 ->writeFacingDirection($block->getFacing());
1596 });
1597 $this->map(Blocks::LILAC(), fn(DoublePlant $block) => Helper::encodeDoublePlant($block, Writer::create(Ids::LILAC)));
1598 $this->map(Blocks::LIT_PUMPKIN(), function(LitPumpkin $block) : Writer{
1599 return Writer::create(Ids::LIT_PUMPKIN)
1600 ->writeCardinalHorizontalFacing($block->getFacing());
1601 });
1602 $this->map(Blocks::LOOM(), function(Loom $block) : Writer{
1603 return Writer::create(Ids::LOOM)
1604 ->writeLegacyHorizontalFacing($block->getFacing());
1605 });
1606 $this->map(Blocks::MATERIAL_REDUCER(), fn(ChemistryTable $block) => Helper::encodeChemistryTable($block, Writer::create(Ids::MATERIAL_REDUCER)));
1607 $this->map(Blocks::MELON_STEM(), fn(MelonStem $block) => Helper::encodeStem($block, new Writer(Ids::MELON_STEM)));
1608 $this->mapSlab(Blocks::MOSSY_COBBLESTONE_SLAB(), Ids::MOSSY_COBBLESTONE_SLAB, Ids::MOSSY_COBBLESTONE_DOUBLE_SLAB);
1609 $this->mapStairs(Blocks::MOSSY_COBBLESTONE_STAIRS(), Ids::MOSSY_COBBLESTONE_STAIRS);
1610 $this->map(Blocks::MOSSY_COBBLESTONE_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::MOSSY_COBBLESTONE_WALL)));
1611 $this->mapSlab(Blocks::MOSSY_STONE_BRICK_SLAB(), Ids::MOSSY_STONE_BRICK_SLAB, Ids::MOSSY_STONE_BRICK_DOUBLE_SLAB);
1612 $this->mapStairs(Blocks::MOSSY_STONE_BRICK_STAIRS(), Ids::MOSSY_STONE_BRICK_STAIRS);
1613 $this->map(Blocks::MOSSY_STONE_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::MOSSY_STONE_BRICK_WALL)));
1614 $this->mapSlab(Blocks::MUD_BRICK_SLAB(), Ids::MUD_BRICK_SLAB, Ids::MUD_BRICK_DOUBLE_SLAB);
1615 $this->mapStairs(Blocks::MUD_BRICK_STAIRS(), Ids::MUD_BRICK_STAIRS);
1616 $this->map(Blocks::MUD_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::MUD_BRICK_WALL)));
1617 $this->map(Blocks::MUDDY_MANGROVE_ROOTS(), fn(SimplePillar $block) => Writer::create(Ids::MUDDY_MANGROVE_ROOTS)
1618 ->writePillarAxis($block->getAxis()));
1619 $this->map(Blocks::MUSHROOM_STEM(), fn() => Writer::create(Ids::MUSHROOM_STEM)
1620 ->writeInt(StateNames::HUGE_MUSHROOM_BITS, BlockLegacyMetadata::MUSHROOM_BLOCK_STEM));
1621 $this->mapSlab(Blocks::NETHER_BRICK_SLAB(), Ids::NETHER_BRICK_SLAB, Ids::NETHER_BRICK_DOUBLE_SLAB);
1622 $this->mapStairs(Blocks::NETHER_BRICK_STAIRS(), Ids::NETHER_BRICK_STAIRS);
1623 $this->map(Blocks::NETHER_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::NETHER_BRICK_WALL)));
1624 $this->map(Blocks::NETHER_PORTAL(), function(NetherPortal $block) : Writer{
1625 return Writer::create(Ids::PORTAL)
1626 ->writeString(StateNames::PORTAL_AXIS, match($block->getAxis()){
1627 Axis::X => StringValues::PORTAL_AXIS_X,
1628 Axis::Z => StringValues::PORTAL_AXIS_Z,
1629 default => throw new BlockStateSerializeException("Invalid Nether Portal axis " . $block->getAxis()),
1630 });
1631 });
1632 $this->map(Blocks::NETHER_WART(), function(NetherWartPlant $block) : Writer{
1633 return Writer::create(Ids::NETHER_WART)
1634 ->writeInt(StateNames::AGE, $block->getAge());
1635 });
1636 $this->map(Blocks::PEONY(), fn(DoublePlant $block) => Helper::encodeDoublePlant($block, Writer::create(Ids::PEONY)));
1637 $this->map(Blocks::PINK_PETALS(), function(PinkPetals $block) : Writer{
1638 return Writer::create(Ids::PINK_PETALS)
1639 ->writeCardinalHorizontalFacing($block->getFacing())
1640 ->writeInt(StateNames::GROWTH, $block->getCount() - 1);
1641 });
1642 $this->map(Blocks::PITCHER_PLANT(), function(DoublePlant $block) : Writer{
1643 return Writer::create(Ids::PITCHER_PLANT)
1644 ->writeBool(StateNames::UPPER_BLOCK_BIT, $block->isTop());
1645 });
1646 $this->map(Blocks::PITCHER_CROP(), function(PitcherCrop $block) : Writer{
1647 return Writer::create(Ids::PITCHER_CROP)
1648 ->writeInt(StateNames::GROWTH, $block->getAge())
1649 ->writeBool(StateNames::UPPER_BLOCK_BIT, false);
1650 });
1651 $this->map(Blocks::DOUBLE_PITCHER_CROP(), function(DoublePitcherCrop $block) : Writer{
1652 return Writer::create(Ids::PITCHER_CROP)
1653 ->writeInt(StateNames::GROWTH, $block->getAge() + 1 + PitcherCrop::MAX_AGE)
1654 ->writeBool(StateNames::UPPER_BLOCK_BIT, $block->isTop());
1655 });
1656 $this->mapSlab(Blocks::POLISHED_ANDESITE_SLAB(), Ids::POLISHED_ANDESITE_SLAB, Ids::POLISHED_ANDESITE_DOUBLE_SLAB);
1657 $this->mapStairs(Blocks::POLISHED_ANDESITE_STAIRS(), Ids::POLISHED_ANDESITE_STAIRS);
1658 $this->map(Blocks::POLISHED_BASALT(), function(SimplePillar $block) : Writer{
1659 return Writer::create(Ids::POLISHED_BASALT)
1660 ->writePillarAxis($block->getAxis());
1661 });
1662 $this->mapSlab(Blocks::POLISHED_BLACKSTONE_BRICK_SLAB(), Ids::POLISHED_BLACKSTONE_BRICK_SLAB, Ids::POLISHED_BLACKSTONE_BRICK_DOUBLE_SLAB);
1663 $this->mapStairs(Blocks::POLISHED_BLACKSTONE_BRICK_STAIRS(), Ids::POLISHED_BLACKSTONE_BRICK_STAIRS);
1664 $this->map(Blocks::POLISHED_BLACKSTONE_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::POLISHED_BLACKSTONE_BRICK_WALL)));
1665 $this->map(Blocks::POLISHED_BLACKSTONE_BUTTON(), fn(Button $block) => Helper::encodeButton($block, new Writer(Ids::POLISHED_BLACKSTONE_BUTTON)));
1666 $this->map(Blocks::POLISHED_BLACKSTONE_PRESSURE_PLATE(), fn(SimplePressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::POLISHED_BLACKSTONE_PRESSURE_PLATE)));
1667 $this->mapSlab(Blocks::POLISHED_BLACKSTONE_SLAB(), Ids::POLISHED_BLACKSTONE_SLAB, Ids::POLISHED_BLACKSTONE_DOUBLE_SLAB);
1668 $this->mapStairs(Blocks::POLISHED_BLACKSTONE_STAIRS(), Ids::POLISHED_BLACKSTONE_STAIRS);
1669 $this->map(Blocks::POLISHED_BLACKSTONE_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::POLISHED_BLACKSTONE_WALL)));
1670 $this->mapSlab(Blocks::POLISHED_DEEPSLATE_SLAB(), Ids::POLISHED_DEEPSLATE_SLAB, Ids::POLISHED_DEEPSLATE_DOUBLE_SLAB);
1671 $this->mapStairs(Blocks::POLISHED_DEEPSLATE_STAIRS(), Ids::POLISHED_DEEPSLATE_STAIRS);
1672 $this->map(Blocks::POLISHED_DEEPSLATE_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::POLISHED_DEEPSLATE_WALL)));
1673 $this->mapSlab(Blocks::POLISHED_DIORITE_SLAB(), Ids::POLISHED_DIORITE_SLAB, Ids::POLISHED_DIORITE_DOUBLE_SLAB);
1674 $this->mapStairs(Blocks::POLISHED_DIORITE_STAIRS(), Ids::POLISHED_DIORITE_STAIRS);
1675 $this->mapSlab(Blocks::POLISHED_GRANITE_SLAB(), Ids::POLISHED_GRANITE_SLAB, Ids::POLISHED_GRANITE_DOUBLE_SLAB);
1676 $this->mapStairs(Blocks::POLISHED_GRANITE_STAIRS(), Ids::POLISHED_GRANITE_STAIRS);
1677 $this->mapSlab(Blocks::POLISHED_TUFF_SLAB(), Ids::POLISHED_TUFF_SLAB, Ids::POLISHED_TUFF_DOUBLE_SLAB);
1678 $this->mapStairs(Blocks::POLISHED_TUFF_STAIRS(), Ids::POLISHED_TUFF_STAIRS);
1679 $this->map(Blocks::POLISHED_TUFF_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::POLISHED_TUFF_WALL)));
1680 $this->map(Blocks::POTATOES(), fn(Potato $block) => Helper::encodeCrops($block, new Writer(Ids::POTATOES)));
1681 $this->map(Blocks::POWERED_RAIL(), function(PoweredRail $block) : Writer{
1682 return Writer::create(Ids::GOLDEN_RAIL)
1683 ->writeBool(StateNames::RAIL_DATA_BIT, $block->isPowered())
1684 ->writeInt(StateNames::RAIL_DIRECTION, $block->getShape());
1685 });
1686 $this->mapSlab(Blocks::PRISMARINE_BRICKS_SLAB(), Ids::PRISMARINE_BRICK_SLAB, Ids::PRISMARINE_BRICK_DOUBLE_SLAB);
1687 $this->mapStairs(Blocks::PRISMARINE_BRICKS_STAIRS(), Ids::PRISMARINE_BRICKS_STAIRS);
1688 $this->mapSlab(Blocks::PRISMARINE_SLAB(), Ids::PRISMARINE_SLAB, Ids::PRISMARINE_DOUBLE_SLAB);
1689 $this->mapStairs(Blocks::PRISMARINE_STAIRS(), Ids::PRISMARINE_STAIRS);
1690 $this->map(Blocks::PRISMARINE_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::PRISMARINE_WALL)));
1691 $this->map(Blocks::PUMPKIN(), function() : Writer{
1692 return Writer::create(Ids::PUMPKIN)
1693 ->writeCardinalHorizontalFacing(Facing::SOUTH); //no longer used
1694 });
1695 $this->map(Blocks::PUMPKIN_STEM(), fn(PumpkinStem $block) => Helper::encodeStem($block, new Writer(Ids::PUMPKIN_STEM)));
1696 $this->map(Blocks::PURPUR(), fn() => Writer::create(Ids::PURPUR_BLOCK)->writePillarAxis(Axis::Y));
1697 $this->map(Blocks::PURPLE_TORCH(), fn(Torch $block) => Helper::encodeTorch($block, Writer::create(Ids::COLORED_TORCH_PURPLE)));
1698 $this->map(Blocks::PURPUR_PILLAR(), function(SimplePillar $block) : Writer{
1699 return Writer::create(Ids::PURPUR_PILLAR)
1700 ->writePillarAxis($block->getAxis());
1701 });
1702 $this->mapSlab(Blocks::PURPUR_SLAB(), Ids::PURPUR_SLAB, Ids::PURPUR_DOUBLE_SLAB);
1703 $this->mapStairs(Blocks::PURPUR_STAIRS(), Ids::PURPUR_STAIRS);
1704 $this->map(Blocks::QUARTZ(), fn() => Helper::encodeQuartz(Axis::Y, Writer::create(Ids::QUARTZ_BLOCK)));
1705 $this->map(Blocks::QUARTZ_PILLAR(), fn(SimplePillar $block) => Helper::encodeQuartz($block->getAxis(), Writer::create(Ids::QUARTZ_PILLAR)));
1706 $this->mapSlab(Blocks::QUARTZ_SLAB(), Ids::QUARTZ_SLAB, Ids::QUARTZ_DOUBLE_SLAB);
1707 $this->mapStairs(Blocks::QUARTZ_STAIRS(), Ids::QUARTZ_STAIRS);
1708 $this->map(Blocks::RAIL(), function(Rail $block) : Writer{
1709 return Writer::create(Ids::RAIL)
1710 ->writeInt(StateNames::RAIL_DIRECTION, $block->getShape());
1711 });
1712 $this->map(Blocks::REDSTONE_COMPARATOR(), function(RedstoneComparator $block) : Writer{
1713 return Writer::create($block->isPowered() ? Ids::POWERED_COMPARATOR : Ids::UNPOWERED_COMPARATOR)
1714 ->writeBool(StateNames::OUTPUT_LIT_BIT, $block->isPowered())
1715 ->writeBool(StateNames::OUTPUT_SUBTRACT_BIT, $block->isSubtractMode())
1716 ->writeCardinalHorizontalFacing($block->getFacing());
1717 });
1718 $this->map(Blocks::REDSTONE_LAMP(), fn(RedstoneLamp $block) => new Writer($block->isPowered() ? Ids::LIT_REDSTONE_LAMP : Ids::REDSTONE_LAMP));
1719 $this->map(Blocks::REDSTONE_ORE(), fn(RedstoneOre $block) => new Writer($block->isLit() ? Ids::LIT_REDSTONE_ORE : Ids::REDSTONE_ORE));
1720 $this->map(Blocks::REDSTONE_REPEATER(), function(RedstoneRepeater $block) : Writer{
1721 return Writer::create($block->isPowered() ? Ids::POWERED_REPEATER : Ids::UNPOWERED_REPEATER)
1722 ->writeCardinalHorizontalFacing($block->getFacing())
1723 ->writeInt(StateNames::REPEATER_DELAY, $block->getDelay() - 1);
1724 });
1725 $this->map(Blocks::REDSTONE_TORCH(), function(RedstoneTorch $block) : Writer{
1726 return Writer::create($block->isLit() ? Ids::REDSTONE_TORCH : Ids::UNLIT_REDSTONE_TORCH)
1727 ->writeTorchFacing($block->getFacing());
1728 });
1729 $this->map(Blocks::REDSTONE_WIRE(), function(RedstoneWire $block) : Writer{
1730 return Writer::create(Ids::REDSTONE_WIRE)
1731 ->writeInt(StateNames::REDSTONE_SIGNAL, $block->getOutputSignalStrength());
1732 });
1733 $this->map(Blocks::RED_MUSHROOM_BLOCK(), fn(RedMushroomBlock $block) => Helper::encodeMushroomBlock($block, new Writer(Ids::RED_MUSHROOM_BLOCK)));
1734 $this->mapSlab(Blocks::RED_NETHER_BRICK_SLAB(), Ids::RED_NETHER_BRICK_SLAB, Ids::RED_NETHER_BRICK_DOUBLE_SLAB);
1735 $this->mapStairs(Blocks::RED_NETHER_BRICK_STAIRS(), Ids::RED_NETHER_BRICK_STAIRS);
1736 $this->map(Blocks::RED_NETHER_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::RED_NETHER_BRICK_WALL)));
1737 $this->mapSlab(Blocks::RED_SANDSTONE_SLAB(), Ids::RED_SANDSTONE_SLAB, Ids::RED_SANDSTONE_DOUBLE_SLAB);
1738 $this->mapStairs(Blocks::RED_SANDSTONE_STAIRS(), Ids::RED_SANDSTONE_STAIRS);
1739 $this->map(Blocks::RED_SANDSTONE_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::RED_SANDSTONE_WALL)));
1740 $this->map(Blocks::RED_TORCH(), fn(Torch $block) => Helper::encodeTorch($block, Writer::create(Ids::COLORED_TORCH_RED)));
1741 $this->mapSlab(Blocks::RESIN_BRICK_SLAB(), Ids::RESIN_BRICK_SLAB, Ids::RESIN_BRICK_DOUBLE_SLAB);
1742 $this->map(Blocks::RESIN_BRICK_STAIRS(), fn(Stair $block) => Helper::encodeStairs($block, new Writer(Ids::RESIN_BRICK_STAIRS)));
1743 $this->map(Blocks::RESIN_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::RESIN_BRICK_WALL)));
1744 $this->map(Blocks::RESIN_CLUMP(), function(ResinClump $block) : Writer{
1745 return Writer::create(Ids::RESIN_CLUMP)
1746 ->writeFacingFlags($block->getFaces());
1747 });
1748 $this->map(Blocks::ROSE_BUSH(), fn(DoublePlant $block) => Helper::encodeDoublePlant($block, Writer::create(Ids::ROSE_BUSH)));
1749 $this->mapSlab(Blocks::SANDSTONE_SLAB(), Ids::SANDSTONE_SLAB, Ids::SANDSTONE_DOUBLE_SLAB);
1750 $this->mapStairs(Blocks::SANDSTONE_STAIRS(), Ids::SANDSTONE_STAIRS);
1751 $this->map(Blocks::SANDSTONE_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::SANDSTONE_WALL)));
1752 $this->map(Blocks::SEA_PICKLE(), function(SeaPickle $block) : Writer{
1753 return Writer::create(Ids::SEA_PICKLE)
1754 ->writeBool(StateNames::DEAD_BIT, !$block->isUnderwater())
1755 ->writeInt(StateNames::CLUSTER_COUNT, $block->getCount() - 1);
1756 });
1757 $this->map(Blocks::SMALL_DRIPLEAF(), function(SmallDripleaf $block) : Writer{
1758 return Writer::create(Ids::SMALL_DRIPLEAF_BLOCK)
1759 ->writeCardinalHorizontalFacing($block->getFacing())
1760 ->writeBool(StateNames::UPPER_BLOCK_BIT, $block->isTop());
1761 });
1762 $this->map(Blocks::SMOKER(), fn(Furnace $block) => Helper::encodeFurnace($block, Ids::SMOKER, Ids::LIT_SMOKER));
1763 $this->map(Blocks::SMOOTH_QUARTZ(), fn() => Helper::encodeQuartz(Axis::Y, Writer::create(Ids::SMOOTH_QUARTZ)));
1764 $this->mapSlab(Blocks::SMOOTH_QUARTZ_SLAB(), Ids::SMOOTH_QUARTZ_SLAB, Ids::SMOOTH_QUARTZ_DOUBLE_SLAB);
1765 $this->mapStairs(Blocks::SMOOTH_QUARTZ_STAIRS(), Ids::SMOOTH_QUARTZ_STAIRS);
1766 $this->mapSlab(Blocks::SMOOTH_RED_SANDSTONE_SLAB(), Ids::SMOOTH_RED_SANDSTONE_SLAB, Ids::SMOOTH_RED_SANDSTONE_DOUBLE_SLAB);
1767 $this->mapStairs(Blocks::SMOOTH_RED_SANDSTONE_STAIRS(), Ids::SMOOTH_RED_SANDSTONE_STAIRS);
1768 $this->mapSlab(Blocks::SMOOTH_SANDSTONE_SLAB(), Ids::SMOOTH_SANDSTONE_SLAB, Ids::SMOOTH_SANDSTONE_DOUBLE_SLAB);
1769 $this->mapStairs(Blocks::SMOOTH_SANDSTONE_STAIRS(), Ids::SMOOTH_SANDSTONE_STAIRS);
1770 $this->mapSlab(Blocks::SMOOTH_STONE_SLAB(), Ids::SMOOTH_STONE_SLAB, Ids::SMOOTH_STONE_DOUBLE_SLAB);
1771 $this->map(Blocks::SNOW_LAYER(), function(SnowLayer $block) : Writer{
1772 return Writer::create(Ids::SNOW_LAYER)
1773 ->writeBool(StateNames::COVERED_BIT, false)
1774 ->writeInt(StateNames::HEIGHT, $block->getLayers() - 1);
1775 });
1776 $this->map(Blocks::SOUL_CAMPFIRE(), function(SoulCampfire $block) : Writer{
1777 return Writer::create(Ids::SOUL_CAMPFIRE)
1778 ->writeCardinalHorizontalFacing($block->getFacing())
1779 ->writeBool(StateNames::EXTINGUISHED, !$block->isLit());
1780 });
1781 $this->map(Blocks::SOUL_FIRE(), function() : Writer{
1782 return Writer::create(Ids::SOUL_FIRE)
1783 ->writeInt(StateNames::AGE, 0); //useless for soul fire, we don't track it
1784 });
1785 $this->map(Blocks::SOUL_LANTERN(), function(Lantern $block) : Writer{
1786 return Writer::create(Ids::SOUL_LANTERN)
1787 ->writeBool(StateNames::HANGING, $block->isHanging());
1788 });
1789 $this->map(Blocks::SOUL_TORCH(), function(Torch $block) : Writer{
1790 return Writer::create(Ids::SOUL_TORCH)
1791 ->writeTorchFacing($block->getFacing());
1792 });
1793 $this->map(Blocks::SPONGE(), fn(Sponge $block) => Writer::create($block->isWet() ? Ids::WET_SPONGE : Ids::SPONGE));
1794 $this->map(Blocks::STONECUTTER(), fn(Stonecutter $block) => Writer::create(Ids::STONECUTTER_BLOCK)
1795 ->writeCardinalHorizontalFacing($block->getFacing()));
1796 $this->mapSlab(Blocks::STONE_BRICK_SLAB(), Ids::STONE_BRICK_SLAB, Ids::STONE_BRICK_DOUBLE_SLAB);
1797 $this->mapStairs(Blocks::STONE_BRICK_STAIRS(), Ids::STONE_BRICK_STAIRS);
1798 $this->map(Blocks::STONE_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, Writer::create(Ids::STONE_BRICK_WALL)));
1799 $this->map(Blocks::STONE_BUTTON(), fn(StoneButton $block) => Helper::encodeButton($block, new Writer(Ids::STONE_BUTTON)));
1800 $this->map(Blocks::STONE_PRESSURE_PLATE(), fn(StonePressurePlate $block) => Helper::encodeSimplePressurePlate($block, new Writer(Ids::STONE_PRESSURE_PLATE)));
1801 $this->mapSlab(Blocks::STONE_SLAB(), Ids::NORMAL_STONE_SLAB, Ids::NORMAL_STONE_DOUBLE_SLAB);
1802 $this->mapStairs(Blocks::STONE_STAIRS(), Ids::NORMAL_STONE_STAIRS);
1803 $this->map(Blocks::SUGARCANE(), function(Sugarcane $block) : Writer{
1804 return Writer::create(Ids::REEDS)
1805 ->writeInt(StateNames::AGE, $block->getAge());
1806 });
1807 $this->map(Blocks::SUNFLOWER(), fn(DoublePlant $block) => Helper::encodeDoublePlant($block, Writer::create(Ids::SUNFLOWER)));
1808 $this->map(Blocks::SWEET_BERRY_BUSH(), function(SweetBerryBush $block) : Writer{
1809 return Writer::create(Ids::SWEET_BERRY_BUSH)
1810 ->writeInt(StateNames::GROWTH, $block->getAge());
1811 });
1812 $this->map(Blocks::TNT(), fn(TNT $block) => Writer::create($block->worksUnderwater() ? Ids::UNDERWATER_TNT : Ids::TNT)
1813 ->writeBool(StateNames::EXPLODE_BIT, $block->isUnstable())
1814 );
1815 $this->map(Blocks::TORCH(), function(Torch $block) : Writer{
1816 return Writer::create(Ids::TORCH)
1817 ->writeTorchFacing($block->getFacing());
1818 });
1819 $this->map(Blocks::TORCHFLOWER_CROP(), function(TorchflowerCrop $block){
1820 return Writer::create(Ids::TORCHFLOWER_CROP)
1821 ->writeInt(StateNames::GROWTH, $block->isReady() ? 1 : 0);
1822 });
1823 $this->map(Blocks::TRAPPED_CHEST(), function(TrappedChest $block) : Writer{
1824 return Writer::create(Ids::TRAPPED_CHEST)
1825 ->writeCardinalHorizontalFacing($block->getFacing());
1826 });
1827 $this->map(Blocks::TRIPWIRE(), function(Tripwire $block) : Writer{
1828 return Writer::create(Ids::TRIP_WIRE)
1829 ->writeBool(StateNames::ATTACHED_BIT, $block->isConnected())
1830 ->writeBool(StateNames::DISARMED_BIT, $block->isDisarmed())
1831 ->writeBool(StateNames::POWERED_BIT, $block->isTriggered())
1832 ->writeBool(StateNames::SUSPENDED_BIT, $block->isSuspended());
1833 });
1834 $this->map(Blocks::TRIPWIRE_HOOK(), function(TripwireHook $block) : Writer{
1835 return Writer::create(Ids::TRIPWIRE_HOOK)
1836 ->writeBool(StateNames::ATTACHED_BIT, $block->isConnected())
1837 ->writeBool(StateNames::POWERED_BIT, $block->isPowered())
1838 ->writeLegacyHorizontalFacing($block->getFacing());
1839 });
1840 $this->mapSlab(Blocks::TUFF_BRICK_SLAB(), Ids::TUFF_BRICK_SLAB, Ids::TUFF_BRICK_DOUBLE_SLAB);
1841 $this->mapStairs(Blocks::TUFF_BRICK_STAIRS(), Ids::TUFF_BRICK_STAIRS);
1842 $this->map(Blocks::TUFF_BRICK_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::TUFF_BRICK_WALL)));
1843 $this->mapSlab(Blocks::TUFF_SLAB(), Ids::TUFF_SLAB, Ids::TUFF_DOUBLE_SLAB);
1844 $this->mapStairs(Blocks::TUFF_STAIRS(), Ids::TUFF_STAIRS);
1845 $this->map(Blocks::TUFF_WALL(), fn(Wall $block) => Helper::encodeWall($block, new Writer(Ids::TUFF_WALL)));
1846 $this->map(Blocks::TWISTING_VINES(), function(NetherVines $block) : Writer{
1847 return Writer::create(Ids::TWISTING_VINES)
1848 ->writeInt(StateNames::TWISTING_VINES_AGE, $block->getAge());
1849 });
1850 $this->map(Blocks::UNDERWATER_TORCH(), function(UnderwaterTorch $block) : Writer{
1851 return Writer::create(Ids::UNDERWATER_TORCH)
1852 ->writeTorchFacing($block->getFacing());
1853 });
1854 $this->map(Blocks::VINES(), function(Vine $block) : Writer{
1855 return Writer::create(Ids::VINE)
1856 ->writeInt(StateNames::VINE_DIRECTION_BITS, ($block->hasFace(Facing::NORTH) ? BlockLegacyMetadata::VINE_FLAG_NORTH : 0) | ($block->hasFace(Facing::SOUTH) ? BlockLegacyMetadata::VINE_FLAG_SOUTH : 0) | ($block->hasFace(Facing::WEST) ? BlockLegacyMetadata::VINE_FLAG_WEST : 0) | ($block->hasFace(Facing::EAST) ? BlockLegacyMetadata::VINE_FLAG_EAST : 0));
1857 });
1858 $this->map(Blocks::WALL_BANNER(), function(WallBanner $block) : Writer{
1859 return Writer::create(Ids::WALL_BANNER)
1860 ->writeHorizontalFacing($block->getFacing());
1861 });
1862 $this->map(Blocks::WATER(), fn(Water $block) => Helper::encodeLiquid($block, Ids::WATER, Ids::FLOWING_WATER));
1863 $this->map(Blocks::WEEPING_VINES(), function(NetherVines $block) : Writer{
1864 return Writer::create(Ids::WEEPING_VINES)
1865 ->writeInt(StateNames::WEEPING_VINES_AGE, $block->getAge());
1866 });
1867 $this->map(Blocks::WEIGHTED_PRESSURE_PLATE_HEAVY(), function(WeightedPressurePlate $block) : Writer{
1868 return Writer::create(Ids::HEAVY_WEIGHTED_PRESSURE_PLATE)
1869 ->writeInt(StateNames::REDSTONE_SIGNAL, $block->getOutputSignalStrength());
1870 });
1871 $this->map(Blocks::WEIGHTED_PRESSURE_PLATE_LIGHT(), function(WeightedPressurePlate $block) : Writer{
1872 return Writer::create(Ids::LIGHT_WEIGHTED_PRESSURE_PLATE)
1873 ->writeInt(StateNames::REDSTONE_SIGNAL, $block->getOutputSignalStrength());
1874 });
1875 $this->map(Blocks::WHEAT(), fn(Wheat $block) => Helper::encodeCrops($block, new Writer(Ids::WHEAT)));
1876 }
1877}