mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-21 02:44:03 +00:00
Allow remapped oldState and newState to accept null, to make it easier for third-party tools to use the schemas
since PHP emits empty JSON objects as arrays, this makes it pretty annoying to work with the schemas in other languages. However, nullability is something most languages understand pretty easily. This should continue to support old schemas.
This commit is contained in:
parent
341a9b78b5
commit
0818388bd5
@ -150,9 +150,9 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
foreach(Utils::stringifyKeys($model->remappedStates ?? []) as $oldBlockName => $remaps){
|
foreach(Utils::stringifyKeys($model->remappedStates ?? []) as $oldBlockName => $remaps){
|
||||||
foreach($remaps as $remap){
|
foreach($remaps as $remap){
|
||||||
$result->remappedStates[$oldBlockName][] = new BlockStateUpgradeSchemaBlockRemap(
|
$result->remappedStates[$oldBlockName][] = new BlockStateUpgradeSchemaBlockRemap(
|
||||||
array_map(fn(BlockStateUpgradeSchemaModelTag $tag) => self::jsonModelToTag($tag), $remap->oldState),
|
array_map(fn(BlockStateUpgradeSchemaModelTag $tag) => self::jsonModelToTag($tag), $remap->oldState ?? []),
|
||||||
$remap->newName,
|
$remap->newName,
|
||||||
array_map(fn(BlockStateUpgradeSchemaModelTag $tag) => self::jsonModelToTag($tag), $remap->newState),
|
array_map(fn(BlockStateUpgradeSchemaModelTag $tag) => self::jsonModelToTag($tag), $remap->newState ?? []),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,24 +23,25 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\data\bedrock\block\upgrade\model;
|
namespace pocketmine\data\bedrock\block\upgrade\model;
|
||||||
|
|
||||||
|
use function count;
|
||||||
|
|
||||||
final class BlockStateUpgradeSchemaModelBlockRemap{
|
final class BlockStateUpgradeSchemaModelBlockRemap{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var BlockStateUpgradeSchemaModelTag[]
|
* @var BlockStateUpgradeSchemaModelTag[]|null
|
||||||
* @phpstan-var array<string, BlockStateUpgradeSchemaModelTag>
|
* @phpstan-var array<string, BlockStateUpgradeSchemaModelTag>|null
|
||||||
* @required
|
* @required
|
||||||
*/
|
*/
|
||||||
public array $oldState;
|
public ?array $oldState;
|
||||||
|
|
||||||
/** @required */
|
/** @required */
|
||||||
public string $newName;
|
public string $newName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var BlockStateUpgradeSchemaModelTag[]
|
* @var BlockStateUpgradeSchemaModelTag[]|null
|
||||||
* @phpstan-var array<string, BlockStateUpgradeSchemaModelTag>
|
* @phpstan-var array<string, BlockStateUpgradeSchemaModelTag>|null
|
||||||
* @required
|
|
||||||
*/
|
*/
|
||||||
public array $newState;
|
public ?array $newState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param BlockStateUpgradeSchemaModelTag[] $oldState
|
* @param BlockStateUpgradeSchemaModelTag[] $oldState
|
||||||
@ -49,8 +50,8 @@ final class BlockStateUpgradeSchemaModelBlockRemap{
|
|||||||
* @phpstan-param array<string, BlockStateUpgradeSchemaModelTag> $newState
|
* @phpstan-param array<string, BlockStateUpgradeSchemaModelTag> $newState
|
||||||
*/
|
*/
|
||||||
public function __construct(array $oldState, string $newName, array $newState){
|
public function __construct(array $oldState, string $newName, array $newState){
|
||||||
$this->oldState = $oldState;
|
$this->oldState = count($oldState) === 0 ? null : $oldState;
|
||||||
$this->newName = $newName;
|
$this->newName = $newName;
|
||||||
$this->newState = $newState;
|
$this->newState = count($newState) === 0 ? null : $newState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user