PocketMine-MP
5.21.2 git-09bf203267aca9b83a09640e17bfac0fc7b58ff8
Loading...
Searching...
No Matches
ItemComponentPacket.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\CacheableNbt
;
19
use
pocketmine\network\mcpe\protocol\types\ItemComponentPacketEntry
;
20
use
function
count;
21
22
class
ItemComponentPacket
extends
DataPacket
implements
ClientboundPacket
{
23
public
const
NETWORK_ID = ProtocolInfo::ITEM_COMPONENT_PACKET;
24
29
private
array $entries;
30
36
public
static
function
create
(array $entries) : self{
37
$result = new self;
38
$result->entries = $entries;
39
return
$result;
40
}
41
46
public
function
getEntries
() : array{ return $this->entries; }
47
48
protected
function
decodePayload
(
PacketSerializer
$in) : void{
49
$this->entries = [];
50
for
($i = 0, $len = $in->
getUnsignedVarInt
(); $i < $len; ++$i){
51
$name = $in->
getString
();
52
$nbt = $in->getNbtCompoundRoot();
53
$this->entries[] =
new
ItemComponentPacketEntry
($name,
new
CacheableNbt
($nbt));
54
}
55
}
56
57
protected
function
encodePayload
(
PacketSerializer
$out) : void{
58
$out->putUnsignedVarInt(count($this->entries));
59
foreach
($this->entries as $entry){
60
$out->putString($entry->getName());
61
$out->put($entry->getComponentNbt()->getEncodedNbt());
62
}
63
}
64
65
public
function
handle
(
PacketHandlerInterface
$handler) : bool{
66
return $handler->handleItemComponent($this);
67
}
68
}
pocketmine\network\mcpe\protocol\DataPacket
Definition
DataPacket.php:21
pocketmine\network\mcpe\protocol\ItemComponentPacket
Definition
ItemComponentPacket.php:22
pocketmine\network\mcpe\protocol\ItemComponentPacket\create
static create(array $entries)
Definition
ItemComponentPacket.php:36
pocketmine\network\mcpe\protocol\ItemComponentPacket\encodePayload
encodePayload(PacketSerializer $out)
Definition
ItemComponentPacket.php:57
pocketmine\network\mcpe\protocol\ItemComponentPacket\decodePayload
decodePayload(PacketSerializer $in)
Definition
ItemComponentPacket.php:48
pocketmine\network\mcpe\protocol\ItemComponentPacket\handle
handle(PacketHandlerInterface $handler)
Definition
ItemComponentPacket.php:65
pocketmine\network\mcpe\protocol\ItemComponentPacket\getEntries
getEntries()
Definition
ItemComponentPacket.php:46
pocketmine\network\mcpe\protocol\serializer\PacketSerializer
Definition
bedrock-protocol/src/serializer/PacketSerializer.php:66
pocketmine\network\mcpe\protocol\serializer\PacketSerializer\getString
getString()
Definition
bedrock-protocol/src/serializer/PacketSerializer.php:83
pocketmine\network\mcpe\protocol\types\CacheableNbt
Definition
CacheableNbt.php:24
pocketmine\network\mcpe\protocol\types\ItemComponentPacketEntry
Definition
ItemComponentPacketEntry.php:17
pocketmine\utils\BinaryStream\getUnsignedVarInt
getUnsignedVarInt()
Definition
BinaryStream.php:307
pocketmine\network\mcpe\protocol\ClientboundPacket
Definition
ClientboundPacket.php:17
pocketmine\network\mcpe\protocol\PacketHandlerInterface
Definition
PacketHandlerInterface.php:20
vendor
pocketmine
bedrock-protocol
src
ItemComponentPacket.php
Generated by
1.12.0