BlockStateUpgrader: calculate output version ID in a less stupid way

this improves the performance by a conservative 10%.
This commit is contained in:
Dylan K. Taylor 2024-03-12 11:48:48 +00:00
parent 8ec304e66e
commit a6202d0442
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -38,6 +38,8 @@ final class BlockStateUpgrader{
/** @var BlockStateUpgradeSchema[] */
private array $upgradeSchemas = [];
private int $outputVersion = 0;
/**
* @param BlockStateUpgradeSchema[] $upgradeSchemas
* @phpstan-param array<int, BlockStateUpgradeSchema> $upgradeSchemas
@ -56,14 +58,14 @@ final class BlockStateUpgrader{
$this->upgradeSchemas[$schemaId] = $schema;
ksort($this->upgradeSchemas, SORT_NUMERIC);
$this->outputVersion = max($this->outputVersion, $schema->getVersionId());
}
public function upgrade(BlockStateData $blockStateData) : BlockStateData{
$version = $blockStateData->getVersion();
$highestVersion = $version;
foreach($this->upgradeSchemas as $schema){
$resultVersion = $schema->versionId;
$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 :(
@ -93,10 +95,10 @@ final class BlockStateUpgrader{
}
}
if($highestVersion > $version){
if($this->outputVersion > $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);
$blockStateData = new BlockStateData($blockStateData->getName(), $blockStateData->getStates(), $this->outputVersion);
}
return $blockStateData;
}