package techreborn.api.recipe;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;


public class RecipeHanderer {

	/**
	 * This is the array list of all of the recipes for all of the machines
	 */
	public static ArrayList<IBaseRecipeType> recipeList = new ArrayList<IBaseRecipeType>();

	/**
	 * This is a backedup clone of the master recipeList
	 */
	public static ArrayList<IBaseRecipeType> recipeListBackup = new ArrayList<IBaseRecipeType>();

	/**
	 * Use this to get all of the recipes form a recipe name
	 * @param name the name that the recipe was resisted as.
	 * @return A list of all the recipes of a given name.
	 */
	public static List<IBaseRecipeType> getRecipeClassFromName(String name){
		List<IBaseRecipeType> baseRecipeList = new ArrayList<IBaseRecipeType>();
		for(IBaseRecipeType baseRecipe : recipeList){
			if(baseRecipe.getRecipeName().equals(name)){
				baseRecipeList.add(baseRecipe);
			}
		}
		return baseRecipeList;
	}

	/**
	 * Add a recipe to the system
	 * @param recipe The recipe to add to the system.
	 */
	public static void addRecipe(IBaseRecipeType recipe){
		if(recipe == null){
			return;
		}
		if(recipeList.contains(recipe)){
			return;
		}
		recipeList.add(recipe);
	}


	public static void addOreDicRecipes(){
		recipeListBackup.clear();
		recipeListBackup.addAll(recipeList);
		ArrayList<IBaseRecipeType> newRecipes = new ArrayList<IBaseRecipeType>();
		for(IBaseRecipeType baseRecipe : recipeList){
			if(baseRecipe instanceof BaseRecipe){
				for (int i = 0; i < baseRecipe.getInputs().size(); i++) {
					BaseRecipe newRecipe = (BaseRecipe) baseRecipe;
					for(int oreId : OreDictionary.getOreIDs(((BaseRecipe) baseRecipe).inputs.get(i))){
						for(ItemStack itemStack : getInputs(OreDictionary.getOreName(oreId))){
							System.out.println(itemStack.getDisplayName());
							newRecipe.inputs.set(i, itemStack);
						}
					}
					newRecipes.add(newRecipe);
				}
				for (int i = 0; i < baseRecipe.getOutputs().size(); i++) {
					BaseRecipe newRecipe = (BaseRecipe) baseRecipe;
					for(int oreId : OreDictionary.getOreIDs(((BaseRecipe) baseRecipe).outputs.get(i))){
						for(ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreName(oreId))){
							newRecipe.outputs.set(i, itemStack);
						}
					}
					newRecipes.add(newRecipe);
				}

			}
		}
		recipeList.addAll(newRecipes);
	}

	public static List<ItemStack> getInputs(String name) {
		List ores = getOres(name);
		boolean hasInvalidEntries = false;
		Iterator ret = ores.iterator();

		while(ret.hasNext()) {
			ItemStack i$ = (ItemStack)ret.next();
			if(i$.getItem() == null) {
				hasInvalidEntries = true;
				break;
			}
		}

		if(!hasInvalidEntries) {
			return ores;
		} else {
			ArrayList ret1 = new ArrayList(ores.size());
			Iterator i$1 = ores.iterator();

			while(i$1.hasNext()) {
				ItemStack stack = (ItemStack)i$1.next();
				if(stack.getItem() != null) {
					ret1.add(stack);
				}
			}

			return Collections.unmodifiableList(ret1);
		}
	}

	private static List<ItemStack> getOres(String name) {
		ArrayList ret = OreDictionary.getOres(name);
		return ret;
	}

}
@@ -1496,1792 +1496,68 @@
 ;%0A%09%09
-ArrayList%3CIBaseRecipeType%3E newRecipes = new ArrayList%3CIBaseRecipeType%3E();%0A%09%09for(IBaseRecipeType baseRecipe : recipeList)%7B%0A%09%09%09if(baseRecipe instanceof BaseRecipe)%7B%0A%09%09%09%09for (int i = 0; i %3C baseRecipe.getInputs().size(); i++) %7B%0A%09%09%09%09%09BaseRecipe newRecipe = (BaseRecipe) baseRecipe;%0A%09%09%09%09%09for(int oreId : OreDictionary.getOreIDs(((BaseRecipe) baseRecipe).inputs.get(i)))%7B%0A%09%09%09%09%09%09for(ItemStack itemStack : getInputs(OreDictionary.getOreName(oreId)))%7B%0A%09%09%09%09%09%09%09System.out.println(itemStack.getDisplayName());%0A%09%09%09%09%09%09%09newRecipe.inputs.set(i, itemStack);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%09newRecipes.add(newRecipe);%0A%09%09%09%09%7D%0A%09%09%09%09for (int i = 0; i %3C baseRecipe.getOutputs().size(); i++) %7B%0A%09%09%09%09%09BaseRecipe newRecipe = (BaseRecipe) baseRecipe;%0A%09%09%09%09%09for(int oreId : OreDictionary.getOreIDs(((BaseRecipe) baseRecipe).outputs.get(i)))%7B%0A%09%09%09%09%09%09for(ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreName(oreId)))%7B%0A%09%09%09%09%09%09%09newRecipe.outputs.set(i, itemStack);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%09newRecipes.add(newRecipe);%0A%09%09%09%09%7D%0A%0A%09%09%09%7D%0A%09%09%7D%0A%09%09recipeList.addAll(newRecipes);%0A%09%7D%0A%0A%09public static List%3CItemStack%3E getInputs(String name) %7B%0A%09%09List ores = getOres(name);%0A%09%09boolean hasInvalidEntries = false;%0A%09%09Iterator ret = ores.iterator();%0A%0A%09%09while(ret.hasNext()) %7B%0A%09%09%09ItemStack i$ = (ItemStack)ret.next();%0A%09%09%09if(i$.getItem() == null) %7B%0A%09%09%09%09hasInvalidEntries = true;%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09if(!hasInvalidEntries) %7B%0A%09%09%09return ores;%0A%09%09%7D else %7B%0A%09%09%09ArrayList ret1 = new ArrayList(ores.size());%0A%09%09%09Iterator i$1 = ores.iterator();%0A%0A%09%09%09while(i$1.hasNext()) %7B%0A%09%09%09%09ItemStack stack = (ItemStack)i$1.next();%0A%09%09%09%09if(stack.getItem() != null) %7B%0A%09%09%09%09%09ret1.add(stack);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%0A%09%09%09return Collections.unmodifiableList(ret1);%0A%09%09%7D%0A%09%7D%0A%0A%09private static List%3CItemStack%3E getOres(String name) %7B%0A%09%09ArrayList ret = OreDictionary.getOres(name);%0A%09%09return ret;%0A%09%7D
+//TODO add all of the recipes with all the different ores%0A%09%7D%0A
 %0A%0A%7D

Clean up of testing code