11package net .pitan76 .mcpitanlib .midohra .recipe .input ;
22
3+ import net .minecraft .recipe .input .CraftingRecipeInput ;
4+ import net .minecraft .recipe .input .RecipeInput ;
5+ import net .minecraft .recipe .input .SingleStackRecipeInput ;
36import net .minecraft .world .Container ;
47import net .minecraft .world .item .crafting .RecipeInput ;
8+ import net .pitan76 .mcpitanlib .api .util .inventory .CompatInventory ;
59import org .jetbrains .annotations .Nullable ;
610
711public class TypedRecipeInputOrInventory <T extends RecipeInput > extends RecipeInputOrInventory {
@@ -18,6 +22,29 @@ public static <T extends RecipeInput> TypedRecipeInputOrInventory<T> _of(T recip
1822 return new TypedRecipeInputOrInventory <>(recipeInput );
1923 }
2024
25+ public static <T extends RecipeInput > TypedRecipeInputOrInventory <T > _of (CompatInventory recipeInput ) {
26+ if (recipeInput instanceof RecipeInput ) {
27+ return _of ((T ) recipeInput );
28+ }
29+
30+ if (recipeInput .callSize () == 1 ) {
31+ SingleStackRecipeInput singleStackInput = new SingleStackRecipeInput (recipeInput .getItem (0 ));
32+ return _of ((T ) singleStackInput );
33+ }
34+
35+ if (recipeInput .callSize () == 4 ) {
36+ CraftingRecipeInput craftingInput = CraftingRecipeInput .create (2 , 2 , recipeInput .callGetHeldStacks ());
37+ return _of ((T ) craftingInput );
38+ }
39+
40+ if (recipeInput .callSize () == 9 ) {
41+ CraftingRecipeInput craftingInput = CraftingRecipeInput .create (3 , 3 , recipeInput .callGetHeldStacks ());
42+ return _of ((T ) craftingInput );
43+ }
44+
45+ return new TypedRecipeInputOrInventory <>(null );
46+ }
47+
2148 public static TypedRecipeInputOrInventory <?> of (Container inventory ) {
2249 if (inventory instanceof RecipeInput ) {
2350 return _of ((RecipeInput ) inventory );
0 commit comments