22declare(strict_types=1);
24namespace pocketmine\data\bedrock\item\upgrade;
27use
const SORT_NUMERIC;
38 private array $idMetaUpgradeSchemas = [];
45 array $idMetaUpgradeSchemas,
47 foreach($idMetaUpgradeSchemas as $schema){
48 $this->addSchema($schema);
53 if(isset($this->idMetaUpgradeSchemas[$schema->getSchemaId()])){
54 throw new \InvalidArgumentException(
"Already have a schema with priority " . $schema->getSchemaId());
56 $this->idMetaUpgradeSchemas[$schema->getSchemaId()] = $schema;
57 ksort($this->idMetaUpgradeSchemas, SORT_NUMERIC);
64 public function getSchemas() : array{ return $this->idMetaUpgradeSchemas; }
69 public function upgrade(
string $id,
int $meta) : array{
72 foreach($this->idMetaUpgradeSchemas as $schema){
73 if(($remappedMetaId = $schema->remapMeta($newId, $newMeta)) !==
null){
74 $newId = $remappedMetaId;
76 }elseif(($renamedId = $schema->renameId($newId)) !==
null){
81 return [$newId, $newMeta];