PocketMine-MP 5.21.2 git-09bf203267aca9b83a09640e17bfac0fc7b58ff8
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
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
18use function count;
19
21 public const NETWORK_ID = ProtocolInfo::UNLOCKED_RECIPES_PACKET;
22
23 public const TYPE_EMPTY = 0;
24 public const TYPE_INITIALLY_UNLOCKED = 1;
25 public const TYPE_NEWLY_UNLOCKED = 2;
26 public const TYPE_REMOVE = 3;
27 public const TYPE_REMOVE_ALL = 4;
28
29 private int $type;
31 private array $recipes;
32
37 public static function create(int $type, array $recipes) : self{
38 $result = new self;
39 $result->type = $type;
40 $result->recipes = $recipes;
41 return $result;
42 }
43
44 public function getType() : int{ return $this->type; }
45
49 public function getRecipes() : array{ return $this->recipes; }
50
51 protected function decodePayload(PacketSerializer $in) : void{
52 $this->type = $in->getLInt();
53 $this->recipes = [];
54 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; $i++){
55 $this->recipes[] = $in->getString();
56 }
57 }
58
59 protected function encodePayload(PacketSerializer $out) : void{
60 $out->putLInt($this->type);
61 $out->putUnsignedVarInt(count($this->recipes));
62 foreach($this->recipes as $recipe){
63 $out->putString($recipe);
64 }
65 }
66
67 public function handle(PacketHandlerInterface $handler) : bool{
68 return $handler->handleUnlockedRecipes($this);
69 }
70}