diff --git a/src/data/bedrock/item/upgrade/ItemDataUpgrader.php b/src/data/bedrock/item/upgrade/ItemDataUpgrader.php index defaed6a3..f37bc7f8e 100644 --- a/src/data/bedrock/item/upgrade/ItemDataUpgrader.php +++ b/src/data/bedrock/item/upgrade/ItemDataUpgrader.php @@ -64,10 +64,10 @@ final class ItemDataUpgrader{ } public function addIdMetaUpgradeSchema(ItemIdMetaUpgradeSchema $schema) : void{ - if(isset($this->idMetaUpgradeSchemas[$schema->getPriority()])){ - throw new \InvalidArgumentException("Already have a schema with priority " . $schema->getPriority()); + if(isset($this->idMetaUpgradeSchemas[$schema->getSchemaId()])){ + throw new \InvalidArgumentException("Already have a schema with priority " . $schema->getSchemaId()); } - $this->idMetaUpgradeSchemas[$schema->getPriority()] = $schema; + $this->idMetaUpgradeSchemas[$schema->getSchemaId()] = $schema; ksort($this->idMetaUpgradeSchemas, SORT_NUMERIC); } diff --git a/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchema.php b/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchema.php index e88111ef2..8a271e430 100644 --- a/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchema.php +++ b/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchema.php @@ -36,10 +36,10 @@ final class ItemIdMetaUpgradeSchema{ public function __construct( private array $renamedIds, private array $remappedMetas, - private int $priority + private int $schemaId ){} - public function getPriority() : int{ return $this->priority; } + public function getSchemaId() : int{ return $this->schemaId; } public function renameId(string $id) : ?string{ return $this->renamedIds[mb_strtolower($id, 'US-ASCII')] ?? null; diff --git a/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchemaUtils.php b/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchemaUtils.php index 6aade2eaa..ef1543a80 100644 --- a/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchemaUtils.php +++ b/src/data/bedrock/item/upgrade/ItemIdMetaUpgradeSchemaUtils.php @@ -39,7 +39,7 @@ final class ItemIdMetaUpgradeSchemaUtils{ * @return ItemIdMetaUpgradeSchema[] * @phpstan-return array */ - public static function loadSchemas(string $path) : array{ + public static function loadSchemas(string $path, int $maxSchemaId) : array{ $iterator = new \RegexIterator( new \FilesystemIterator( $path, @@ -55,26 +55,29 @@ final class ItemIdMetaUpgradeSchemaUtils{ /** @var string[] $matches */ foreach($iterator as $matches){ $filename = $matches[0]; - $priority = (int) $matches[1]; + $schemaId = (int) $matches[1]; + if($schemaId > $maxSchemaId){ + continue; + } $fullPath = Path::join($path, $filename); $raw = Filesystem::fileGetContents($fullPath); try{ - $schema = self::loadSchemaFromString($raw, $priority); + $schema = self::loadSchemaFromString($raw, $schemaId); }catch(\RuntimeException $e){ throw new \RuntimeException("Loading schema file $fullPath: " . $e->getMessage(), 0, $e); } - $result[$priority] = $schema; + $result[$schemaId] = $schema; } ksort($result, SORT_NUMERIC); return $result; } - public static function loadSchemaFromString(string $raw, int $priority) : ItemIdMetaUpgradeSchema{ + public static function loadSchemaFromString(string $raw, int $schemaId) : ItemIdMetaUpgradeSchema{ try{ $json = json_decode($raw, false, flags: JSON_THROW_ON_ERROR); }catch(\JsonException $e){ @@ -91,6 +94,6 @@ final class ItemIdMetaUpgradeSchemaUtils{ throw new \RuntimeException($e->getMessage(), 0, $e); } - return new ItemIdMetaUpgradeSchema($model->renamedIds, $model->remappedMetas, $priority); + return new ItemIdMetaUpgradeSchema($model->renamedIds, $model->remappedMetas, $schemaId); } } diff --git a/src/world/format/io/GlobalItemDataHandlers.php b/src/world/format/io/GlobalItemDataHandlers.php index dab291b58..d7530113a 100644 --- a/src/world/format/io/GlobalItemDataHandlers.php +++ b/src/world/format/io/GlobalItemDataHandlers.php @@ -33,6 +33,7 @@ use Symfony\Component\Filesystem\Path; use const pocketmine\BEDROCK_ITEM_UPGRADE_SCHEMA_PATH; final class GlobalItemDataHandlers{ + public const MAX_ITEM_ID_UPGRADE_SCHEMA_ID = 81; //0081_1.18.30_to_1.19.30.34_beta.json private static ?ItemSerializer $itemSerializer = null; @@ -53,7 +54,7 @@ final class GlobalItemDataHandlers{ LegacyItemIdToStringIdMap::getInstance(), R12ItemIdToBlockIdMap::getInstance(), GlobalBlockStateHandlers::getUpgrader(), - ItemIdMetaUpgradeSchemaUtils::loadSchemas(Path::join(BEDROCK_ITEM_UPGRADE_SCHEMA_PATH, 'id_meta_upgrade_schema')) + ItemIdMetaUpgradeSchemaUtils::loadSchemas(Path::join(BEDROCK_ITEM_UPGRADE_SCHEMA_PATH, 'id_meta_upgrade_schema'), self::MAX_ITEM_ID_UPGRADE_SCHEMA_ID) ); } }