mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-08-29 22:45:00 +00:00
BlockStateUpgradeSchemaUtils: Use independent suffixes for each property mapping list
This commit is contained in:
parent
b3e94ef1dc
commit
29694c19af
@ -34,6 +34,7 @@ use pocketmine\nbt\tag\Tag;
|
|||||||
use pocketmine\utils\Filesystem;
|
use pocketmine\utils\Filesystem;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
use Symfony\Component\Filesystem\Path;
|
use Symfony\Component\Filesystem\Path;
|
||||||
|
use function array_key_last;
|
||||||
use function array_map;
|
use function array_map;
|
||||||
use function array_values;
|
use function array_values;
|
||||||
use function assert;
|
use function assert;
|
||||||
@ -170,9 +171,7 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$dedupMapping = [];
|
$dedupMapping = [];
|
||||||
$dedupTable = [];
|
|
||||||
$dedupTableMap = [];
|
$dedupTableMap = [];
|
||||||
$counter = 0;
|
|
||||||
|
|
||||||
$orderedRemappedValues = $schema->remappedPropertyValues;
|
$orderedRemappedValues = $schema->remappedPropertyValues;
|
||||||
ksort($orderedRemappedValues);
|
ksort($orderedRemappedValues);
|
||||||
@ -185,7 +184,8 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
}
|
}
|
||||||
ksort($remappedValuesMap);
|
ksort($remappedValuesMap);
|
||||||
|
|
||||||
foreach(Utils::stringifyKeys($dedupTableMap) as $dedupName => $dedupValuesMap){
|
if(isset($dedupTableMap[$propertyName])){
|
||||||
|
foreach($dedupTableMap[$propertyName] as $k => $dedupValuesMap){
|
||||||
if(count($remappedValuesMap) !== count($dedupValuesMap)){
|
if(count($remappedValuesMap) !== count($dedupValuesMap)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -201,36 +201,45 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//we found a match
|
//we found a match
|
||||||
$dedupMapping[$blockName][$propertyName] = $dedupName;
|
$dedupMapping[$blockName][$propertyName] = $k;
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//no match, add the values to the table
|
//no match, add the values to the table
|
||||||
$newDedupName = $propertyName . "_" . str_pad(strval($counter++), 2, "0", STR_PAD_LEFT);
|
$dedupTableMap[$propertyName][] = $remappedValuesMap;
|
||||||
$dedupTableMap[$newDedupName] = $remappedValuesMap;
|
$dedupMapping[$blockName][$propertyName] = array_key_last($dedupTableMap[$propertyName]);
|
||||||
$dedupTable[$newDedupName] = array_values($remappedValuesMap);
|
|
||||||
$dedupMapping[$blockName][$propertyName] = $newDedupName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$modelTable = [];
|
$modelTable = [];
|
||||||
foreach(Utils::stringifyKeys($dedupTable) as $dedupName => $valuePairs){
|
foreach(Utils::stringifyKeys($dedupTableMap) as $propertyName => $mappingSet){
|
||||||
foreach($valuePairs as $k => $pair){
|
foreach($mappingSet as $setId => $valuePairs){
|
||||||
$modelTable[$dedupName][$k] = new BlockStateUpgradeSchemaModelValueRemap(
|
$newDedupName = $propertyName . "_" . str_pad(strval($setId), 2, "0", STR_PAD_LEFT);
|
||||||
|
foreach($valuePairs as $pair){
|
||||||
|
$modelTable[$newDedupName][] = new BlockStateUpgradeSchemaModelValueRemap(
|
||||||
BlockStateUpgradeSchemaUtils::tagToJsonModel($pair->old),
|
BlockStateUpgradeSchemaUtils::tagToJsonModel($pair->old),
|
||||||
BlockStateUpgradeSchemaUtils::tagToJsonModel($pair->new),
|
BlockStateUpgradeSchemaUtils::tagToJsonModel($pair->new),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
$modelDedupMapping = [];
|
||||||
|
foreach(Utils::stringifyKeys($dedupMapping) as $blockName => $properties){
|
||||||
|
foreach(Utils::stringifyKeys($properties) as $propertyName => $dedupTableIndex){
|
||||||
|
$modelDedupMapping[$blockName][$propertyName] = $propertyName . "_" . str_pad(strval($dedupTableIndex), 2, "0", STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ksort($modelTable);
|
ksort($modelTable);
|
||||||
ksort($dedupMapping);
|
ksort($modelDedupMapping);
|
||||||
foreach(Utils::stringifyKeys($dedupMapping) as $blockName => $properties){
|
foreach(Utils::stringifyKeys($dedupMapping) as $blockName => $properties){
|
||||||
ksort($properties);
|
ksort($properties);
|
||||||
$dedupMapping[$blockName] = $properties;
|
$dedupMapping[$blockName] = $properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
$model->remappedPropertyValuesIndex = $modelTable;
|
$model->remappedPropertyValuesIndex = $modelTable;
|
||||||
$model->remappedPropertyValues = $dedupMapping;
|
$model->remappedPropertyValues = $modelDedupMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function toJsonModel(BlockStateUpgradeSchema $schema) : BlockStateUpgradeSchemaModel{
|
public static function toJsonModel(BlockStateUpgradeSchema $schema) : BlockStateUpgradeSchemaModel{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user