PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
23use function count;
24
26 public const NETWORK_ID = ProtocolInfo::INVENTORY_CONTENT_PACKET;
27
28 public int $windowId;
30 public array $items = [];
31 public FullContainerName $containerName;
32 public ItemStackWrapper $storage;
33
38 public static function create(int $windowId, array $items, FullContainerName $containerName, ItemStackWrapper $storage) : self{
39 $result = new self;
40 $result->windowId = $windowId;
41 $result->items = $items;
42 $result->containerName = $containerName;
43 $result->storage = $storage;
44 return $result;
45 }
46
47 protected function decodePayload(ByteBufferReader $in) : void{
48 $this->windowId = VarInt::readUnsignedInt($in);
49 $count = VarInt::readUnsignedInt($in);
50 for($i = 0; $i < $count; ++$i){
51 $this->items[] = CommonTypes::getItemStackWrapper($in);
52 }
53 $this->containerName = FullContainerName::read($in);
54 $this->storage = CommonTypes::getItemStackWrapper($in);
55 }
56
57 protected function encodePayload(ByteBufferWriter $out) : void{
58 VarInt::writeUnsignedInt($out, $this->windowId);
59 VarInt::writeUnsignedInt($out, count($this->items));
60 foreach($this->items as $item){
61 CommonTypes::putItemStackWrapper($out, $item);
62 }
63 $this->containerName->write($out);
64 CommonTypes::putItemStackWrapper($out, $this->storage);
65 }
66
67 public function handle(PacketHandlerInterface $handler) : bool{
68 return $handler->handleInventoryContent($this);
69 }
70}
static create(int $windowId, array $items, FullContainerName $containerName, ItemStackWrapper $storage)