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 = VarInt::readUnsignedInt($in);
74 $previousType =
"none";
75 for($i = 0; $i < $recipeCount; ++$i){
76 $recipeType = VarInt::readSignedInt($in);
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_MULTI => MultiRecipe::decode($recipeType, $in),
82 self::ENTRY_SMITHING_TRANSFORM => SmithingTransformRecipe::decode($recipeType, $in),
83 self::ENTRY_SMITHING_TRIM => SmithingTrimRecipe::decode($recipeType, $in),
84 default =>
throw new PacketDecodeException(
"Unhandled recipe type $recipeType (previous was $previousType)"),
86 $previousType = $recipeType;
88 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
89 $inputId = VarInt::readSignedInt($in);
90 $inputMeta = VarInt::readSignedInt($in);
91 $ingredientId = VarInt::readSignedInt($in);
92 $ingredientMeta = VarInt::readSignedInt($in);
93 $outputId = VarInt::readSignedInt($in);
94 $outputMeta = VarInt::readSignedInt($in);
95 $this->potionTypeRecipes[] =
new PotionTypeRecipe($inputId, $inputMeta, $ingredientId, $ingredientMeta, $outputId, $outputMeta);
97 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
98 $input = VarInt::readSignedInt($in);
99 $ingredient = VarInt::readSignedInt($in);
100 $output = VarInt::readSignedInt($in);
101 $this->potionContainerRecipes[] =
new PotionContainerChangeRecipe($input, $ingredient, $output);
103 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
104 $inputIdAndData = VarInt::readSignedInt($in);
105 [$inputId, $inputMeta] = [$inputIdAndData >> 16, $inputIdAndData & 0x7fff];
107 for($j = 0, $outputCount = VarInt::readUnsignedInt($in); $j < $outputCount; ++$j){
108 $outputItemId = VarInt::readSignedInt($in);
109 $outputItemCount = VarInt::readSignedInt($in);
110 $outputs[] =
new MaterialReducerRecipeOutput($outputItemId, $outputItemCount);
112 $this->materialReducerRecipes[] =
new MaterialReducerRecipe($inputId, $inputMeta, $outputs);
114 $this->cleanRecipes = CommonTypes::getBool($in);
118 VarInt::writeUnsignedInt($out, count($this->recipesWithTypeIds));
119 foreach($this->recipesWithTypeIds as $d){
120 VarInt::writeSignedInt($out, $d->getTypeId());
123 VarInt::writeUnsignedInt($out, count($this->potionTypeRecipes));
124 foreach($this->potionTypeRecipes as $recipe){
125 VarInt::writeSignedInt($out, $recipe->getInputItemId());
126 VarInt::writeSignedInt($out, $recipe->getInputItemMeta());
127 VarInt::writeSignedInt($out, $recipe->getIngredientItemId());
128 VarInt::writeSignedInt($out, $recipe->getIngredientItemMeta());
129 VarInt::writeSignedInt($out, $recipe->getOutputItemId());
130 VarInt::writeSignedInt($out, $recipe->getOutputItemMeta());
132 VarInt::writeUnsignedInt($out, count($this->potionContainerRecipes));
133 foreach($this->potionContainerRecipes as $recipe){
134 VarInt::writeSignedInt($out, $recipe->getInputItemId());
135 VarInt::writeSignedInt($out, $recipe->getIngredientItemId());
136 VarInt::writeSignedInt($out, $recipe->getOutputItemId());
138 VarInt::writeUnsignedInt($out, count($this->materialReducerRecipes));
139 foreach($this->materialReducerRecipes as $recipe){
140 VarInt::writeSignedInt($out, ($recipe->getInputItemId() << 16) | $recipe->getInputItemMeta());
141 VarInt::writeUnsignedInt($out, count($recipe->getOutputs()));
142 foreach($recipe->getOutputs() as $output){
143 VarInt::writeSignedInt($out, $output->getItemId());
144 VarInt::writeSignedInt($out, $output->getCount());
147 CommonTypes::putBool($out, $this->cleanRecipes);