PocketMine-MP 5.33.2 git-09cc76ae2b49f1fe3ab0253e6e987fb82bd0a08f
Loading...
Searching...
No Matches
GlobalBlockStateHandlers.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\world\format\io;
25
38use Symfony\Component\Filesystem\Path;
39use const PHP_INT_MAX;
40use const pocketmine\BEDROCK_BLOCK_UPGRADE_SCHEMA_PATH;
41
49 private static ?BlockDataUpgrader $blockDataUpgrader = null;
50
51 private static ?BlockStateData $unknownBlockStateData = null;
52
53 private static ?BlockSerializerDeserializerRegistrar $registrar = null;
54
55 public static function getRegistrar() : BlockSerializerDeserializerRegistrar{
56 if(self::$registrar === null){
57 $deserializer = new BlockStateToObjectDeserializer();
58 $serializer = new BlockObjectToStateSerializer();
59 self::$registrar = new BlockSerializerDeserializerRegistrar($deserializer, $serializer);
60 VanillaBlockMappings::init(self::$registrar);
61 }
62 return self::$registrar;
63 }
64
65 public static function getDeserializer() : BlockStateToObjectDeserializer{
66 return self::getRegistrar()->deserializer;
67 }
68
69 public static function getSerializer() : BlockObjectToStateSerializer{
70 return self::getRegistrar()->serializer;
71 }
72
73 public static function getUpgrader() : BlockDataUpgrader{
74 if(self::$blockDataUpgrader === null){
76 Path::join(BEDROCK_BLOCK_UPGRADE_SCHEMA_PATH, 'nbt_upgrade_schema'),
77 PHP_INT_MAX
78 ));
79 self::$blockDataUpgrader = new BlockDataUpgrader(
80 BlockIdMetaUpgrader::loadFromString(
81 Filesystem::fileGetContents(Path::join(
82 BEDROCK_BLOCK_UPGRADE_SCHEMA_PATH,
83 'id_meta_to_nbt/1.12.0.bin'
84 )),
85 LegacyBlockIdToStringIdMap::getInstance(),
86 $blockStateUpgrader
87 ),
88 $blockStateUpgrader
89 );
90 }
91
92 return self::$blockDataUpgrader;
93 }
94
95 public static function getUnknownBlockStateData() : BlockStateData{
96 return self::$unknownBlockStateData ??= BlockStateData::current(BlockTypeNames::INFO_UPDATE, []);
97 }
98}