mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-12 12:55:21 +00:00
BlockStateUpgrader: extract state remap to its own function
This commit is contained in:
parent
dbc7105e5b
commit
ac8dbf8640
@ -69,44 +69,14 @@ final class BlockStateUpgrader{
|
|||||||
//didn't always bump the blockstate version when changing it :(
|
//didn't always bump the blockstate version when changing it :(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$oldName = $blockStateData->getName();
|
|
||||||
$oldState = $blockStateData->getStates();
|
|
||||||
if(isset($schema->remappedStates[$oldName])){
|
|
||||||
foreach($schema->remappedStates[$oldName] as $remap){
|
|
||||||
if(count($remap->oldState) > count($oldState)){
|
|
||||||
//match criteria has more requirements than we have state properties
|
|
||||||
continue; //try next state
|
|
||||||
}
|
|
||||||
foreach(Utils::stringifyKeys($remap->oldState) as $k => $v){
|
|
||||||
if(!isset($oldState[$k]) || !$oldState[$k]->equals($v)){
|
|
||||||
continue 2; //try next state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(is_string($remap->newName)){
|
$newStateData = $this->applyStateRemapped($schema, $blockStateData);
|
||||||
$newName = $remap->newName;
|
if($newStateData !== null){
|
||||||
}else{
|
$blockStateData = $newStateData;
|
||||||
$flattenedValue = $oldState[$remap->newName->flattenedProperty] ?? null;
|
continue;
|
||||||
if($flattenedValue instanceof StringTag){
|
|
||||||
$newName = sprintf("%s%s%s", $remap->newName->prefix, $flattenedValue->getValue(), $remap->newName->suffix);
|
|
||||||
unset($oldState[$remap->newName->flattenedProperty]);
|
|
||||||
}else{
|
|
||||||
//flattened property is not a TAG_String, so this transformation is not applicable
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$newState = $remap->newState;
|
|
||||||
foreach($remap->copiedState as $stateName){
|
|
||||||
if(isset($oldState[$stateName])){
|
|
||||||
$newState[$stateName] = $oldState[$stateName];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$blockStateData = new BlockStateData($newName, $newState, $resultVersion);
|
|
||||||
continue 2; //try next schema
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oldName = $blockStateData->getName();
|
||||||
$newName = $schema->renamedIds[$oldName] ?? null;
|
$newName = $schema->renamedIds[$oldName] ?? null;
|
||||||
|
|
||||||
$stateChanges = 0;
|
$stateChanges = 0;
|
||||||
@ -131,6 +101,49 @@ final class BlockStateUpgrader{
|
|||||||
return $blockStateData;
|
return $blockStateData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function applyStateRemapped(BlockStateUpgradeSchema $schema, BlockStateData $blockStateData) : ?BlockStateData{
|
||||||
|
$oldName = $blockStateData->getName();
|
||||||
|
$oldState = $blockStateData->getStates();
|
||||||
|
|
||||||
|
if(isset($schema->remappedStates[$oldName])){
|
||||||
|
foreach($schema->remappedStates[$oldName] as $remap){
|
||||||
|
if(count($remap->oldState) > count($oldState)){
|
||||||
|
//match criteria has more requirements than we have state properties
|
||||||
|
continue; //try next state
|
||||||
|
}
|
||||||
|
foreach(Utils::stringifyKeys($remap->oldState) as $k => $v){
|
||||||
|
if(!isset($oldState[$k]) || !$oldState[$k]->equals($v)){
|
||||||
|
continue 2; //try next state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_string($remap->newName)){
|
||||||
|
$newName = $remap->newName;
|
||||||
|
}else{
|
||||||
|
$flattenedValue = $oldState[$remap->newName->flattenedProperty] ?? null;
|
||||||
|
if($flattenedValue instanceof StringTag){
|
||||||
|
$newName = sprintf("%s%s%s", $remap->newName->prefix, $flattenedValue->getValue(), $remap->newName->suffix);
|
||||||
|
unset($oldState[$remap->newName->flattenedProperty]);
|
||||||
|
}else{
|
||||||
|
//flattened property is not a TAG_String, so this transformation is not applicable
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$newState = $remap->newState;
|
||||||
|
foreach($remap->copiedState as $stateName){
|
||||||
|
if(isset($oldState[$stateName])){
|
||||||
|
$newState[$stateName] = $oldState[$stateName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BlockStateData($newName, $newState, $schema->getVersionId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Tag[] $states
|
* @param Tag[] $states
|
||||||
* @phpstan-param array<string, Tag> $states
|
* @phpstan-param array<string, Tag> $states
|
||||||
|
Loading…
x
Reference in New Issue
Block a user