PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
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
36use Symfony\Component\Filesystem\Path;
37use const PHP_INT_MAX;
38use const pocketmine\BEDROCK_BLOCK_UPGRADE_SCHEMA_PATH;
39
47 private static ?BlockObjectToStateSerializer $blockStateSerializer = null;
48
49 private static ?BlockStateToObjectDeserializer $blockStateDeserializer = null;
50
51 private static ?BlockDataUpgrader $blockDataUpgrader = null;
52
53 private static ?BlockStateData $unknownBlockStateData = null;
54
55 public static function getDeserializer() : BlockStateToObjectDeserializer{
56 return self::$blockStateDeserializer ??= new BlockStateToObjectDeserializer();
57 }
58
59 public static function getSerializer() : BlockObjectToStateSerializer{
60 return self::$blockStateSerializer ??= new BlockObjectToStateSerializer();
61 }
62
63 public static function getUpgrader() : BlockDataUpgrader{
64 if(self::$blockDataUpgrader === null){
66 Path::join(BEDROCK_BLOCK_UPGRADE_SCHEMA_PATH, 'nbt_upgrade_schema'),
67 PHP_INT_MAX
68 ));
69 self::$blockDataUpgrader = new BlockDataUpgrader(
70 BlockIdMetaUpgrader::loadFromString(
71 Filesystem::fileGetContents(Path::join(
72 BEDROCK_BLOCK_UPGRADE_SCHEMA_PATH,
73 'id_meta_to_nbt/1.12.0.bin'
74 )),
75 LegacyBlockIdToStringIdMap::getInstance(),
76 $blockStateUpgrader
77 ),
78 $blockStateUpgrader
79 );
80 }
81
82 return self::$blockDataUpgrader;
83 }
84
85 public static function getUnknownBlockStateData() : BlockStateData{
86 return self::$unknownBlockStateData ??= BlockStateData::current(BlockTypeNames::INFO_UPDATE, []);
87 }
88}