PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
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
20use function count;
21
23 public const NETWORK_ID = ProtocolInfo::INVENTORY_CONTENT_PACKET;
24
25 public int $windowId;
27 public array $items = [];
28 public FullContainerName $containerName;
29 public ItemStackWrapper $storage;
30
35 public static function create(int $windowId, array $items, FullContainerName $containerName, ItemStackWrapper $storage) : self{
36 $result = new self;
37 $result->windowId = $windowId;
38 $result->items = $items;
39 $result->containerName = $containerName;
40 $result->storage = $storage;
41 return $result;
42 }
43
44 protected function decodePayload(PacketSerializer $in) : void{
45 $this->windowId = $in->getUnsignedVarInt();
46 $count = $in->getUnsignedVarInt();
47 for($i = 0; $i < $count; ++$i){
48 $this->items[] = $in->getItemStackWrapper();
49 }
50 $this->containerName = FullContainerName::read($in);
51 $this->storage = $in->getItemStackWrapper();
52 }
53
54 protected function encodePayload(PacketSerializer $out) : void{
55 $out->putUnsignedVarInt($this->windowId);
56 $out->putUnsignedVarInt(count($this->items));
57 foreach($this->items as $item){
58 $out->putItemStackWrapper($item);
59 }
60 $this->containerName->write($out);
61 $out->putItemStackWrapper($this->storage);
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handleInventoryContent($this);
66 }
67}
static create(int $windowId, array $items, FullContainerName $containerName, ItemStackWrapper $storage)