From e2108557abb8503656111b51cd07fa2f1c3cee27 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 28 Apr 2023 17:26:19 +0100 Subject: [PATCH] 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). --- src/data/bedrock/block/upgrade/BlockStateUpgrader.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/data/bedrock/block/upgrade/BlockStateUpgrader.php b/src/data/bedrock/block/upgrade/BlockStateUpgrader.php index b7fd5a422..949bd27b1 100644 --- a/src/data/bedrock/block/upgrade/BlockStateUpgrader.php +++ b/src/data/bedrock/block/upgrade/BlockStateUpgrader.php @@ -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; }