PocketMine-MP 5.18.1 git-9381fc4172e5dce4cada1cb356050c8a2ab57b94
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
20use function count;
21
26 public function __construct(
27 private int $requestId,
28 private array $requestChangedSlots,
29 private UseItemTransactionData $transactionData
30 ){}
31
32 public function getRequestId() : int{
33 return $this->requestId;
34 }
35
39 public function getRequestChangedSlots() : array{
40 return $this->requestChangedSlots;
41 }
42
43 public function getTransactionData() : UseItemTransactionData{
44 return $this->transactionData;
45 }
46
47 public static function read(PacketSerializer $in) : self{
48 $requestId = $in->getVarInt();
49 $requestChangedSlots = [];
50 if($requestId !== 0){
51 $len = $in->getUnsignedVarInt();
52 for($i = 0; $i < $len; ++$i){
53 $requestChangedSlots[] = InventoryTransactionChangedSlotsHack::read($in);
54 }
55 }
56 $transactionData = new UseItemTransactionData();
57 $transactionData->decode($in);
58 return new ItemInteractionData($requestId, $requestChangedSlots, $transactionData);
59 }
60
61 public function write(PacketSerializer $out) : void{
62 $out->putVarInt($this->requestId);
63 if($this->requestId !== 0){
64 $out->putUnsignedVarInt(count($this->requestChangedSlots));
65 foreach($this->requestChangedSlots as $changedSlot){
66 $changedSlot->write($out);
67 }
68 }
69 $this->transactionData->encode($out);
70 }
71}
__construct(private int $requestId, private array $requestChangedSlots, private UseItemTransactionData $transactionData)