PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
CraftRecipeAutoStackRequestAction.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\inventory\stackrequest;
16
18use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
20use function count;
21
27 use GetTypeIdFromConstTrait;
28
29 public const ID = ItemStackRequestActionType::CRAFTING_RECIPE_AUTO;
30
35 final public function __construct(
36 private int $recipeId,
37 private int $repetitions,
38 private int $repetitions2,
39 private array $ingredients
40 ){}
41
42 public function getRecipeId() : int{ return $this->recipeId; }
43
44 public function getRepetitions() : int{ return $this->repetitions; }
45
46 public function getRepetitions2() : int{ return $this->repetitions2; }
47
52 public function getIngredients() : array{ return $this->ingredients; }
53
54 public static function read(PacketSerializer $in) : self{
55 $recipeId = $in->readRecipeNetId();
56 $repetitions = $in->getByte();
57 $repetitions2 = $in->getByte(); //repetitions property is sent twice, mojang...
58 $ingredients = [];
59 for($i = 0, $count = $in->getByte(); $i < $count; ++$i){
60 $ingredients[] = $in->getRecipeIngredient();
61 }
62 return new self($recipeId, $repetitions, $repetitions2, $ingredients);
63 }
64
65 public function write(PacketSerializer $out) : void{
66 $out->writeRecipeNetId($this->recipeId);
67 $out->putByte($this->repetitions);
68 $out->putByte($this->repetitions2);
69 $out->putByte(count($this->ingredients));
70 foreach($this->ingredients as $ingredient){
71 $out->putRecipeIngredient($ingredient);
72 }
73 }
74}
__construct(private int $recipeId, private int $repetitions, private int $repetitions2, private array $ingredients)