mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 20:58:34 +00:00
ItemStack: added jsonSerialize
This commit is contained in:
parent
1d02829d6f
commit
2bcb398db9
@ -24,9 +24,13 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\network\mcpe\protocol\types\inventory;
|
namespace pocketmine\network\mcpe\protocol\types\inventory;
|
||||||
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
|
use pocketmine\nbt\TreeRoot;
|
||||||
|
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
|
||||||
use pocketmine\network\mcpe\protocol\types\FixedItemIds;
|
use pocketmine\network\mcpe\protocol\types\FixedItemIds;
|
||||||
|
use function base64_encode;
|
||||||
|
use function count;
|
||||||
|
|
||||||
final class ItemStack{
|
final class ItemStack implements \JsonSerializable{
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $id;
|
private $id;
|
||||||
@ -110,4 +114,25 @@ final class ItemStack{
|
|||||||
($this->nbt !== null && $itemStack->nbt !== null && $this->nbt->equals($itemStack->nbt))
|
($this->nbt !== null && $itemStack->nbt !== null && $this->nbt->equals($itemStack->nbt))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize() : array{
|
||||||
|
$result = [
|
||||||
|
"id" => $this->id,
|
||||||
|
"meta" => $this->meta,
|
||||||
|
"count" => $this->count,
|
||||||
|
];
|
||||||
|
if(count($this->canPlaceOn) > 0){
|
||||||
|
$result["canPlaceOn"] = $this->canPlaceOn;
|
||||||
|
}
|
||||||
|
if(count($this->canDestroy) > 0){
|
||||||
|
$result["canDestroy"] = $this->canDestroy;
|
||||||
|
}
|
||||||
|
if($this->shieldBlockingTick !== null){
|
||||||
|
$result["shieldBlockingTick"] = $this->shieldBlockingTick;
|
||||||
|
}
|
||||||
|
if($this->nbt !== null){
|
||||||
|
$result["nbt"] = base64_encode((new NetworkNbtSerializer())->write(new TreeRoot($this->nbt)));
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user