PocketMine-MP 5.18.2 git-00e39821f06a4b6d728d35053c2621dbb19369ff
BlockDataUpgrader.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\upgrade;
25
29
31
32 public function __construct(
33 private BlockIdMetaUpgrader $blockIdMetaUpgrader,
34 private BlockStateUpgrader $blockStateUpgrader
35 ){}
36
40 public function upgradeIntIdMeta(int $id, int $meta) : BlockStateData{
41 return $this->blockIdMetaUpgrader->fromIntIdMeta($id, $meta);
42 }
43
47 public function upgradeStringIdMeta(string $id, int $meta) : BlockStateData{
48 return $this->blockIdMetaUpgrader->fromStringIdMeta($id, $meta);
49 }
50
55 if($tag->getTag("name") !== null && $tag->getTag("val") !== null){
56 //Legacy (pre-1.13) blockstate - upgrade it to a version we understand
57 $id = $tag->getString("name");
58 $data = $tag->getShort("val");
59
60 $blockStateData = $this->upgradeStringIdMeta($id, $data);
61 }else{
62 //Modern (post-1.13) blockstate
63 $blockStateData = BlockStateData::fromNbt($tag);
64 }
65
66 return $this->blockStateUpgrader->upgrade($blockStateData);
67 }
68
69 public function getBlockStateUpgrader() : BlockStateUpgrader{ return $this->blockStateUpgrader; }
70
71 public function getBlockIdMetaUpgrader() : BlockIdMetaUpgrader{ return $this->blockIdMetaUpgrader; }
72}