> $mappingTable */ public function __construct( private array $mappingTable, private LegacyBlockIdToStringIdMap $legacyNumericIdMap ){} public function fromStringIdMeta(string $id, int $meta) : ?BlockStateData{ return $this->mappingTable[$id][$meta] ?? $this->mappingTable[$id][0] ?? null; } public function fromIntIdMeta(int $id, int $meta) : ?BlockStateData{ $stringId = $this->legacyNumericIdMap->legacyToString($id); if($stringId === null){ return null; } return $this->fromStringIdMeta($stringId, $meta); } /** * Adds a mapping of legacy block numeric ID to modern string ID. This is used for upgrading blocks from pre-1.2.13 * worlds (PM3). It's also needed for upgrading flower pot contents and falling blocks from PM4 worlds. */ public function addIntIdToStringIdMapping(int $intId, string $stringId) : void{ $this->legacyNumericIdMap->add($stringId, $intId); } /** * Adds a mapping of legacy block ID and meta to modern blockstate data. This may be needed for upgrading data from * stored custom blocks from older versions of PocketMine-MP. */ public function addIdMetaToStateMapping(string $stringId, int $meta, BlockStateData $stateData) : void{ if(isset($this->mappingTable[$stringId][$meta])){ throw new \InvalidArgumentException("A mapping for $stringId:$meta already exists"); } $this->mappingTable[$stringId][$meta] = $stateData; } public static function loadFromString(string $data, LegacyBlockIdToStringIdMap $idMap, BlockStateUpgrader $blockStateUpgrader) : self{ $mappingTable = []; $legacyStateMapReader = new BinaryStream($data); $nbtReader = new LittleEndianNbtSerializer(); $idCount = $legacyStateMapReader->getUnsignedVarInt(); for($idIndex = 0; $idIndex < $idCount; $idIndex++){ $id = $legacyStateMapReader->get($legacyStateMapReader->getUnsignedVarInt()); $metaCount = $legacyStateMapReader->getUnsignedVarInt(); for($metaIndex = 0; $metaIndex < $metaCount; $metaIndex++){ $meta = $legacyStateMapReader->getUnsignedVarInt(); $offset = $legacyStateMapReader->getOffset(); $state = $nbtReader->read($legacyStateMapReader->getBuffer(), $offset)->mustGetCompoundTag(); $legacyStateMapReader->setOffset($offset); $mappingTable[$id][$meta] = $blockStateUpgrader->upgrade(BlockStateData::fromNbt($state)); } } if(!$legacyStateMapReader->feof()){ throw new BinaryDataException("Unexpected trailing data in legacy state map data"); } return new self($mappingTable, $idMap); } }