2015-12-31 06:17:20 +01:00
|
|
|
package techreborn.compat.jei;
|
|
|
|
|
2016-02-18 08:44:15 +01:00
|
|
|
import mezz.jei.api.recipe.BlankRecipeWrapper;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
import techreborn.api.recipe.BaseRecipe;
|
|
|
|
|
2015-12-31 06:17:20 +01:00
|
|
|
import javax.annotation.Nonnull;
|
2016-02-24 09:18:21 +01:00
|
|
|
import java.util.*;
|
2015-12-31 06:17:20 +01:00
|
|
|
|
2015-12-31 09:56:09 +01:00
|
|
|
public abstract class BaseRecipeWrapper<T extends BaseRecipe> extends BlankRecipeWrapper {
|
|
|
|
protected final T baseRecipe;
|
2016-02-18 08:44:15 +01:00
|
|
|
@Nonnull
|
2015-12-31 10:19:06 +01:00
|
|
|
private final List<List<ItemStack>> inputs;
|
2015-12-31 06:17:20 +01:00
|
|
|
|
2015-12-31 09:56:09 +01:00
|
|
|
public BaseRecipeWrapper(T baseRecipe) {
|
2015-12-31 06:17:20 +01:00
|
|
|
this.baseRecipe = baseRecipe;
|
2015-12-31 10:19:06 +01:00
|
|
|
|
|
|
|
inputs = new ArrayList<>();
|
|
|
|
for (ItemStack input : baseRecipe.getInputs()) {
|
|
|
|
if (baseRecipe.useOreDic()) {
|
2016-01-06 09:46:15 +01:00
|
|
|
List<ItemStack> oreDictInputs = expandOreDict(input);
|
|
|
|
inputs.add(oreDictInputs);
|
2015-12-31 10:19:06 +01:00
|
|
|
} else {
|
|
|
|
inputs.add(Collections.singletonList(input));
|
|
|
|
}
|
|
|
|
}
|
2015-12-31 06:17:20 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 09:46:15 +01:00
|
|
|
private static List<ItemStack> expandOreDict(ItemStack itemStack) {
|
|
|
|
int[] oreIds = OreDictionary.getOreIDs(itemStack);
|
|
|
|
if (oreIds.length == 0) {
|
|
|
|
return Collections.singletonList(itemStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<ItemStack> itemStackSet = new HashSet<>();
|
|
|
|
for (int oreId : oreIds) {
|
|
|
|
String oreName = OreDictionary.getOreName(oreId);
|
|
|
|
List<ItemStack> ores = OreDictionary.getOres(oreName);
|
|
|
|
itemStackSet.addAll(ores);
|
|
|
|
}
|
|
|
|
return new ArrayList<>(itemStackSet);
|
|
|
|
}
|
|
|
|
|
2016-02-18 08:44:15 +01:00
|
|
|
@Nonnull
|
2015-12-31 06:17:20 +01:00
|
|
|
@Override
|
2015-12-31 10:19:06 +01:00
|
|
|
public List<List<ItemStack>> getInputs() {
|
|
|
|
return inputs;
|
2015-12-31 06:17:20 +01:00
|
|
|
}
|
|
|
|
|
2016-02-18 08:44:15 +01:00
|
|
|
@Nonnull
|
2015-12-31 06:17:20 +01:00
|
|
|
@Override
|
|
|
|
public List<ItemStack> getOutputs() {
|
|
|
|
return baseRecipe.getOutputs();
|
|
|
|
}
|
|
|
|
}
|