16
16
17
17
use pocketmine \network \mcpe \protocol \serializer \PacketSerializer ;
18
18
use pocketmine \network \mcpe \protocol \types \GetTypeIdFromConstTrait ;
19
+ use pocketmine \network \mcpe \protocol \types \recipe \RecipeIngredient ;
19
20
20
21
/**
21
22
* Tells that the current transaction crafted the specified recipe, using the recipe book. This is effectively the same
@@ -26,23 +27,42 @@ final class CraftRecipeAutoStackRequestAction extends ItemStackRequestAction{
26
27
27
28
public const ID = ItemStackRequestActionType::CRAFTING_RECIPE_AUTO ;
28
29
30
+ /**
31
+ * @param RecipeIngredient[] $ingredients
32
+ * @phpstan-param list<RecipeIngredient> $ingredients
33
+ */
29
34
final public function __construct (
30
35
private int $ recipeId ,
31
- private int $ repetitions
36
+ private int $ repetitions ,
37
+ private array $ ingredients
32
38
){}
33
39
34
40
public function getRecipeId () : int { return $ this ->recipeId ; }
35
41
36
42
public function getRepetitions () : int { return $ this ->repetitions ; }
37
43
44
+ /**
45
+ * @return RecipeIngredient[]
46
+ * @phpstan-return list<RecipeIngredient>
47
+ */
48
+ public function getIngredients () : array { return $ this ->ingredients ; }
49
+
38
50
public static function read (PacketSerializer $ in ) : self {
39
51
$ recipeId = $ in ->readGenericTypeNetworkId ();
40
52
$ repetitions = $ in ->getByte ();
41
- return new self ($ recipeId , $ repetitions );
53
+ $ ingredients = [];
54
+ for ($ i = 0 , $ count = $ in ->getByte (); $ i < $ count ; ++$ i ){
55
+ $ ingredients [] = $ in ->getRecipeIngredient ();
56
+ }
57
+ return new self ($ recipeId , $ repetitions , $ ingredients );
42
58
}
43
59
44
60
public function write (PacketSerializer $ out ) : void {
45
61
$ out ->writeGenericTypeNetworkId ($ this ->recipeId );
46
62
$ out ->putByte ($ this ->repetitions );
63
+ $ out ->putByte (count ($ this ->ingredients ));
64
+ foreach ($ this ->ingredients as $ ingredient ){
65
+ $ out ->putRecipeIngredient ($ ingredient );
66
+ }
47
67
}
48
68
}
0 commit comments