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
13
declare(strict_types=1);
14
15
namespace
pocketmine\network\mcpe\protocol;
16
17
use
pocketmine\network\mcpe\protocol\serializer\PacketSerializer
;
18
use
pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper
;
19
use
function
count;
20
21
class
InventoryContentPacket
extends
DataPacket
implements
ClientboundPacket
{
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
}
pocketmine\network\mcpe\protocol\DataPacket
Definition:
DataPacket.php:21
pocketmine\network\mcpe\protocol\InventoryContentPacket
Definition:
InventoryContentPacket.php:21
pocketmine\network\mcpe\protocol\InventoryContentPacket\create
static create(int $windowId, array $items)
Definition:
InventoryContentPacket.php:32
pocketmine\network\mcpe\protocol\InventoryContentPacket\handle
handle(PacketHandlerInterface $handler)
Definition:
InventoryContentPacket.php:55
pocketmine\network\mcpe\protocol\InventoryContentPacket\decodePayload
decodePayload(PacketSerializer $in)
Definition:
InventoryContentPacket.php:39
pocketmine\network\mcpe\protocol\InventoryContentPacket\encodePayload
encodePayload(PacketSerializer $out)
Definition:
InventoryContentPacket.php:47
pocketmine\network\mcpe\protocol\serializer\PacketSerializer
Definition:
bedrock-protocol/src/serializer/PacketSerializer.php:67
pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper
Definition:
ItemStackWrapper.php:17
pocketmine\utils\BinaryStream\getUnsignedVarInt
getUnsignedVarInt()
Definition:
BinaryStream.php:307
pocketmine\utils\BinaryStream\putUnsignedVarInt
putUnsignedVarInt(int $v)
Definition:
BinaryStream.php:314
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.9.3