mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-25 04:44:03 +00:00
Item: use base64 instead of hex for json encoding NBT
This commit is contained in:
parent
b5da6b1591
commit
3def3cd502
@ -876,7 +876,7 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($this->hasCompoundTag()){
|
if($this->hasCompoundTag()){
|
||||||
$data["nbt_hex"] = bin2hex($this->getCompoundTag());
|
$data["nbt_b64"] = base64_encode($this->getCompoundTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
@ -889,11 +889,21 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
* @return Item
|
* @return Item
|
||||||
*/
|
*/
|
||||||
final public static function jsonDeserialize(array $data) : Item{
|
final public static function jsonDeserialize(array $data) : Item{
|
||||||
|
$nbt = "";
|
||||||
|
|
||||||
|
//Backwards compatibility
|
||||||
|
if(isset($data["nbt"])){
|
||||||
|
$nbt = $data["nbt"];
|
||||||
|
}elseif(isset($data["nbt_hex"])){
|
||||||
|
$nbt = hex2bin($data["nbt_hex"]);
|
||||||
|
}elseif(isset($data["nbt_b64"])){
|
||||||
|
$nbt = base64_decode($data["nbt_b64"], true);
|
||||||
|
}
|
||||||
return ItemFactory::get(
|
return ItemFactory::get(
|
||||||
(int) $data["id"],
|
(int) $data["id"],
|
||||||
(int) ($data["damage"] ?? 0),
|
(int) ($data["damage"] ?? 0),
|
||||||
(int) ($data["count"] ?? 1),
|
(int) ($data["count"] ?? 1),
|
||||||
(string) ($data["nbt"] ?? (isset($data["nbt_hex"]) ? hex2bin($data["nbt_hex"]) : "")) //`nbt` key might contain old raw data
|
(string) $nbt
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user