57 private array $caches = [];
60 $id = spl_object_id($manager);
61 if(!isset($this->caches[$id])){
62 $manager->getDestructorCallbacks()->add(
function() use ($id) :
void{
63 unset($this->caches[$id]);
66 unset($this->caches[$id]);
68 $this->caches[$id] = $this->buildCraftingDataCache($manager);
70 return $this->caches[$id];
77 Timings::$craftingDataCacheRebuild->startTiming();
79 $nullUUID = Uuid::fromString(Uuid::NIL);
80 $converter = TypeConverter::getInstance();
81 $recipesWithTypeIds = [];
86 $typeTag = match($recipe->getType()){
87 ShapelessRecipeType::CRAFTING => CraftingRecipeBlockName::CRAFTING_TABLE,
88 ShapelessRecipeType::STONECUTTER => CraftingRecipeBlockName::STONECUTTER,
89 ShapelessRecipeType::CARTOGRAPHY => CraftingRecipeBlockName::CARTOGRAPHY_TABLE,
90 ShapelessRecipeType::SMITHING => CraftingRecipeBlockName::SMITHING_TABLE,
92 $recipesWithTypeIds[] =
new ProtocolShapelessRecipe(
93 CraftingDataPacket::ENTRY_SHAPELESS,
94 Binary::writeInt($index),
95 array_map($converter->coreRecipeIngredientToNet(...), $recipe->getIngredientList()),
96 array_map($converter->coreItemStackToNet(...), $recipe->getResults()),
100 $noUnlockingRequirement,
106 for($row = 0, $height = $recipe->getHeight(); $row < $height; ++$row){
107 for($column = 0, $width = $recipe->getWidth(); $column < $width; ++$column){
108 $inputs[$row][$column] = $converter->coreRecipeIngredientToNet($recipe->getIngredient($column, $row));
111 $recipesWithTypeIds[] = $r =
new ProtocolShapedRecipe(
112 CraftingDataPacket::ENTRY_SHAPED,
113 Binary::writeInt($index),
115 array_map($converter->coreItemStackToNet(...), $recipe->getResults()),
117 CraftingRecipeBlockName::CRAFTING_TABLE,
120 $noUnlockingRequirement,
128 foreach(FurnaceType::cases() as $furnaceType){
129 $typeTag = match($furnaceType){
130 FurnaceType::FURNACE => FurnaceRecipeBlockName::FURNACE,
131 FurnaceType::BLAST_FURNACE => FurnaceRecipeBlockName::BLAST_FURNACE,
132 FurnaceType::SMOKER => FurnaceRecipeBlockName::SMOKER,
133 FurnaceType::CAMPFIRE => FurnaceRecipeBlockName::CAMPFIRE,
134 FurnaceType::SOUL_CAMPFIRE => FurnaceRecipeBlockName::SOUL_CAMPFIRE
136 foreach($manager->getFurnaceRecipeManager($furnaceType)->getAll() as $recipe){
137 $input = $converter->coreRecipeIngredientToNet($recipe->getInput())->getDescriptor();
141 $recipesWithTypeIds[] =
new ProtocolFurnaceRecipe(
142 CraftingDataPacket::ENTRY_FURNACE_DATA,
145 $converter->coreItemStackToNet($recipe->getResult()),
151 $potionTypeRecipes = [];
153 $input = $converter->coreRecipeIngredientToNet($recipe->getInput())->getDescriptor();
154 $ingredient = $converter->coreRecipeIngredientToNet($recipe->getIngredient())->getDescriptor();
158 $output = $converter->coreItemStackToNet($recipe->getOutput());
159 $potionTypeRecipes[] =
new ProtocolPotionTypeRecipe(
162 $ingredient->getId(),
163 $ingredient->getMeta(),
169 $potionContainerChangeRecipes = [];
170 $itemTypeDictionary = $converter->getItemTypeDictionary();
172 $input = $itemTypeDictionary->fromStringId($recipe->getInputItemId());
173 $ingredient = $converter->coreRecipeIngredientToNet($recipe->getIngredient())->getDescriptor();
177 $output = $itemTypeDictionary->fromStringId($recipe->getOutputItemId());
178 $potionContainerChangeRecipes[] =
new ProtocolPotionContainerChangeRecipe(
180 $ingredient->getId(),
185 Timings::$craftingDataCacheRebuild->stopTiming();