BlockStateUpgrader: make sure the returned state always has an updated version ID

PM itself doesn't require this, but it's useful for tools to know whether to upgrade the schema again (e.g. in testing scenarios).
This commit is contained in:
Dylan K. Taylor 2023-04-28 17:26:19 +01:00
parent ff8301b86c
commit e2108557ab
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -56,8 +56,10 @@ final class BlockStateUpgrader{
public function upgrade(BlockStateData $blockStateData) : BlockStateData{
$version = $blockStateData->getVersion();
$highestVersion = $version;
foreach($this->upgradeSchemas as $schema){
$resultVersion = $schema->getVersionId();
$highestVersion = max($highestVersion, $resultVersion);
if($version > $resultVersion){
//even if this is actually the same version, we have to apply it anyway because mojang are dumb and
//didn't always bump the blockstate version when changing it :(
@ -96,6 +98,11 @@ final class BlockStateUpgrader{
}
}
if($highestVersion > $version){
//always update the version number of the blockstate, even if it didn't change - this is needed for
//external tools
$blockStateData = new BlockStateData($blockStateData->getName(), $blockStateData->getStates(), $highestVersion);
}
return $blockStateData;
}