feof()){ $list[] = $stream->getNbtCompoundRoot(); } $this->bedrockKnownStates = $list; $this->setupLegacyMappings(); } private function setupLegacyMappings() : void{ $legacyIdMap = LegacyBlockIdToStringIdMap::getInstance(); /** @var R12ToCurrentBlockMapEntry[] $legacyStateMap */ $legacyStateMap = []; $legacyStateMapReader = new PacketSerializer(file_get_contents(\pocketmine\RESOURCE_PATH . "vanilla/r12_to_current_block_map.bin")); $nbtReader = new NetworkNbtSerializer(); while(!$legacyStateMapReader->feof()){ $id = $legacyStateMapReader->getString(); $meta = $legacyStateMapReader->getLShort(); $offset = $legacyStateMapReader->getOffset(); $state = $nbtReader->read($legacyStateMapReader->getBuffer(), $offset)->mustGetCompoundTag(); $legacyStateMapReader->setOffset($offset); $legacyStateMap[] = new R12ToCurrentBlockMapEntry($id, $meta, $state); } /** * @var int[][] $idToStatesMap string id -> int[] list of candidate state indices */ $idToStatesMap = []; foreach($this->bedrockKnownStates as $k => $state){ $idToStatesMap[$state->getString("name")][] = $k; } foreach($legacyStateMap as $pair){ $id = $legacyIdMap->stringToLegacy($pair->getId()) ?? null; if($id === null){ throw new \RuntimeException("No legacy ID matches " . $pair->getId()); } $data = $pair->getMeta(); if($data > 15){ //we can't handle metadata with more than 4 bits continue; } $mappedState = $pair->getBlockState(); $mappedName = $mappedState->getString("name"); if(!isset($idToStatesMap[$mappedName])){ throw new \RuntimeException("Mapped new state does not appear in network table"); } foreach($idToStatesMap[$mappedName] as $k){ $networkState = $this->bedrockKnownStates[$k]; if($mappedState->equals($networkState)){ $this->registerMapping($k, $id, $data); continue 2; } } throw new \RuntimeException("Mapped new state does not appear in network table"); } } public function toRuntimeId(int $internalStateId) : int{ return $this->legacyToRuntimeMap[$internalStateId] ?? $this->legacyToRuntimeMap[BlockLegacyIds::INFO_UPDATE << 4]; } public function fromRuntimeId(int $runtimeId) : int{ return $this->runtimeToLegacyMap[$runtimeId]; } private function registerMapping(int $staticRuntimeId, int $legacyId, int $legacyMeta) : void{ $this->legacyToRuntimeMap[($legacyId << 4) | $legacyMeta] = $staticRuntimeId; $this->runtimeToLegacyMap[$staticRuntimeId] = ($legacyId << 4) | $legacyMeta; } /** * @return CompoundTag[] */ public function getBedrockKnownStates() : array{ return $this->bedrockKnownStates; } }