mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
BlockStateUpgrader: calculate output version ID in a less stupid way
this improves the performance by a conservative 10%.
This commit is contained in:
parent
8ec304e66e
commit
a6202d0442
@ -38,6 +38,8 @@ final class BlockStateUpgrader{
|
|||||||
/** @var BlockStateUpgradeSchema[] */
|
/** @var BlockStateUpgradeSchema[] */
|
||||||
private array $upgradeSchemas = [];
|
private array $upgradeSchemas = [];
|
||||||
|
|
||||||
|
private int $outputVersion = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param BlockStateUpgradeSchema[] $upgradeSchemas
|
* @param BlockStateUpgradeSchema[] $upgradeSchemas
|
||||||
* @phpstan-param array<int, BlockStateUpgradeSchema> $upgradeSchemas
|
* @phpstan-param array<int, BlockStateUpgradeSchema> $upgradeSchemas
|
||||||
@ -56,14 +58,14 @@ final class BlockStateUpgrader{
|
|||||||
$this->upgradeSchemas[$schemaId] = $schema;
|
$this->upgradeSchemas[$schemaId] = $schema;
|
||||||
|
|
||||||
ksort($this->upgradeSchemas, SORT_NUMERIC);
|
ksort($this->upgradeSchemas, SORT_NUMERIC);
|
||||||
|
|
||||||
|
$this->outputVersion = max($this->outputVersion, $schema->getVersionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function upgrade(BlockStateData $blockStateData) : BlockStateData{
|
public function upgrade(BlockStateData $blockStateData) : BlockStateData{
|
||||||
$version = $blockStateData->getVersion();
|
$version = $blockStateData->getVersion();
|
||||||
$highestVersion = $version;
|
|
||||||
foreach($this->upgradeSchemas as $schema){
|
foreach($this->upgradeSchemas as $schema){
|
||||||
$resultVersion = $schema->versionId;
|
$resultVersion = $schema->versionId;
|
||||||
$highestVersion = max($highestVersion, $resultVersion);
|
|
||||||
if($version > $resultVersion){
|
if($version > $resultVersion){
|
||||||
//even if this is actually the same version, we have to apply it anyway because mojang are dumb and
|
//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 :(
|
//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
|
//always update the version number of the blockstate, even if it didn't change - this is needed for
|
||||||
//external tools
|
//external tools
|
||||||
$blockStateData = new BlockStateData($blockStateData->getName(), $blockStateData->getStates(), $highestVersion);
|
$blockStateData = new BlockStateData($blockStateData->getName(), $blockStateData->getStates(), $this->outputVersion);
|
||||||
}
|
}
|
||||||
return $blockStateData;
|
return $blockStateData;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user