PocketMine-MP
5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
UnlockedRecipesPacket.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\LE;
20
use pmmp\encoding\VarInt;
21
use
pocketmine\network\mcpe\protocol\serializer\CommonTypes
;
22
use
function
count;
23
24
class
UnlockedRecipesPacket
extends
DataPacket
implements
ClientboundPacket
{
25
public
const
NETWORK_ID = ProtocolInfo::UNLOCKED_RECIPES_PACKET;
26
27
public
const
TYPE_EMPTY = 0;
28
public
const
TYPE_INITIALLY_UNLOCKED = 1;
29
public
const
TYPE_NEWLY_UNLOCKED = 2;
30
public
const
TYPE_REMOVE = 3;
31
public
const
TYPE_REMOVE_ALL = 4;
32
33
private
int
$type;
35
private
array $recipes;
36
41
public
static
function
create
(
int
$type, array $recipes) : self{
42
$result = new self;
43
$result->type = $type;
44
$result->recipes = $recipes;
45
return
$result;
46
}
47
48
public
function
getType() : int{ return $this->type; }
49
53
public
function
getRecipes
() : array{ return $this->recipes; }
54
55
protected
function
decodePayload
(ByteBufferReader $in) : void{
56
$this->type = LE::readUnsignedInt($in);
57
$this->recipes = [];
58
for
($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
59
$this->recipes[] = CommonTypes::getString($in);
60
}
61
}
62
63
protected
function
encodePayload
(ByteBufferWriter $out) : void{
64
LE::writeUnsignedInt($out, $this->type);
65
VarInt::writeUnsignedInt($out, count($this->recipes));
66
foreach
($this->recipes as $recipe){
67
CommonTypes::putString($out, $recipe);
68
}
69
}
70
71
public
function
handle
(
PacketHandlerInterface
$handler) : bool{
72
return $handler->handleUnlockedRecipes($this);
73
}
74
}
pocketmine\network\mcpe\protocol\DataPacket
Definition
DataPacket.php:23
pocketmine\network\mcpe\protocol\UnlockedRecipesPacket
Definition
UnlockedRecipesPacket.php:24
pocketmine\network\mcpe\protocol\UnlockedRecipesPacket\decodePayload
decodePayload(ByteBufferReader $in)
Definition
UnlockedRecipesPacket.php:55
pocketmine\network\mcpe\protocol\UnlockedRecipesPacket\getRecipes
getRecipes()
Definition
UnlockedRecipesPacket.php:53
pocketmine\network\mcpe\protocol\UnlockedRecipesPacket\encodePayload
encodePayload(ByteBufferWriter $out)
Definition
UnlockedRecipesPacket.php:63
pocketmine\network\mcpe\protocol\UnlockedRecipesPacket\create
static create(int $type, array $recipes)
Definition
UnlockedRecipesPacket.php:41
pocketmine\network\mcpe\protocol\UnlockedRecipesPacket\handle
handle(PacketHandlerInterface $handler)
Definition
UnlockedRecipesPacket.php:71
pocketmine\network\mcpe\protocol\serializer\CommonTypes
Definition
CommonTypes.php:70
pocketmine\network\mcpe\protocol\ClientboundPacket
Definition
ClientboundPacket.php:17
pocketmine\network\mcpe\protocol\PacketHandlerInterface
Definition
PacketHandlerInterface.php:20
vendor
pocketmine
bedrock-protocol
src
UnlockedRecipesPacket.php
Generated by
1.12.0