/* * This file ("RecipeUtil.java") is part of the Actually Additions mod for Minecraft. * It is created and owned by Ellpeck and distributed * under the Actually Additions License to be found at * http://ellpeck.de/actaddlicense * View the source code at https://github.com/Ellpeck/ActuallyAdditions * * © 2015-2016 Ellpeck */ package de.ellpeck.actuallyadditions.mod.util; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.lens.LensConversion; import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe; import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe; import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; import java.util.Collections; import java.util.List; public final class RecipeUtil{ public static LensConversionRecipe lastReconstructorRecipe(){ List list = ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES; return list.get(list.size()-1); } public static CrusherRecipe lastCrusherRecipe(){ List list = ActuallyAdditionsAPI.CRUSHER_RECIPES; return list.get(list.size()-1); } public static IRecipe lastIRecipe(){ List list = CraftingManager.getInstance().getRecipeList(); Object recipe = list.get(list.size()-1); return recipe instanceof IRecipe ? (IRecipe)recipe : null; } public static List getCrusherRecipeOutputOnes(CrusherRecipe recipe){ return doRecipeOrWhatever(recipe.outputOneStack, recipe.outputOne, recipe.outputOneAmount); } public static List getCrusherRecipeOutputTwos(CrusherRecipe recipe){ return doRecipeOrWhatever(recipe.outputTwoStack, recipe.outputTwo, recipe.outputTwoAmount); } public static List getCrusherRecipeInputs(CrusherRecipe recipe){ return doRecipeOrWhatever(recipe.inputStack, recipe.input, 1); } public static List getConversionLensInputs(LensConversionRecipe recipe){ return doRecipeOrWhatever(recipe.inputStack, recipe.input, 1); } public static List getConversionLensOutputs(LensConversionRecipe recipe){ return doRecipeOrWhatever(recipe.outputStack, recipe.output, 1); } private static List doRecipeOrWhatever(ItemStack stack, String oredict, int amount){ if(stack != null){ return Collections.singletonList(stack.copy()); } if(oredict == null || oredict.isEmpty()){ return null; } List stacks = OreDictionary.getOres(oredict, false); if(stacks != null && !stacks.isEmpty()){ List stacksCopy = new ArrayList(); for(ItemStack aStack : stacks){ if(aStack != null){ ItemStack stackCopy = aStack.copy(); stackCopy.stackSize = amount; stacksCopy.add(stackCopy); } } return stacksCopy; } return null; } }