Make BlockIdMetaUpgrader API less dumb

the old impl prevented registering more than one meta -> state mapping since the legacy numeric ID map would throw an exception if attempting to map the same ID more than once.
This commit is contained in:
Dylan K. Taylor 2022-07-19 16:21:27 +01:00
parent 9a8902d1fe
commit f64e306fb8
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -52,16 +52,23 @@ final class BlockIdMetaUpgrader{
return $this->fromStringIdMeta($stringId, $meta); 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 * 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. * stored custom blocks from older versions of PocketMine-MP.
*/ */
public function addMapping(string $stringId, int $intId, int $meta, BlockStateData $stateData) : void{ public function addIdMetaToStateMapping(string $stringId, int $meta, BlockStateData $stateData) : void{
if(isset($this->mappingTable[$stringId][$meta])){ if(isset($this->mappingTable[$stringId][$meta])){
throw new \InvalidArgumentException("A mapping for $stringId:$meta already exists"); throw new \InvalidArgumentException("A mapping for $stringId:$meta already exists");
} }
$this->mappingTable[$stringId][$meta] = $stateData; $this->mappingTable[$stringId][$meta] = $stateData;
$this->legacyNumericIdMap->add($stringId, $intId);
} }
public static function loadFromString(string $data, LegacyBlockIdToStringIdMap $idMap, BlockStateUpgrader $blockStateUpgrader) : self{ public static function loadFromString(string $data, LegacyBlockIdToStringIdMap $idMap, BlockStateUpgrader $blockStateUpgrader) : self{