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
13
declare(strict_types=1);
14
15
namespace
pocketmine\network\mcpe\protocol;
16
17
use pmmp\encoding\ByteBufferReader;
18
use pmmp\encoding\ByteBufferWriter;
19
use pmmp\encoding\VarInt;
20
use
pocketmine\network\mcpe\protocol\serializer\CommonTypes
;
21
use
pocketmine\network\mcpe\protocol\types\inventory\FullContainerName
;
22
use
pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper
;
23
use
function
count;
24
25
class
InventoryContentPacket
extends
DataPacket
implements
ClientboundPacket
{
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
}
pocketmine\network\mcpe\protocol\DataPacket
Definition
DataPacket.php:23
pocketmine\network\mcpe\protocol\InventoryContentPacket
Definition
InventoryContentPacket.php:25
pocketmine\network\mcpe\protocol\InventoryContentPacket\encodePayload
encodePayload(ByteBufferWriter $out)
Definition
InventoryContentPacket.php:57
pocketmine\network\mcpe\protocol\InventoryContentPacket\create
static create(int $windowId, array $items, FullContainerName $containerName, ItemStackWrapper $storage)
Definition
InventoryContentPacket.php:38
pocketmine\network\mcpe\protocol\InventoryContentPacket\handle
handle(PacketHandlerInterface $handler)
Definition
InventoryContentPacket.php:67
pocketmine\network\mcpe\protocol\InventoryContentPacket\decodePayload
decodePayload(ByteBufferReader $in)
Definition
InventoryContentPacket.php:47
pocketmine\network\mcpe\protocol\serializer\CommonTypes
Definition
CommonTypes.php:70
pocketmine\network\mcpe\protocol\types\inventory\FullContainerName
Definition
FullContainerName.php:23
pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper
Definition
ItemStackWrapper.php:17
pocketmine\network\mcpe\protocol\ClientboundPacket
Definition
ClientboundPacket.php:17
pocketmine\network\mcpe\protocol\PacketHandlerInterface
Definition
PacketHandlerInterface.php:20
vendor
pocketmine
bedrock-protocol
src
InventoryContentPacket.php
Generated by
1.12.0