mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 19:02:59 +00:00
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:
@ -27,14 +27,18 @@ use pocketmine\nbt\tag\Tag;
|
||||
|
||||
final class BlockStateUpgradeSchemaBlockRemap{
|
||||
/**
|
||||
* @param Tag[] $oldState
|
||||
* @param Tag[] $newState
|
||||
* @param Tag[] $oldState
|
||||
* @param Tag[] $newState
|
||||
* @param string[] $copiedState
|
||||
*
|
||||
* @phpstan-param array<string, Tag> $oldState
|
||||
* @phpstan-param array<string, Tag> $newState
|
||||
* @phpstan-param list<string> $copiedState
|
||||
*/
|
||||
public function __construct(
|
||||
public array $oldState,
|
||||
public string $newName,
|
||||
public array $newState
|
||||
public array $newState,
|
||||
public array $copiedState
|
||||
){}
|
||||
}
|
||||
|
@ -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])){
|
||||
|
@ -70,16 +70,23 @@ final class BlockStateUpgrader{
|
||||
$oldState = $blockStateData->getStates();
|
||||
if(isset($schema->remappedStates[$oldName])){
|
||||
foreach($schema->remappedStates[$oldName] as $remap){
|
||||
if(count($oldState) !== count($remap->oldState)){
|
||||
if(count($remap->oldState) > count($oldState)){
|
||||
//match criteria has more requirements than we have state properties
|
||||
continue; //try next state
|
||||
}
|
||||
foreach(Utils::stringifyKeys($oldState) as $k => $v){
|
||||
if(!isset($remap->oldState[$k]) || !$remap->oldState[$k]->equals($v)){
|
||||
foreach(Utils::stringifyKeys($remap->oldState) as $k => $v){
|
||||
if(!isset($oldState[$k]) || !$oldState[$k]->equals($v)){
|
||||
continue 2; //try next state
|
||||
}
|
||||
}
|
||||
$newState = $remap->newState;
|
||||
foreach($remap->copiedState as $stateName){
|
||||
if(isset($oldState[$stateName])){
|
||||
$newState[$stateName] = $oldState[$stateName];
|
||||
}
|
||||
}
|
||||
|
||||
$blockStateData = new BlockStateData($remap->newName, $remap->newState, $resultVersion);
|
||||
$blockStateData = new BlockStateData($remap->newName, $newState, $resultVersion);
|
||||
continue 2; //try next schema
|
||||
}
|
||||
}
|
||||
|
@ -43,15 +43,25 @@ final class BlockStateUpgradeSchemaModelBlockRemap{
|
||||
*/
|
||||
public ?array $newState;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
* @phpstan-var list<string>
|
||||
* May not be present in older schemas
|
||||
*/
|
||||
public array $copiedState;
|
||||
|
||||
/**
|
||||
* @param BlockStateUpgradeSchemaModelTag[] $oldState
|
||||
* @param BlockStateUpgradeSchemaModelTag[] $newState
|
||||
* @param string[] $copiedState
|
||||
* @phpstan-param array<string, BlockStateUpgradeSchemaModelTag> $oldState
|
||||
* @phpstan-param array<string, BlockStateUpgradeSchemaModelTag> $newState
|
||||
* @phpstan-param list<string> $copiedState
|
||||
*/
|
||||
public function __construct(array $oldState, string $newName, array $newState){
|
||||
public function __construct(array $oldState, string $newName, array $newState, array $copiedState){
|
||||
$this->oldState = count($oldState) === 0 ? null : $oldState;
|
||||
$this->newName = $newName;
|
||||
$this->newState = count($newState) === 0 ? null : $newState;
|
||||
$this->copiedState = $copiedState;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user