Fix oreDict support for recipes in JEI

This commit is contained in:
mezz 2015-12-31 01:19:06 -08:00
parent aed7b5c0c4
commit 6ce72c8339
6 changed files with 35 additions and 9 deletions

View file

@ -1,24 +1,51 @@
package techreborn.compat.jei; package techreborn.compat.jei;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import mezz.jei.api.recipe.BlankRecipeWrapper; import mezz.jei.api.recipe.BlankRecipeWrapper;
import techreborn.api.recipe.BaseRecipe; import techreborn.api.recipe.BaseRecipe;
public abstract class BaseRecipeWrapper<T extends BaseRecipe> extends BlankRecipeWrapper { public abstract class BaseRecipeWrapper<T extends BaseRecipe> extends BlankRecipeWrapper {
protected final T baseRecipe; protected final T baseRecipe;
private final List<List<ItemStack>> inputs;
public BaseRecipeWrapper(T baseRecipe) { public BaseRecipeWrapper(T baseRecipe) {
this.baseRecipe = baseRecipe; this.baseRecipe = baseRecipe;
inputs = new ArrayList<>();
for (ItemStack input : baseRecipe.getInputs()) {
if (baseRecipe.useOreDic()) {
int[] oreIds = OreDictionary.getOreIDs(input);
if (oreIds.length > 0) {
Set<ItemStack> itemStackSet = new HashSet<>();
for (int oreId : oreIds) {
String oreName = OreDictionary.getOreName(oreId);
List<ItemStack> ores = OreDictionary.getOres(oreName);
itemStackSet.addAll(ores);
}
inputs.add(new ArrayList<>(itemStackSet));
} else {
inputs.add(Collections.singletonList(input));
}
} else {
inputs.add(Collections.singletonList(input));
}
}
} }
@Override @Override
public List<ItemStack> getInputs() { public List<List<ItemStack>> getInputs() {
return baseRecipe.getInputs(); return inputs;
} }
@Override @Override

View file

@ -74,7 +74,7 @@ public class BlastFurnaceRecipeCategory implements IRecipeCategory {
if (recipeWrapper instanceof BlastFurnaceRecipeWrapper) { if (recipeWrapper instanceof BlastFurnaceRecipeWrapper) {
BlastFurnaceRecipeWrapper recipe = (BlastFurnaceRecipeWrapper) recipeWrapper; BlastFurnaceRecipeWrapper recipe = (BlastFurnaceRecipeWrapper) recipeWrapper;
List<ItemStack> inputs = recipe.getInputs(); List<List<ItemStack>> inputs = recipe.getInputs();
guiItemStacks.set(INPUT_SLOT_0, inputs.get(0)); guiItemStacks.set(INPUT_SLOT_0, inputs.get(0));
if (inputs.size() > 1) { if (inputs.size() > 1) {
guiItemStacks.set(INPUT_SLOT_1, inputs.get(1)); guiItemStacks.set(INPUT_SLOT_1, inputs.get(1));

View file

@ -71,7 +71,7 @@ public class CentrifugeRecipeCategory implements IRecipeCategory {
if (recipeWrapper instanceof CentrifugeRecipeWrapper) { if (recipeWrapper instanceof CentrifugeRecipeWrapper) {
CentrifugeRecipeWrapper recipe = (CentrifugeRecipeWrapper) recipeWrapper; CentrifugeRecipeWrapper recipe = (CentrifugeRecipeWrapper) recipeWrapper;
List<ItemStack> inputs = recipe.getInputs(); List<List<ItemStack>> inputs = recipe.getInputs();
guiItemStacks.set(INPUT_SLOT, inputs.get(0)); guiItemStacks.set(INPUT_SLOT, inputs.get(0));
if (inputs.size() > 1) { if (inputs.size() > 1) {
guiItemStacks.set(EMPTY_CELL_SLOT, inputs.get(1)); guiItemStacks.set(EMPTY_CELL_SLOT, inputs.get(1));

View file

@ -68,7 +68,7 @@ public class ChemicalReactorRecipeCategory implements IRecipeCategory {
if (recipeWrapper instanceof ChemicalReactorRecipeWrapper) { if (recipeWrapper instanceof ChemicalReactorRecipeWrapper) {
ChemicalReactorRecipeWrapper recipe = (ChemicalReactorRecipeWrapper) recipeWrapper; ChemicalReactorRecipeWrapper recipe = (ChemicalReactorRecipeWrapper) recipeWrapper;
List<ItemStack> inputs = recipe.getInputs(); List<List<ItemStack>> inputs = recipe.getInputs();
guiItemStacks.set(INPUT_SLOT_0, inputs.get(0)); guiItemStacks.set(INPUT_SLOT_0, inputs.get(0));
if (inputs.size() > 1) { if (inputs.size() > 1) {
guiItemStacks.set(INPUT_SLOT_1, inputs.get(1)); guiItemStacks.set(INPUT_SLOT_1, inputs.get(1));

View file

@ -82,11 +82,10 @@ public class GrinderRecipeCategory implements IRecipeCategory {
if (recipeWrapper instanceof GrinderRecipeWrapper) { if (recipeWrapper instanceof GrinderRecipeWrapper) {
GrinderRecipeWrapper recipe = (GrinderRecipeWrapper) recipeWrapper; GrinderRecipeWrapper recipe = (GrinderRecipeWrapper) recipeWrapper;
List<ItemStack> inputs = recipe.getInputs(); List<List<ItemStack>> inputs = recipe.getInputs();
for (int i = 0; i < inputs.size() && i < INPUT_SLOTS.length; i++) { for (int i = 0; i < inputs.size() && i < INPUT_SLOTS.length; i++) {
int inputSlot = INPUT_SLOTS[i]; int inputSlot = INPUT_SLOTS[i];
ItemStack input = inputs.get(i); guiItemStacks.set(inputSlot, inputs.get(i));
guiItemStacks.set(inputSlot, input);
} }
List<ItemStack> outputs = recipe.getOutputs(); List<ItemStack> outputs = recipe.getOutputs();

View file

@ -74,7 +74,7 @@ public class ImplosionCompressorRecipeCategory implements IRecipeCategory {
if (recipeWrapper instanceof ImplosionCompressorRecipeWrapper) { if (recipeWrapper instanceof ImplosionCompressorRecipeWrapper) {
ImplosionCompressorRecipeWrapper recipe = (ImplosionCompressorRecipeWrapper) recipeWrapper; ImplosionCompressorRecipeWrapper recipe = (ImplosionCompressorRecipeWrapper) recipeWrapper;
List<ItemStack> inputs = recipe.getInputs(); List<List<ItemStack>> inputs = recipe.getInputs();
guiItemStacks.set(INPUT_SLOT_0, inputs.get(0)); guiItemStacks.set(INPUT_SLOT_0, inputs.get(0));
if (inputs.size() > 1) { if (inputs.size() > 1) {
guiItemStacks.set(INPUT_SLOT_1, inputs.get(1)); guiItemStacks.set(INPUT_SLOT_1, inputs.get(1));