PocketMine-MP
5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
SetHudPacket.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\hud\HudElement;
19
use pocketmine\network\mcpe\protocol\types\hud\HudVisibility;
20
use
function
count;
21
22
class
SetHudPacket
extends
DataPacket
implements
ClientboundPacket
{
23
public
const
NETWORK_ID = ProtocolInfo::SET_HUD_PACKET;
24
26
private
array $hudElements = [];
27
private
HudVisibility $visibility;
28
33
public
static
function
create
(array $hudElements, HudVisibility $visibility) : self{
34
$result = new self;
35
$result->hudElements = $hudElements;
36
$result->visibility = $visibility;
37
return
$result;
38
}
39
41
public
function
getHudElements
() : array{ return $this->hudElements; }
42
43
public
function
getVisibility() : HudVisibility{ return $this->visibility; }
44
45
protected
function
decodePayload
(
PacketSerializer
$in) : void{
46
$this->hudElements = [];
47
for
($i = 0, $count = $in->
getUnsignedVarInt
(); $i < $count; ++$i){
48
$this->hudElements[] = HudElement::fromPacket($in->
getByte
());
49
}
50
$this->visibility = HudVisibility::fromPacket($in->
getByte
());
51
}
52
53
protected
function
encodePayload
(
PacketSerializer
$out) : void{
54
$out->putUnsignedVarInt(count($this->hudElements));
55
foreach
($this->hudElements as $element){
56
$out->putByte($element->value);
57
}
58
$out->putByte($this->visibility->value);
59
}
60
61
public
function
handle
(
PacketHandlerInterface
$handler) : bool{
62
return $handler->handleSetHud($this);
63
}
64
}
pocketmine\network\mcpe\protocol\DataPacket
Definition
DataPacket.php:21
pocketmine\network\mcpe\protocol\SetHudPacket
Definition
SetHudPacket.php:22
pocketmine\network\mcpe\protocol\SetHudPacket\decodePayload
decodePayload(PacketSerializer $in)
Definition
SetHudPacket.php:45
pocketmine\network\mcpe\protocol\SetHudPacket\create
static create(array $hudElements, HudVisibility $visibility)
Definition
SetHudPacket.php:33
pocketmine\network\mcpe\protocol\SetHudPacket\encodePayload
encodePayload(PacketSerializer $out)
Definition
SetHudPacket.php:53
pocketmine\network\mcpe\protocol\SetHudPacket\getHudElements
getHudElements()
Definition
SetHudPacket.php:41
pocketmine\network\mcpe\protocol\SetHudPacket\handle
handle(PacketHandlerInterface $handler)
Definition
SetHudPacket.php:61
pocketmine\network\mcpe\protocol\serializer\PacketSerializer
Definition
bedrock-protocol/src/serializer/PacketSerializer.php:66
pocketmine\utils\BinaryStream\getByte
getByte()
Definition
BinaryStream.php:117
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
SetHudPacket.php
Generated by
1.12.0