mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
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:
parent
c67e42a723
commit
56e6a55645
@ -81,4 +81,15 @@ abstract class LegacyToStringBidirectionalIdMap{
|
||||
public function getStringToLegacyMap() : array{
|
||||
return $this->stringToLegacy;
|
||||
}
|
||||
|
||||
public function add(string $string, int $legacy) : void{
|
||||
if(isset($this->legacyToString[$legacy])){
|
||||
throw new \InvalidArgumentException("Legacy ID $legacy is already mapped to string " . $this->legacyToString[$legacy]);
|
||||
}
|
||||
if(isset($this->stringToLegacy[$string])){
|
||||
throw new \InvalidArgumentException("String ID $string is already mapped to legacy ID " . $this->stringToLegacy[$string]);
|
||||
}
|
||||
$this->legacyToString[$legacy] = $string;
|
||||
$this->stringToLegacy[$string] = $legacy;
|
||||
}
|
||||
}
|
||||
|
@ -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 = [];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user