PocketMine-MP
5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
CreativeContentPacket.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\types\inventory\CreativeGroupEntry
;
21
use
pocketmine\network\mcpe\protocol\types\inventory\CreativeItemEntry
;
22
use
function
count;
23
24
class
CreativeContentPacket
extends
DataPacket
implements
ClientboundPacket
{
25
public
const
NETWORK_ID = ProtocolInfo::CREATIVE_CONTENT_PACKET;
26
27
public
const
CATEGORY_CONSTRUCTION = 1;
28
public
const
CATEGORY_NATURE = 2;
29
public
const
CATEGORY_EQUIPMENT = 3;
30
public
const
CATEGORY_ITEMS = 4;
31
33
private
array $groups;
35
private
array $items;
36
42
public
static
function
create
(array $groups, array $items) : self{
43
$result = new self;
44
$result->groups = $groups;
45
$result->items = $items;
46
return
$result;
47
}
48
50
public
function
getGroups
() : array{ return $this->groups; }
51
53
public
function
getItems
() : array{ return $this->items; }
54
55
protected
function
decodePayload
(ByteBufferReader $in) : void{
56
$this->groups = [];
57
for
($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
58
$this->groups[] = CreativeGroupEntry::read($in);
59
}
60
61
$this->items = [];
62
for
($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
63
$this->items[] = CreativeItemEntry::read($in);
64
}
65
}
66
67
protected
function
encodePayload
(ByteBufferWriter $out) : void{
68
VarInt::writeUnsignedInt($out, count($this->groups));
69
foreach
($this->groups as $entry){
70
$entry->write($out);
71
}
72
73
VarInt::writeUnsignedInt($out, count($this->items));
74
foreach
($this->items as $entry){
75
$entry->write($out);
76
}
77
}
78
79
public
function
handle
(
PacketHandlerInterface
$handler) : bool{
80
return $handler->handleCreativeContent($this);
81
}
82
}
pocketmine\network\mcpe\protocol\CreativeContentPacket
Definition
CreativeContentPacket.php:24
pocketmine\network\mcpe\protocol\CreativeContentPacket\encodePayload
encodePayload(ByteBufferWriter $out)
Definition
CreativeContentPacket.php:67
pocketmine\network\mcpe\protocol\CreativeContentPacket\handle
handle(PacketHandlerInterface $handler)
Definition
CreativeContentPacket.php:79
pocketmine\network\mcpe\protocol\CreativeContentPacket\create
static create(array $groups, array $items)
Definition
CreativeContentPacket.php:42
pocketmine\network\mcpe\protocol\CreativeContentPacket\getGroups
getGroups()
Definition
CreativeContentPacket.php:50
pocketmine\network\mcpe\protocol\CreativeContentPacket\decodePayload
decodePayload(ByteBufferReader $in)
Definition
CreativeContentPacket.php:55
pocketmine\network\mcpe\protocol\CreativeContentPacket\getItems
getItems()
Definition
CreativeContentPacket.php:53
pocketmine\network\mcpe\protocol\DataPacket
Definition
DataPacket.php:23
pocketmine\network\mcpe\protocol\types\inventory\CreativeGroupEntry
Definition
CreativeGroupEntry.php:22
pocketmine\network\mcpe\protocol\types\inventory\CreativeItemEntry
Definition
CreativeItemEntry.php:22
pocketmine\network\mcpe\protocol\ClientboundPacket
Definition
ClientboundPacket.php:17
pocketmine\network\mcpe\protocol\PacketHandlerInterface
Definition
PacketHandlerInterface.php:20
vendor
pocketmine
bedrock-protocol
src
CreativeContentPacket.php
Generated by
1.12.0