Skip to content

Commit

Permalink
CraftRecipeAutoStackRequestAction: added missing protocol change from…
Browse files Browse the repository at this point in the history
… 1.19.40
  • Loading branch information
dktapps committed Nov 19, 2022
1 parent e5c8a67 commit 9c39f26
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
use pocketmine\network\mcpe\protocol\types\recipe\RecipeIngredient;

/**
* Tells that the current transaction crafted the specified recipe, using the recipe book. This is effectively the same
Expand All @@ -26,23 +27,42 @@ final class CraftRecipeAutoStackRequestAction extends ItemStackRequestAction{

public const ID = ItemStackRequestActionType::CRAFTING_RECIPE_AUTO;

/**
* @param RecipeIngredient[] $ingredients
* @phpstan-param list<RecipeIngredient> $ingredients
*/
final public function __construct(
private int $recipeId,
private int $repetitions
private int $repetitions,
private array $ingredients
){}

public function getRecipeId() : int{ return $this->recipeId; }

public function getRepetitions() : int{ return $this->repetitions; }

/**
* @return RecipeIngredient[]
* @phpstan-return list<RecipeIngredient>
*/
public function getIngredients() : array{ return $this->ingredients; }

public static function read(PacketSerializer $in) : self{
$recipeId = $in->readGenericTypeNetworkId();
$repetitions = $in->getByte();
return new self($recipeId, $repetitions);
$ingredients = [];
for($i = 0, $count = $in->getByte(); $i < $count; ++$i){
$ingredients[] = $in->getRecipeIngredient();
}
return new self($recipeId, $repetitions, $ingredients);
}

public function write(PacketSerializer $out) : void{
$out->writeGenericTypeNetworkId($this->recipeId);
$out->putByte($this->repetitions);
$out->putByte(count($this->ingredients));
foreach($this->ingredients as $ingredient){
$out->putRecipeIngredient($ingredient);
}
}
}

0 comments on commit 9c39f26

Please sign in to comment.