13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol\types\recipe;
19use Ramsey\Uuid\UuidInterface;
23 private string $blockName;
31 private string $recipeId,
33 private array $output,
34 private UuidInterface $uuid,
36 private int $priority,
37 private bool $symmetric,
39 private int $recipeNetId
41 parent::__construct($typeId);
42 $rows = count($input);
43 if($rows < 1 or $rows > 3){
44 throw new \InvalidArgumentException(
"Expected 1, 2 or 3 input rows");
47 foreach($input as $rowNumber => $row){
48 if($columns ===
null){
49 $columns = count($row);
50 }elseif(count($row) !== $columns){
51 throw new \InvalidArgumentException(
"Expected each row to be $columns columns, but have " . count($row) .
" in row $rowNumber");
54 $this->blockName = $blockType;
57 public function getRecipeId() : string{
58 return $this->recipeId;
61 public function getWidth() : int{
62 return count($this->input[0]);
65 public function getHeight() : int{
66 return count($this->input);
83 public function getUuid() : UuidInterface{
87 public function getBlockName() : string{
88 return $this->blockName;
91 public function getPriority() : int{
92 return $this->priority;
95 public function isSymmetric() : bool{ return $this->symmetric; }
97 public function getUnlockingRequirement() : RecipeUnlockingRequirement{ return $this->unlockingRequirement; }
99 public function getRecipeNetId() : int{
100 return $this->recipeNetId;
103 public static function decode(
int $recipeType, PacketSerializer $in) : self{
104 $recipeId = $in->getString();
105 $width = $in->getVarInt();
106 $height = $in->getVarInt();
108 for($row = 0; $row < $height; ++$row){
109 for($column = 0; $column < $width; ++$column){
110 $input[$row][$column] = $in->getRecipeIngredient();
115 for($k = 0, $resultCount = $in->getUnsignedVarInt(); $k < $resultCount; ++$k){
116 $output[] = $in->getItemStackWithoutStackId();
118 $uuid = $in->getUUID();
119 $block = $in->getString();
120 $priority = $in->getVarInt();
121 $symmetric = $in->getBool();
122 $unlockingRequirement = RecipeUnlockingRequirement::read($in);
124 $recipeNetId = $in->readRecipeNetId();
126 return new self($recipeType, $recipeId, $input, $output, $uuid, $block, $priority, $symmetric, $unlockingRequirement, $recipeNetId);
129 public function encode(PacketSerializer $out) : void{
130 $out->putString($this->recipeId);
131 $out->putVarInt($this->getWidth());
132 $out->putVarInt($this->getHeight());
133 foreach($this->input as $row){
134 foreach($row as $ingredient){
135 $out->putRecipeIngredient($ingredient);
139 $out->putUnsignedVarInt(count($this->output));
140 foreach($this->output as $item){
141 $out->putItemStackWithoutStackId($item);
144 $out->putUUID($this->uuid);
145 $out->putString($this->blockName);
146 $out->putVarInt($this->priority);
147 $out->putBool($this->symmetric);
148 $this->unlockingRequirement->write($out);
150 $out->writeRecipeNetId($this->recipeNetId);
__construct(int $typeId, private string $recipeId, private array $input, private array $output, private UuidInterface $uuid, string $blockType, private int $priority, private bool $symmetric, private RecipeUnlockingRequirement $unlockingRequirement, private int $recipeNetId)