package techreborn.compat.jei; import mezz.jei.api.ingredients.IIngredients; import mezz.jei.api.recipe.BlankRecipeWrapper; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; import techreborn.api.recipe.BaseRecipe; import javax.annotation.Nonnull; import java.util.*; public abstract class BaseRecipeWrapper extends BlankRecipeWrapper { protected final T baseRecipe; @Nonnull private final List> inputs; @Nonnull private final List> outputs; public BaseRecipeWrapper(T baseRecipe) { this.baseRecipe = baseRecipe; inputs = new ArrayList<>(); outputs = new ArrayList<>(); for (ItemStack input : baseRecipe.getInputs()) { if (baseRecipe.useOreDic()) { List oreDictInputs = expandOreDict(input); inputs.add(oreDictInputs); } else { inputs.add(Collections.singletonList(input)); } } for (ItemStack input : baseRecipe.getOutputs()) { if (baseRecipe.useOreDic()) { List oreDictInputs = expandOreDict(input); outputs.add(oreDictInputs); } else { outputs.add(Collections.singletonList(input)); } } } private static List expandOreDict(ItemStack itemStack) { int[] oreIds = OreDictionary.getOreIDs(itemStack); if (oreIds.length == 0) { return Collections.singletonList(itemStack); } Set itemStackSet = new HashSet<>(); for (int oreId : oreIds) { String oreName = OreDictionary.getOreName(oreId); List ores = OreDictionary.getOres(oreName); for (ItemStack ore : ores) { if (ore.getCount() != itemStack.getCount()) { ItemStack oreCopy = ore.copy(); oreCopy.setCount(itemStack.getCount()); itemStackSet.add(oreCopy); } else { itemStackSet.add(ore); } } } return new ArrayList<>(itemStackSet); } @Override public void getIngredients( @Nonnull IIngredients ingredients) { ingredients.setInputLists(ItemStack.class, inputs); ingredients.setOutputs(ItemStack.class, baseRecipe.getOutputs()); } @Nonnull public List> getInputs() { return inputs; } public List getFluidInputs() { return new ArrayList<>(); } @Nonnull public List getOutputs() { List stacks = new ArrayList<>(); for (List stackList : outputs) { stacks.addAll(stackList); } return stacks; } }