13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol;
32 public const NETWORK_ID = ProtocolInfo::CRAFTING_DATA_PACKET;
34 public const ENTRY_SHAPELESS = 0;
35 public const ENTRY_SHAPED = 1;
36 public const ENTRY_FURNACE = 2;
37 public const ENTRY_FURNACE_DATA = 3;
38 public const ENTRY_MULTI = 4;
39 public const ENTRY_SHULKER_BOX = 5;
40 public const ENTRY_SHAPELESS_CHEMISTRY = 6;
41 public const ENTRY_SHAPED_CHEMISTRY = 7;
42 public const ENTRY_SMITHING_TRANSFORM = 8;
43 public const ENTRY_SMITHING_TRIM = 9;
46 public array $recipesWithTypeIds = [];
48 public array $potionTypeRecipes = [];
50 public array $potionContainerRecipes = [];
52 public array $materialReducerRecipes = [];
53 public bool $cleanRecipes =
false;
62 public static function create(array $recipesWithTypeIds, array $potionTypeRecipes, array $potionContainerRecipes, array $materialReducerRecipes,
bool $cleanRecipes) : self{
64 $result->recipesWithTypeIds = $recipesWithTypeIds;
65 $result->potionTypeRecipes = $potionTypeRecipes;
66 $result->potionContainerRecipes = $potionContainerRecipes;
67 $result->materialReducerRecipes = $materialReducerRecipes;
68 $result->cleanRecipes = $cleanRecipes;
73 $recipeCount = $in->getUnsignedVarInt();
74 for($i = 0; $i < $recipeCount; ++$i){
77 $this->recipesWithTypeIds[] = match($recipeType){
78 self::ENTRY_SHAPELESS, self::ENTRY_SHULKER_BOX, self::ENTRY_SHAPELESS_CHEMISTRY => ShapelessRecipe::decode($recipeType, $in),
79 self::ENTRY_SHAPED, self::ENTRY_SHAPED_CHEMISTRY => ShapedRecipe::decode($recipeType, $in),
80 self::ENTRY_FURNACE, self::ENTRY_FURNACE_DATA => FurnaceRecipe::decode($recipeType, $in),
81 self::ENTRY_MULTI => MultiRecipe::decode($recipeType, $in),
82 self::ENTRY_SMITHING_TRANSFORM => SmithingTransformRecipe::decode($recipeType, $in),
83 self::ENTRY_SMITHING_TRIM => SmithingTrimRecipe::decode($recipeType, $in),
94 $this->potionTypeRecipes[] =
new PotionTypeRecipe($inputId, $inputMeta, $ingredientId, $ingredientMeta, $outputId, $outputMeta);
100 $this->potionContainerRecipes[] =
new PotionContainerChangeRecipe($input, $ingredient, $output);
104 [$inputId, $inputMeta] = [$inputIdAndData >> 16, $inputIdAndData & 0x7fff];
109 $outputs[] =
new MaterialReducerRecipeOutput($outputItemId, $outputItemCount);
111 $this->materialReducerRecipes[] =
new MaterialReducerRecipe($inputId, $inputMeta, $outputs);
113 $this->cleanRecipes = $in->
getBool();
117 $out->putUnsignedVarInt(count($this->recipesWithTypeIds));
118 foreach($this->recipesWithTypeIds as $d){
123 foreach($this->potionTypeRecipes as $recipe){
124 $out->
putVarInt($recipe->getInputItemId());
125 $out->
putVarInt($recipe->getInputItemMeta());
126 $out->
putVarInt($recipe->getIngredientItemId());
127 $out->
putVarInt($recipe->getIngredientItemMeta());
128 $out->
putVarInt($recipe->getOutputItemId());
129 $out->
putVarInt($recipe->getOutputItemMeta());
132 foreach($this->potionContainerRecipes as $recipe){
133 $out->
putVarInt($recipe->getInputItemId());
134 $out->
putVarInt($recipe->getIngredientItemId());
135 $out->
putVarInt($recipe->getOutputItemId());
138 foreach($this->materialReducerRecipes as $recipe){
139 $out->
putVarInt(($recipe->getInputItemId() << 16) | $recipe->getInputItemMeta());
141 foreach($recipe->getOutputs() as $output){
146 $out->putBool($this->cleanRecipes);
150 return $handler->handleCraftingData($this);
encodePayload(PacketSerializer $out)
decodePayload(PacketSerializer $in)
static create(array $recipesWithTypeIds, array $potionTypeRecipes, array $potionContainerRecipes, array $materialReducerRecipes, bool $cleanRecipes)
handle(PacketHandlerInterface $handler)
putUnsignedVarInt(int $v)