2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 TechReborn
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-03-13 17:08:30 +01:00
|
|
|
package techreborn.compat.jei;
|
|
|
|
|
2016-09-27 18:03:57 +02:00
|
|
|
import mezz.jei.api.ingredients.IIngredients;
|
2016-03-25 10:47:34 +01:00
|
|
|
import mezz.jei.api.recipe.BlankRecipeWrapper;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-11-28 16:28:32 +01:00
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2016-03-25 10:47:34 +01:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
import techreborn.api.recipe.BaseRecipe;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
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;
|
2016-11-28 16:28:32 +01:00
|
|
|
@Nonnull
|
|
|
|
private final List<List<ItemStack>> outputs;
|
2016-03-13 17:08:30 +01:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public BaseRecipeWrapper(T baseRecipe) {
|
2016-03-13 17:08:30 +01:00
|
|
|
this.baseRecipe = baseRecipe;
|
|
|
|
|
|
|
|
inputs = new ArrayList<>();
|
2016-11-28 16:28:32 +01:00
|
|
|
outputs = new ArrayList<>();
|
2017-01-08 22:43:15 +01:00
|
|
|
for (Object input : baseRecipe.getInputs()) {
|
|
|
|
if(input instanceof ItemStack){
|
|
|
|
ItemStack stack = (ItemStack) input;
|
|
|
|
if (baseRecipe.useOreDic()) {
|
|
|
|
List<ItemStack> oreDictInputs = expandOreDict(stack);
|
|
|
|
inputs.add(oreDictInputs);
|
|
|
|
} else {
|
|
|
|
inputs.add(Collections.singletonList(stack));
|
|
|
|
}
|
|
|
|
} else if (input instanceof String){
|
|
|
|
inputs.add(OreDictionary.getOres((String) input));
|
2016-03-13 17:08:30 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-28 16:28:32 +01:00
|
|
|
for (ItemStack input : baseRecipe.getOutputs()) {
|
|
|
|
if (baseRecipe.useOreDic()) {
|
|
|
|
List<ItemStack> oreDictInputs = expandOreDict(input);
|
|
|
|
outputs.add(oreDictInputs);
|
|
|
|
} else {
|
|
|
|
outputs.add(Collections.singletonList(input));
|
|
|
|
}
|
|
|
|
}
|
2016-03-13 17:08:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
private static List<ItemStack> expandOreDict(ItemStack itemStack) {
|
2016-03-13 17:08:30 +01:00
|
|
|
int[] oreIds = OreDictionary.getOreIDs(itemStack);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (oreIds.length == 0) {
|
2016-03-13 17:08:30 +01:00
|
|
|
return Collections.singletonList(itemStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<ItemStack> itemStackSet = new HashSet<>();
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int oreId : oreIds) {
|
2016-03-13 17:08:30 +01:00
|
|
|
String oreName = OreDictionary.getOreName(oreId);
|
|
|
|
List<ItemStack> ores = OreDictionary.getOres(oreName);
|
2016-10-08 21:46:16 +02:00
|
|
|
for (ItemStack ore : ores) {
|
2016-11-28 16:28:32 +01:00
|
|
|
if (ore.getCount() != itemStack.getCount()) {
|
2016-03-13 17:08:30 +01:00
|
|
|
ItemStack oreCopy = ore.copy();
|
2016-11-28 16:28:32 +01:00
|
|
|
oreCopy.setCount(itemStack.getCount());
|
2016-03-13 17:08:30 +01:00
|
|
|
itemStackSet.add(oreCopy);
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-13 17:08:30 +01:00
|
|
|
itemStackSet.add(ore);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new ArrayList<>(itemStackSet);
|
|
|
|
}
|
|
|
|
|
2016-09-27 18:03:57 +02:00
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void getIngredients(
|
|
|
|
@Nonnull
|
|
|
|
IIngredients ingredients) {
|
2016-09-27 18:03:57 +02:00
|
|
|
ingredients.setInputLists(ItemStack.class, inputs);
|
|
|
|
ingredients.setOutputs(ItemStack.class, baseRecipe.getOutputs());
|
|
|
|
}
|
|
|
|
|
2016-03-13 17:08:30 +01:00
|
|
|
@Nonnull
|
2016-10-08 21:46:16 +02:00
|
|
|
public List<List<ItemStack>> getInputs() {
|
2016-03-13 17:08:30 +01:00
|
|
|
return inputs;
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:48:21 +01:00
|
|
|
public List<FluidStack> getFluidInputs() {
|
2016-11-28 16:28:32 +01:00
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
|
|
|
|
2016-03-13 17:08:30 +01:00
|
|
|
@Nonnull
|
2016-10-08 21:46:16 +02:00
|
|
|
public List<ItemStack> getOutputs() {
|
2016-11-28 16:28:32 +01:00
|
|
|
List<ItemStack> stacks = new ArrayList<>();
|
2016-12-05 11:48:21 +01:00
|
|
|
for (List<ItemStack> stackList : outputs) {
|
2016-11-28 16:28:32 +01:00
|
|
|
stacks.addAll(stackList);
|
|
|
|
}
|
|
|
|
return stacks;
|
2016-03-13 17:08:30 +01:00
|
|
|
}
|
|
|
|
}
|