41 private array $mappingTable,
49 return $this->mappingTable[$id][$meta] ??
50 $this->mappingTable[$id][0] ??
58 $stringId = $this->legacyNumericIdMap->legacyToString($id);
59 if($stringId ===
null){
62 return $this->fromStringIdMeta($stringId, $meta);
70 $this->legacyNumericIdMap->add($stringId, $intId);
78 if(isset($this->mappingTable[$stringId][$meta])){
79 throw new \InvalidArgumentException(
"A mapping for $stringId:$meta already exists");
81 $this->mappingTable[$stringId][$meta] = $stateData;
84 public static function loadFromString(
string $data, LegacyBlockIdToStringIdMap $idMap, BlockStateUpgrader $blockStateUpgrader) : self{
87 $legacyStateMapReader =
new BinaryStream($data);
88 $nbtReader =
new LittleEndianNbtSerializer();
90 $idCount = $legacyStateMapReader->getUnsignedVarInt();
91 for($idIndex = 0; $idIndex < $idCount; $idIndex++){
92 $id = $legacyStateMapReader->get($legacyStateMapReader->getUnsignedVarInt());
94 $metaCount = $legacyStateMapReader->getUnsignedVarInt();
95 for($metaIndex = 0; $metaIndex < $metaCount; $metaIndex++){
96 $meta = $legacyStateMapReader->getUnsignedVarInt();
98 $offset = $legacyStateMapReader->getOffset();
99 $state = $nbtReader->read($legacyStateMapReader->getBuffer(), $offset)->mustGetCompoundTag();
100 $legacyStateMapReader->setOffset($offset);
101 $mappingTable[$id][$meta] = $blockStateUpgrader->upgrade(BlockStateData::fromNbt($state));
104 if(!$legacyStateMapReader->feof()){
105 throw new BinaryDataException(
"Unexpected trailing data in legacy state map data");
108 return new self($mappingTable, $idMap);