PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
ItemStack.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol\types\inventory;
16
17use function base64_encode;
18
19final class ItemStack implements \JsonSerializable{
24 public function __construct(
25 private int $id,
26 private int $meta,
27 private int $count,
28 private int $blockRuntimeId,
29 private string $rawExtraData,
30 ){}
31
32 public static function null() : self{
33 return new self(0, 0, 0, 0, "");
34 }
35
36 public function isNull() : bool{
37 return $this->id === 0;
38 }
39
40 public function getId() : int{
41 return $this->id;
42 }
43
44 public function getMeta() : int{
45 return $this->meta;
46 }
47
48 public function getCount() : int{
49 return $this->count;
50 }
51
52 public function getBlockRuntimeId() : int{ return $this->blockRuntimeId; }
53
61 public function getRawExtraData() : string{ return $this->rawExtraData; }
62
63 public function equals(ItemStack $itemStack) : bool{
64 return $this->equalsWithoutCount($itemStack) && $this->count === $itemStack->count;
65 }
66
67 public function equalsWithoutCount(ItemStack $itemStack) : bool{
68 return
69 $this->id === $itemStack->id &&
70 $this->meta === $itemStack->meta &&
71 $this->blockRuntimeId === $itemStack->blockRuntimeId &&
72 $this->rawExtraData === $itemStack->rawExtraData;
73 }
74
76 public function jsonSerialize() : array{
77 return [
78 "id" => $this->id,
79 "meta" => $this->meta,
80 "count" => $this->count,
81 "blockRuntimeId" => $this->blockRuntimeId,
82 "rawExtraData" => base64_encode($this->rawExtraData),
83 ];
84 }
85}
__construct(private int $id, private int $meta, private int $count, private int $blockRuntimeId, private string $rawExtraData,)
Definition ItemStack.php:24