First look at loading 1.13+ worlds

This commit is contained in:
Dylan K. Taylor
2022-02-07 03:04:29 +00:00
parent dd3b79b142
commit e58b3ba46c
12 changed files with 321 additions and 68 deletions

View File

@ -180,13 +180,13 @@ final class BlockStateUpgradeSchemaUtils{
*
* @return BlockStateUpgradeSchema[]
*/
public static function loadSchemas(string $path) : array{
public static function loadSchemas(string $path, int $currentVersion) : array{
$iterator = new \RegexIterator(
new \FilesystemIterator(
$path,
\FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS
),
'/\/mapping_schema_(\d{4}).*\.json$/',
'/\/(\d{4}).*\.json$/',
\RegexIterator::GET_MATCH
);
@ -209,7 +209,14 @@ final class BlockStateUpgradeSchemaUtils{
}
$model = $jsonMapper->map($json, new BlockStateUpgradeSchemaModel());
$result[$priority] = self::fromJsonModel($model);
$schema = self::fromJsonModel($model);
if($schema->getVersionId() > $currentVersion){
//this might be a beta schema which shouldn't be applicable
//TODO: why do we load the whole schema just to throw it away if it's too new? ...
continue;
}
$result[$priority] = $schema;
}
ksort($result, SORT_NUMERIC);

View File

@ -34,6 +34,16 @@ final class BlockStateUpgrader{
/** @var BlockStateUpgradeSchema[][] */
private array $upgradeSchemas = [];
/**
* @param BlockStateUpgradeSchema[] $upgradeSchemas
* @phpstan-param array<int, BlockStateUpgradeSchema> $upgradeSchemas
*/
public function __construct(array $upgradeSchemas){
foreach($upgradeSchemas as $priority => $schema){
$this->addSchema($schema, $priority);
}
}
public function addSchema(BlockStateUpgradeSchema $schema, int $priority) : void{
if(isset($this->upgradeSchemas[$schema->getVersionId()][$priority])){
throw new \InvalidArgumentException("Another schema already has this priority");