From a6202d0442029ffe628484cb9ac1135e400229d4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 12 Mar 2024 11:48:48 +0000 Subject: [PATCH] BlockStateUpgrader: calculate output version ID in a less stupid way this improves the performance by a conservative 10%. --- src/data/bedrock/block/upgrade/BlockStateUpgrader.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/data/bedrock/block/upgrade/BlockStateUpgrader.php b/src/data/bedrock/block/upgrade/BlockStateUpgrader.php index e91a5cf60..501ca750a 100644 --- a/src/data/bedrock/block/upgrade/BlockStateUpgrader.php +++ b/src/data/bedrock/block/upgrade/BlockStateUpgrader.php @@ -38,6 +38,8 @@ final class BlockStateUpgrader{ /** @var BlockStateUpgradeSchema[] */ private array $upgradeSchemas = []; + private int $outputVersion = 0; + /** * @param BlockStateUpgradeSchema[] $upgradeSchemas * @phpstan-param array $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; }