PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
ItemInteractionData.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;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
22use function count;
23
28 public function __construct(
29 private int $requestId,
30 private array $requestChangedSlots,
31 private UseItemTransactionData $transactionData
32 ){}
33
34 public function getRequestId() : int{
35 return $this->requestId;
36 }
37
41 public function getRequestChangedSlots() : array{
42 return $this->requestChangedSlots;
43 }
44
45 public function getTransactionData() : UseItemTransactionData{
46 return $this->transactionData;
47 }
48
49 public static function read(ByteBufferReader $in) : self{
50 $requestId = VarInt::readSignedInt($in);
51 $requestChangedSlots = [];
52 if($requestId !== 0){
53 $len = VarInt::readUnsignedInt($in);
54 for($i = 0; $i < $len; ++$i){
55 $requestChangedSlots[] = InventoryTransactionChangedSlotsHack::read($in);
56 }
57 }
58 $transactionData = new UseItemTransactionData();
59 $transactionData->decode($in);
60 return new ItemInteractionData($requestId, $requestChangedSlots, $transactionData);
61 }
62
63 public function write(ByteBufferWriter $out) : void{
64 VarInt::writeSignedInt($out, $this->requestId);
65 if($this->requestId !== 0){
66 VarInt::writeUnsignedInt($out, count($this->requestChangedSlots));
67 foreach($this->requestChangedSlots as $changedSlot){
68 $changedSlot->write($out);
69 }
70 }
71 $this->transactionData->encode($out);
72 }
73}
__construct(private int $requestId, private array $requestChangedSlots, private UseItemTransactionData $transactionData)