PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
InventoryTransactionChangedSlotsHack.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 pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
21use function count;
22
27 public function __construct(
28 private int $containerId,
29 private array $changedSlotIndexes
30 ){}
31
32 public function getContainerId() : int{ return $this->containerId; }
33
35 public function getChangedSlotIndexes() : array{ return $this->changedSlotIndexes; }
36
37 public static function read(ByteBufferReader $in) : self{
38 $containerId = Byte::readUnsigned($in);
39 $changedSlots = [];
40 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
41 $changedSlots[] = Byte::readUnsigned($in);
42 }
43 return new self($containerId, $changedSlots);
44 }
45
46 public function write(ByteBufferWriter $out) : void{
47 Byte::writeUnsigned($out, $this->containerId);
48 VarInt::writeUnsignedInt($out, count($this->changedSlotIndexes));
49 foreach($this->changedSlotIndexes as $index){
50 Byte::writeUnsigned($out, $index);
51 }
52 }
53}