mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 23:59:53 +00:00
Added support for upgrading states via remap (needed for end rods and all-sided-logs)
This commit is contained in:
parent
166ffe430a
commit
0226f5466c
@ -57,6 +57,12 @@ final class BlockStateUpgradeSchema{
|
|||||||
*/
|
*/
|
||||||
public array $remappedPropertyValues = [];
|
public array $remappedPropertyValues = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var BlockStateUpgradeSchemaBlockRemap[][]
|
||||||
|
* @phpstan-var array<string, list<BlockStateUpgradeSchemaBlockRemap>>
|
||||||
|
*/
|
||||||
|
public array $remappedStates = [];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public int $maxVersionMajor,
|
public int $maxVersionMajor,
|
||||||
public int $maxVersionMinor,
|
public int $maxVersionMinor,
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\data\bedrock\blockstate\upgrade;
|
namespace pocketmine\data\bedrock\blockstate\upgrade;
|
||||||
|
|
||||||
use pocketmine\data\bedrock\blockstate\upgrade\model\BlockStateUpgradeSchemaModel;
|
use pocketmine\data\bedrock\blockstate\upgrade\model\BlockStateUpgradeSchemaModel;
|
||||||
|
use pocketmine\data\bedrock\blockstate\upgrade\model\BlockStateUpgradeSchemaModelBlockRemap;
|
||||||
use pocketmine\data\bedrock\blockstate\upgrade\model\BlockStateUpgradeSchemaModelTag;
|
use pocketmine\data\bedrock\blockstate\upgrade\model\BlockStateUpgradeSchemaModelTag;
|
||||||
use pocketmine\data\bedrock\blockstate\upgrade\model\BlockStateUpgradeSchemaModelValueRemap;
|
use pocketmine\data\bedrock\blockstate\upgrade\model\BlockStateUpgradeSchemaModelValueRemap;
|
||||||
use pocketmine\errorhandler\ErrorToExceptionHandler;
|
use pocketmine\errorhandler\ErrorToExceptionHandler;
|
||||||
@ -33,6 +34,7 @@ use pocketmine\nbt\tag\StringTag;
|
|||||||
use pocketmine\nbt\tag\Tag;
|
use pocketmine\nbt\tag\Tag;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
use Webmozart\PathUtil\Path;
|
use Webmozart\PathUtil\Path;
|
||||||
|
use function array_map;
|
||||||
use function file_get_contents;
|
use function file_get_contents;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function implode;
|
use function implode;
|
||||||
@ -142,6 +144,16 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach(Utils::stringifyKeys($model->remappedStates ?? []) as $oldBlockName => $remaps){
|
||||||
|
foreach($remaps as $remap){
|
||||||
|
$result->remappedStates[$oldBlockName][] = new BlockStateUpgradeSchemaBlockRemap(
|
||||||
|
array_map(fn(BlockStateUpgradeSchemaModelTag $tag) => self::jsonModelToTag($tag), $remap->oldState),
|
||||||
|
$remap->newName,
|
||||||
|
array_map(fn(BlockStateUpgradeSchemaModelTag $tag) => self::jsonModelToTag($tag), $remap->newState),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,6 +184,16 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach(Utils::stringifyKeys($schema->remappedStates) as $oldBlockName => $remaps){
|
||||||
|
foreach($remaps as $remap){
|
||||||
|
$result->remappedStates[$oldBlockName][] = new BlockStateUpgradeSchemaModelBlockRemap(
|
||||||
|
array_map(fn(Tag $tag) => self::tagToJsonModel($tag), $remap->oldState),
|
||||||
|
$remap->newName,
|
||||||
|
array_map(fn(Tag $tag) => self::tagToJsonModel($tag), $remap->newState),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,6 @@ final class BlockStateUpgrader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function upgrade(BlockStateData $blockStateData) : BlockStateData{
|
public function upgrade(BlockStateData $blockStateData) : BlockStateData{
|
||||||
$oldName = $blockStateData->getName();
|
|
||||||
|
|
||||||
$version = $blockStateData->getVersion();
|
$version = $blockStateData->getVersion();
|
||||||
foreach($this->upgradeSchemas as $resultVersion => $schemas){
|
foreach($this->upgradeSchemas as $resultVersion => $schemas){
|
||||||
if($version > $resultVersion){
|
if($version > $resultVersion){
|
||||||
@ -64,6 +62,15 @@ final class BlockStateUpgrader{
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach($schemas as $schema){
|
foreach($schemas as $schema){
|
||||||
|
$oldName = $blockStateData->getName();
|
||||||
|
if(isset($schema->remappedStates[$oldName])){
|
||||||
|
foreach($schema->remappedStates[$oldName] as $remap){
|
||||||
|
if($blockStateData->getStates()->equals($remap->oldState)){
|
||||||
|
$blockStateData = new BlockStateData($remap->newName, clone $remap->newState, $resultVersion);
|
||||||
|
continue 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$newName = $schema->renamedIds[$oldName] ?? null;
|
$newName = $schema->renamedIds[$oldName] ?? null;
|
||||||
|
|
||||||
$stateChanges = 0;
|
$stateChanges = 0;
|
||||||
|
@ -69,6 +69,12 @@ final class BlockStateUpgradeSchemaModel implements \JsonSerializable{
|
|||||||
*/
|
*/
|
||||||
public array $remappedPropertyValues;
|
public array $remappedPropertyValues;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var BlockStateUpgradeSchemaModelBlockRemap[][]
|
||||||
|
* @phpstan-var array<string, list<BlockStateUpgradeSchemaModelBlockRemap>>
|
||||||
|
*/
|
||||||
|
public array $remappedStates;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user