77import com .google .common .collect .ImmutableMap ;
88import com .google .common .collect .ImmutableMultimap ;
99import net .minecraft .resources .ResourceLocation ;
10+ import net .minecraft .world .item .ItemStack ;
11+ import net .minecraft .world .item .crafting .Ingredient ;
1012import net .minecraft .world .item .crafting .Recipe ;
1113import net .minecraft .world .item .crafting .RecipeHolder ;
1214import net .minecraft .world .item .crafting .RecipeManager ;
2123import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2224
2325import java .util .List ;
26+ import java .util .Optional ;
2427
2528@ Mixin (RecipeManager .class )
2629public class RecipeManagerMixin {
@@ -29,21 +32,30 @@ public class RecipeManagerMixin {
2932 private static void collectRecipe (ResourceLocation recipeId , ImmutableMultimap .Builder <RecipeType <?>, RecipeHolder <?>> byType ,
3033 ImmutableMap .Builder <ResourceLocation , RecipeHolder <?>> byName , WithConditions <Recipe <?>> recipeWithConditions , CallbackInfo ci ) {
3134 if (recipeWithConditions .carrier () instanceof SmeltingRecipe smeltingRecipe ) {
32- RecipeHolder <AlloySmeltingRecipe > convertedHolder = enderio$convert (recipeId , smeltingRecipe );
33- byType .put (MachineRecipes .ALLOY_SMELTING .type ().get (), convertedHolder );
34- byName .put (convertedHolder .id (), convertedHolder );
35+ Optional <RecipeHolder <AlloySmeltingRecipe >> convertedHolder = enderio$convert (recipeId , smeltingRecipe );
36+
37+ convertedHolder .ifPresent (holder -> {
38+ byType .put (MachineRecipes .ALLOY_SMELTING .type ().get (), holder );
39+ byName .put (holder .id (), holder );
40+ });
3541 }
3642 }
3743
3844 @ Unique
39- private static RecipeHolder <AlloySmeltingRecipe > enderio$convert (ResourceLocation originalId , SmeltingRecipe smeltingRecipe ) {
45+ private static Optional < RecipeHolder <AlloySmeltingRecipe > > enderio$convert (ResourceLocation originalId , SmeltingRecipe smeltingRecipe ) {
4046 AbstractCookingRecipeAccessor accessor = (AbstractCookingRecipeAccessor ) smeltingRecipe ;
47+
48+ if (accessor .getResult ().isEmpty ()) {
49+ EnderIOBase .LOGGER .warn ("Unable to inherit the cooking recipe with ID: {}. Reason: The result item is empty." , originalId );
50+ return Optional .empty ();
51+ }
52+
4153 SizedIngredient input = new SizedIngredient (accessor .getIngredient (), 1 );
4254 int energy = MachinesConfig .COMMON .ENERGY .ALLOY_SMELTER_VANILLA_ITEM_ENERGY .get ();
4355 AlloySmeltingRecipe recipe = new AlloySmeltingRecipe (List .of (input ), accessor .getResult (), energy , accessor .getExperience (), true );
4456
4557 String path = "smelting/" + originalId .getNamespace () + "/" + originalId .getPath ();
4658 ResourceLocation id = EnderIOBase .loc (path );
47- return new RecipeHolder <>(id , recipe );
59+ return Optional . of ( new RecipeHolder <>(id , recipe ) );
4860 }
4961}
0 commit comments