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_USER_DATA_SHAPELESS = 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 $previousType =
"none";
75 for($i = 0; $i < $recipeCount; ++$i){
78 $this->recipesWithTypeIds[] = match($recipeType){
79 self::ENTRY_SHAPELESS, self::ENTRY_USER_DATA_SHAPELESS, self::ENTRY_SHAPELESS_CHEMISTRY => ShapelessRecipe::decode($recipeType, $in),
80 self::ENTRY_SHAPED, self::ENTRY_SHAPED_CHEMISTRY => ShapedRecipe::decode($recipeType, $in),
81 self::ENTRY_FURNACE, self::ENTRY_FURNACE_DATA => FurnaceRecipe::decode($recipeType, $in),
82 self::ENTRY_MULTI => MultiRecipe::decode($recipeType, $in),
83 self::ENTRY_SMITHING_TRANSFORM => SmithingTransformRecipe::decode($recipeType, $in),
84 self::ENTRY_SMITHING_TRIM => SmithingTrimRecipe::decode($recipeType, $in),
85 default =>
throw new PacketDecodeException(
"Unhandled recipe type $recipeType (previous was $previousType)"),
87 $previousType = $recipeType;
96 $this->potionTypeRecipes[] =
new PotionTypeRecipe($inputId, $inputMeta, $ingredientId, $ingredientMeta, $outputId, $outputMeta);
102 $this->potionContainerRecipes[] =
new PotionContainerChangeRecipe($input, $ingredient, $output);
106 [$inputId, $inputMeta] = [$inputIdAndData >> 16, $inputIdAndData & 0x7fff];
111 $outputs[] =
new MaterialReducerRecipeOutput($outputItemId, $outputItemCount);
113 $this->materialReducerRecipes[] =
new MaterialReducerRecipe($inputId, $inputMeta, $outputs);
115 $this->cleanRecipes = $in->
getBool();
119 $out->putUnsignedVarInt(count($this->recipesWithTypeIds));
120 foreach($this->recipesWithTypeIds as $d){
125 foreach($this->potionTypeRecipes as $recipe){
126 $out->
putVarInt($recipe->getInputItemId());
127 $out->
putVarInt($recipe->getInputItemMeta());
128 $out->
putVarInt($recipe->getIngredientItemId());
129 $out->
putVarInt($recipe->getIngredientItemMeta());
130 $out->
putVarInt($recipe->getOutputItemId());
131 $out->
putVarInt($recipe->getOutputItemMeta());
134 foreach($this->potionContainerRecipes as $recipe){
135 $out->
putVarInt($recipe->getInputItemId());
136 $out->
putVarInt($recipe->getIngredientItemId());
137 $out->
putVarInt($recipe->getOutputItemId());
140 foreach($this->materialReducerRecipes as $recipe){
141 $out->
putVarInt(($recipe->getInputItemId() << 16) | $recipe->getInputItemMeta());
143 foreach($recipe->getOutputs() as $output){
148 $out->putBool($this->cleanRecipes);
152 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)