PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
InventoryContentPacket.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;
16
19use function count;
20
22 public const NETWORK_ID = ProtocolInfo::INVENTORY_CONTENT_PACKET;
23
24 public int $windowId;
26 public array $items = [];
27
32 public static function create(int $windowId, array $items) : self{
33 $result = new self;
34 $result->windowId = $windowId;
35 $result->items = $items;
36 return $result;
37 }
38
39 protected function decodePayload(PacketSerializer $in) : void{
40 $this->windowId = $in->getUnsignedVarInt();
41 $count = $in->getUnsignedVarInt();
42 for($i = 0; $i < $count; ++$i){
43 $this->items[] = $in->getItemStackWrapper();
44 }
45 }
46
47 protected function encodePayload(PacketSerializer $out) : void{
48 $out->putUnsignedVarInt($this->windowId);
49 $out->putUnsignedVarInt(count($this->items));
50 foreach($this->items as $item){
51 $out->putItemStackWrapper($item);
52 }
53 }
54
55 public function handle(PacketHandlerInterface $handler) : bool{
56 return $handler->handleInventoryContent($this);
57 }
58}