BlockStateUpgrader: do not apply backwards-incompatible schemas to blockstates already on the correct version

this notably led to corruption of glow_lichen and sculk_vein in 1.18.10.
This commit is contained in:
Dylan K. Taylor
2022-02-10 20:51:31 +00:00
parent 8a11ed70e3
commit 905eee3198
3 changed files with 42 additions and 8 deletions

View File

@ -64,6 +64,8 @@ final class BlockStateUpgradeSchema{
*/
public array $remappedStates = [];
private ?bool $backwardsCompatible = null;
public function __construct(
public int $maxVersionMajor,
public int $maxVersionMinor,
@ -91,4 +93,22 @@ final class BlockStateUpgradeSchema{
return true;
}
public function isBackwardsCompatible() : bool{
if($this->backwardsCompatible === null){
$this->backwardsCompatible = true;
foreach([
$this->renamedIds,
$this->removedProperties,
$this->remappedPropertyValues,
$this->remappedStates
] as $bcBreakingRules){
if(count($bcBreakingRules) !== 0){
$this->backwardsCompatible = false;
}
}
}
//schemas which only add properties are backwards compatible
return $this->backwardsCompatible;
}
}