PocketMine-MP 5.18.1 git-9381fc4172e5dce4cada1cb356050c8a2ab57b94
vendor/pocketmine/bedrock-protocol/src/types/recipe/ShapelessRecipe.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
19use Ramsey\Uuid\UuidInterface;
20use function count;
21
27 public function __construct(
28 int $typeId,
29 private string $recipeId,
30 private array $inputs,
31 private array $outputs,
32 private UuidInterface $uuid,
33 private string $blockName,
34 private int $priority,
35 private RecipeUnlockingRequirement $unlockingRequirement,
36 private int $recipeNetId
37 ){
38 parent::__construct($typeId);
39 }
40
41 public function getRecipeId() : string{
42 return $this->recipeId;
43 }
44
48 public function getInputs() : array{
49 return $this->inputs;
50 }
51
55 public function getOutputs() : array{
56 return $this->outputs;
57 }
58
59 public function getUuid() : UuidInterface{
60 return $this->uuid;
61 }
62
63 public function getBlockName() : string{
64 return $this->blockName;
65 }
66
67 public function getPriority() : int{
68 return $this->priority;
69 }
70
71 public function getUnlockingRequirement() : RecipeUnlockingRequirement{ return $this->unlockingRequirement; }
72
73 public function getRecipeNetId() : int{
74 return $this->recipeNetId;
75 }
76
77 public static function decode(int $recipeType, PacketSerializer $in) : self{
78 $recipeId = $in->getString();
79 $input = [];
80 for($j = 0, $ingredientCount = $in->getUnsignedVarInt(); $j < $ingredientCount; ++$j){
81 $input[] = $in->getRecipeIngredient();
82 }
83 $output = [];
84 for($k = 0, $resultCount = $in->getUnsignedVarInt(); $k < $resultCount; ++$k){
85 $output[] = $in->getItemStackWithoutStackId();
86 }
87 $uuid = $in->getUUID();
88 $block = $in->getString();
89 $priority = $in->getVarInt();
90 $unlockingRequirement = RecipeUnlockingRequirement::read($in);
91
92 $recipeNetId = $in->readRecipeNetId();
93
94 return new self($recipeType, $recipeId, $input, $output, $uuid, $block, $priority, $unlockingRequirement, $recipeNetId);
95 }
96
97 public function encode(PacketSerializer $out) : void{
98 $out->putString($this->recipeId);
99 $out->putUnsignedVarInt(count($this->inputs));
100 foreach($this->inputs as $item){
101 $out->putRecipeIngredient($item);
102 }
103
104 $out->putUnsignedVarInt(count($this->outputs));
105 foreach($this->outputs as $item){
106 $out->putItemStackWithoutStackId($item);
107 }
108
109 $out->putUUID($this->uuid);
110 $out->putString($this->blockName);
111 $out->putVarInt($this->priority);
112 $this->unlockingRequirement->write($out);
113
114 $out->writeRecipeNetId($this->recipeNetId);
115 }
116}
__construct(int $typeId, private string $recipeId, private array $inputs, private array $outputs, private UuidInterface $uuid, private string $blockName, private int $priority, private RecipeUnlockingRequirement $unlockingRequirement, private int $recipeNetId)