PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
21use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
23use function count;
24
30 use GetTypeIdFromConstTrait;
31
32 public const ID = ItemStackRequestActionType::CRAFTING_RECIPE_AUTO;
33
38 final public function __construct(
39 private int $recipeId,
40 private int $repetitions,
41 private int $repetitions2,
42 private array $ingredients
43 ){}
44
45 public function getRecipeId() : int{ return $this->recipeId; }
46
47 public function getRepetitions() : int{ return $this->repetitions; }
48
49 public function getRepetitions2() : int{ return $this->repetitions2; }
50
55 public function getIngredients() : array{ return $this->ingredients; }
56
57 public static function read(ByteBufferReader $in) : self{
58 $recipeId = CommonTypes::readRecipeNetId($in);
59 $repetitions = Byte::readUnsigned($in);
60 $repetitions2 = Byte::readUnsigned($in); //repetitions property is sent twice, mojang...
61 $ingredients = [];
62 for($i = 0, $count = Byte::readUnsigned($in); $i < $count; ++$i){
63 $ingredients[] = CommonTypes::getRecipeIngredient($in);
64 }
65 return new self($recipeId, $repetitions, $repetitions2, $ingredients);
66 }
67
68 public function write(ByteBufferWriter $out) : void{
69 CommonTypes::writeRecipeNetId($out, $this->recipeId);
70 Byte::writeUnsigned($out, $this->repetitions);
71 Byte::writeUnsigned($out, $this->repetitions2);
72 Byte::writeUnsigned($out, count($this->ingredients));
73 foreach($this->ingredients as $ingredient){
74 CommonTypes::putRecipeIngredient($out, $ingredient);
75 }
76 }
77}
__construct(private int $recipeId, private int $repetitions, private int $repetitions2, private array $ingredients)