PocketMine-MP 5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
Loading...
Searching...
No Matches
RecipeUnlockingRequirement.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\types\recipe;
16
18use function count;
19
21
26 public function __construct(
27 private ?array $unlockingIngredients
28 ){}
29
34 public function getUnlockingIngredients() : ?array{ return $this->unlockingIngredients; }
35
36 public static function read(PacketSerializer $in) : self{
37 //I don't know what the point of this structure is. It could easily have been a list<RecipeIngredient> instead.
38 //It's basically just an optional list, which could have been done by an empty list wherever it's not needed.
39 $unlockingContext = $in->getBool();
40 $unlockingIngredients = null;
41 if(!$unlockingContext){
42 $unlockingIngredients = [];
43 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; $i++){
44 $unlockingIngredients[] = $in->getRecipeIngredient();
45 }
46 }
47
48 return new self($unlockingIngredients);
49 }
50
51 public function write(PacketSerializer $out) : void{
52 $out->putBool($this->unlockingIngredients === null);
53 if($this->unlockingIngredients !== null){
54 $out->putUnsignedVarInt(count($this->unlockingIngredients));
55 foreach($this->unlockingIngredients as $ingredient){
56 $out->putRecipeIngredient($ingredient);
57 }
58 }
59 }
60}