TechReborn/src/main/java/techreborn/compat/jei/BaseRecipeWrapper.java

69 lines
1.7 KiB
Java
Raw Normal View History

2016-03-13 17:08:30 +01:00
package techreborn.compat.jei;
import mezz.jei.api.recipe.BlankRecipeWrapper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import techreborn.api.recipe.BaseRecipe;
import javax.annotation.Nonnull;
2016-03-13 17:08:30 +01:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public abstract class BaseRecipeWrapper<T extends BaseRecipe> extends BlankRecipeWrapper {
2016-03-13 17:08:30 +01:00
protected final T baseRecipe;
@Nonnull
private final List<List<ItemStack>> inputs;
public BaseRecipeWrapper(T baseRecipe) {
2016-03-13 17:08:30 +01:00
this.baseRecipe = baseRecipe;
inputs = new ArrayList<>();
for (ItemStack input : baseRecipe.getInputs()) {
if (baseRecipe.useOreDic()) {
2016-03-13 17:08:30 +01:00
List<ItemStack> oreDictInputs = expandOreDict(input);
inputs.add(oreDictInputs);
} else {
2016-03-13 17:08:30 +01:00
inputs.add(Collections.singletonList(input));
}
}
}
private static List<ItemStack> expandOreDict(ItemStack itemStack) {
2016-03-13 17:08:30 +01:00
int[] oreIds = OreDictionary.getOreIDs(itemStack);
if (oreIds.length == 0) {
2016-03-13 17:08:30 +01:00
return Collections.singletonList(itemStack);
}
Set<ItemStack> itemStackSet = new HashSet<>();
for (int oreId : oreIds) {
2016-03-13 17:08:30 +01:00
String oreName = OreDictionary.getOreName(oreId);
List<ItemStack> ores = OreDictionary.getOres(oreName);
for (ItemStack ore : ores) {
if (ore.stackSize != itemStack.stackSize) {
2016-03-13 17:08:30 +01:00
ItemStack oreCopy = ore.copy();
oreCopy.stackSize = itemStack.stackSize;
itemStackSet.add(oreCopy);
} else {
2016-03-13 17:08:30 +01:00
itemStackSet.add(ore);
}
}
}
return new ArrayList<>(itemStackSet);
}
@Nonnull
@Override
public List<List<ItemStack>> getInputs() {
2016-03-13 17:08:30 +01:00
return inputs;
}
@Nonnull
@Override
public List<ItemStack> getOutputs() {
2016-03-13 17:08:30 +01:00
return baseRecipe.getOutputs();
}
}