PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
ItemStackResponseSlotInfo.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\stackresponse;
16
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
22
24 public function __construct(
25 private int $slot,
26 private int $hotbarSlot,
27 private int $count,
28 private int $itemStackId,
29 private string $customName,
30 private string $filteredCustomName,
31 private int $durabilityCorrection
32 ){}
33
34 public function getSlot() : int{ return $this->slot; }
35
36 public function getHotbarSlot() : int{ return $this->hotbarSlot; }
37
38 public function getCount() : int{ return $this->count; }
39
40 public function getItemStackId() : int{ return $this->itemStackId; }
41
42 public function getCustomName() : string{ return $this->customName; }
43
44 public function getFilteredCustomName() : string{ return $this->filteredCustomName; }
45
46 public function getDurabilityCorrection() : int{ return $this->durabilityCorrection; }
47
48 public static function read(ByteBufferReader $in) : self{
49 $slot = Byte::readUnsigned($in);
50 $hotbarSlot = Byte::readUnsigned($in);
51 $count = Byte::readUnsigned($in);
52 $itemStackId = CommonTypes::readServerItemStackId($in);
53 $customName = CommonTypes::getString($in);
54 $filteredCustomName = CommonTypes::getString($in);
55 $durabilityCorrection = VarInt::readSignedInt($in);
56 return new self($slot, $hotbarSlot, $count, $itemStackId, $customName, $filteredCustomName, $durabilityCorrection);
57 }
58
59 public function write(ByteBufferWriter $out) : void{
60 Byte::writeUnsigned($out, $this->slot);
61 Byte::writeUnsigned($out, $this->hotbarSlot);
62 Byte::writeUnsigned($out, $this->count);
63 CommonTypes::writeServerItemStackId($out, $this->itemStackId);
64 CommonTypes::putString($out, $this->customName);
65 CommonTypes::putString($out, $this->filteredCustomName);
66 VarInt::writeSignedInt($out, $this->durabilityCorrection);
67 }
68}