Added support for compressing blockstate remaps using copiedState

this significantly reduces the size of schemas when state remaps are used (see pmmp/BedrockBlockUpgradeSchema@85b83b360e).

in addition, this will likely offer a substantial performance and memory saving when walls get flattened, which will eventually happen.
This commit is contained in:
Dylan K. Taylor
2023-04-28 20:34:06 +01:00
parent 263e1e9950
commit a1d44de487
5 changed files with 166 additions and 10 deletions

View File

@ -157,6 +157,7 @@ final class BlockStateUpgradeSchemaUtils{
array_map(fn(BlockStateUpgradeSchemaModelTag $tag) => self::jsonModelToTag($tag), $remap->oldState ?? []),
$remap->newName,
array_map(fn(BlockStateUpgradeSchemaModelTag $tag) => self::jsonModelToTag($tag), $remap->newState ?? []),
$remap->copiedState ?? []
);
}
}
@ -277,7 +278,11 @@ final class BlockStateUpgradeSchemaUtils{
array_map(fn(Tag $tag) => self::tagToJsonModel($tag), $remap->oldState),
$remap->newName,
array_map(fn(Tag $tag) => self::tagToJsonModel($tag), $remap->newState),
$remap->copiedState
);
if(count($modelRemap->copiedState) === 0){
unset($modelRemap->copiedState); //avoid polluting the JSON
}
$key = json_encode($modelRemap);
assert(!isset($keyedRemaps[$key]));
if(isset($keyedRemaps[$key])){