@@ -56,6 +56,12 @@ final class CraftingDataCache{
56
56
*/
57
57
private array $ caches = [];
58
58
59
+ /**
60
+ * The client doesn't like recipes with ID 0 (as of 1.21.100) and complains about them in the content log
61
+ * This doesn't actually affect the function of the recipe, but it is annoying, so this offset fixes it
62
+ */
63
+ public const RECIPE_ID_OFFSET = 1 ;
64
+
59
65
public function getCache (CraftingManager $ manager ) : CraftingDataPacket {
60
66
$ id = spl_object_id ($ manager );
61
67
if (!isset ($ this ->caches [$ id ])){
@@ -82,6 +88,8 @@ private function buildCraftingDataCache(CraftingManager $manager) : CraftingData
82
88
83
89
$ noUnlockingRequirement = new RecipeUnlockingRequirement (null );
84
90
foreach ($ manager ->getCraftingRecipeIndex () as $ index => $ recipe ){
91
+ //the client doesn't like recipes with an ID of 0, so we need to offset them
92
+ $ recipeNetId = $ index + self ::RECIPE_ID_OFFSET ;
85
93
if ($ recipe instanceof ShapelessRecipe){
86
94
$ typeTag = match ($ recipe ->getType ()){
87
95
ShapelessRecipeType::CRAFTING => CraftingRecipeBlockName::CRAFTING_TABLE ,
@@ -91,14 +99,14 @@ private function buildCraftingDataCache(CraftingManager $manager) : CraftingData
91
99
};
92
100
$ recipesWithTypeIds [] = new ProtocolShapelessRecipe (
93
101
CraftingDataPacket::ENTRY_SHAPELESS ,
94
- Binary::writeInt ($ index ),
102
+ Binary::writeInt ($ recipeNetId ),
95
103
array_map ($ converter ->coreRecipeIngredientToNet (...), $ recipe ->getIngredientList ()),
96
104
array_map ($ converter ->coreItemStackToNet (...), $ recipe ->getResults ()),
97
105
$ nullUUID ,
98
106
$ typeTag ,
99
107
50 ,
100
108
$ noUnlockingRequirement ,
101
- $ index
109
+ $ recipeNetId
102
110
);
103
111
}elseif ($ recipe instanceof ShapedRecipe){
104
112
$ inputs = [];
@@ -110,15 +118,15 @@ private function buildCraftingDataCache(CraftingManager $manager) : CraftingData
110
118
}
111
119
$ recipesWithTypeIds [] = $ r = new ProtocolShapedRecipe (
112
120
CraftingDataPacket::ENTRY_SHAPED ,
113
- Binary::writeInt ($ index ),
121
+ Binary::writeInt ($ recipeNetId ),
114
122
$ inputs ,
115
123
array_map ($ converter ->coreItemStackToNet (...), $ recipe ->getResults ()),
116
124
$ nullUUID ,
117
125
CraftingRecipeBlockName::CRAFTING_TABLE ,
118
126
50 ,
119
127
true ,
120
128
$ noUnlockingRequirement ,
121
- $ index ,
129
+ $ recipeNetId ,
122
130
);
123
131
}else {
124
132
//TODO: probably special recipe types
0 commit comments