Skip to content

Commit b6ea417

Browse files
committed
feat: enhance TypedRecipeInputOrInventory for improved recipe input handling
1 parent c844619 commit b6ea417

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/Recipe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public ItemStack getOutput(World world) {
102102
inventory.callSetStack(i, stack);
103103
}
104104

105-
return craftMidohra(RecipeInputOrInventory.of(inventory), world);
105+
return craftMidohra(TypedRecipeInputOrInventory._of(inventory), world);
106106
}
107107

108108
private ItemStack cachedOutput = null;

common/src/main/java/net/pitan76/mcpitanlib/midohra/recipe/input/TypedRecipeInputOrInventory.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package 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;
36
import net.minecraft.world.Container;
47
import net.minecraft.world.item.crafting.RecipeInput;
8+
import net.pitan76.mcpitanlib.api.util.inventory.CompatInventory;
59
import org.jetbrains.annotations.Nullable;
610

711
public 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

Comments
 (0)