tools/generate-bedrock-data-from-packets: generate less noise for items

if we have only a name (the majority case), we can just return the name directly instead of an object.
this massively reduces the amount of noise in the files as seen in pmmp/BedrockData@f814036229
This commit is contained in:
Dylan K. Taylor
2025-08-28 21:15:09 +01:00
parent de234d1f38
commit dd9030f1f5
4 changed files with 34 additions and 8 deletions

View File

@ -162,7 +162,7 @@ final class CraftingManagerFromDataHelper{
}
$mapper = new \JsonMapper();
$mapper->bStrictObjectTypeChecking = true;
$mapper->bStrictObjectTypeChecking = false; //to allow hydrating ItemStackData - since this is only used for offline data it's safe
$mapper->bExceptionOnUndefinedProperty = true;
$mapper->bExceptionOnMissingData = true;

View File

@ -23,7 +23,9 @@ declare(strict_types=1);
namespace pocketmine\crafting\json;
final class ItemStackData{
use function count;
final class ItemStackData implements \JsonSerializable{
/** @required */
public string $name;
@ -40,4 +42,15 @@ final class ItemStackData{
public function __construct(string $name){
$this->name = $name;
}
/**
* @return mixed[]|string
*/
public function jsonSerialize() : array|string{
$result = (array) $this;
if(count($result) === 1 && isset($result["name"])){
return $this->name;
}
return $result;
}
}