LegacyBlockStateMapper: provide a way to add custom upgrade mappings

this will be needed by plugin developers to upgrade old custom blocks from PM4.
This commit is contained in:
Dylan K. Taylor
2022-07-07 19:44:16 +01:00
parent c67e42a723
commit 56e6a55645
2 changed files with 23 additions and 0 deletions

View File

@ -52,6 +52,18 @@ final class LegacyBlockStateMapper{
return $this->fromStringIdMeta($stringId, $meta);
}
/**
* 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 addMapping(string $stringId, int $intId, 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;
$this->legacyNumericIdMap->add($intId, $stringId);
}
public static function loadFromString(string $data, LegacyBlockIdToStringIdMap $idMap, BlockStateUpgrader $blockStateUpgrader) : self{
$mappingTable = [];