package modtweaker2.mods.extraUtils.handlers;

import java.util.LinkedList;

import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;

import com.rwtema.extrautils.tileentity.enderconstructor.EnderConstructorRecipesHandler;

@ZenClass("mods.extraUtils.QED")
public class QED {

	@ZenMethod
	public static void addShapedRecipe(IItemStack output, IItemStack[][] recipe) {
		MineTweakerAPI.apply(new Add(new ShapedOreRecipe(InputHelper.toStack(output), InputHelper.toShapedObjects(recipe))));
	}
	
	private static class Add extends BaseListAddition<IRecipe> {

		public Add(IRecipe recipe) {
			super("QED", EnderConstructorRecipesHandler.recipes);
			recipes.add(recipe);
		}

		@Override
		protected String getRecipeInfo(IRecipe recipe) {
			return recipe.toString();
		}

	}

	@ZenMethod
	public static void removeRecipe(IItemStack toRemove) {
		if (toRemove == null) {
			LogHelper.logError(String.format("Required parameters missing for %s Recipe.", "QED"));
			return;
		}
		LinkedList<IRecipe> recipes = new LinkedList<IRecipe>();

		for (IRecipe recipe : EnderConstructorRecipesHandler.recipes) {
			if (recipe != null && recipe.getRecipeOutput() != null && recipe.getRecipeOutput().isItemEqual(InputHelper.toStack(toRemove))) {
				recipes.add(recipe);
			}
		}

		MineTweakerAPI.apply(new Remove(recipes));

	}

	public static class Remove extends BaseListRemoval<IRecipe> {

		protected Remove(LinkedList<IRecipe> stacks) {
			super("QED", EnderConstructorRecipesHandler.recipes, stacks);

		}

		@Override
		protected String getRecipeInfo(IRecipe recipe) {
			return recipe.toString();
		}

	}

}

@@ -105,16 +105,57 @@
 kerAPI;%0A
+import minetweaker.api.item.IIngredient;%0A
 import m
@@ -448,62 +448,8 @@
 pe;%0A
-import net.minecraftforge.oredict.ShapelessOreRecipe;%0A
 impo
@@ -640,59 +640,236 @@
 r;%0A%0A
-@ZenClass(%22mods.extraUtils.QED%22)%0Apublic class QED %7B
+import static modtweaker2.helpers.InputHelper.toIItemStack;%0Aimport static modtweaker2.helpers.StackHelper.matches;%0A%0A@ZenClass(%22mods.extraUtils.QED%22)%0Apublic class QED %7B%0A%0A%09public static final String name = %22ExtraUtilities Q.E.D.%22;
 %0A%0A%09@
@@ -935,24 +935,25 @@
 tput, II
-temStack
+ngredient
 %5B%5D%5B%5D rec
@@ -1356,25 +1356,24 @@
 ring();%0A%09%09%7D%0A
-%0A
 %09%7D%0A%0A%09@ZenMet
@@ -1415,160 +1415,27 @@
 e(II
-temStack toRemove) %7B%0A%09%09if (toRemove == null) %7B%0A%09%09%09LogHelper.logError(String.format(%22Required parameters missing for %25s Recipe.%22, %22QED%22));%0A%09%09%09return;%0A%09%09%7D
+ngredient output) %7B
 %0A%09%09L
@@ -1622,73 +1622,61 @@
  && 
-recipe.getRecipeOutput().isItemEqual(InputHelper.toStack(toRemove
+matches(output, toIItemStack(recipe.getRecipeOutput()
 ))) 
@@ -1712,16 +1712,44 @@
 %09%7D%0A%09%09%7D%0A%0A
+%09%09if(!recipes.isEmpty()) %7B%0A%09
 %09%09MineTw
@@ -1785,16 +1785,166 @@
 ipes));%0A
+%09%09%7D else %7B%0A%09%09%09LogHelper.logWarning(String.format(%22No %25s Recipe found for %25s. Command ignored!%22, QED.name, LogHelper.getStackDescription(output)));%0A%09%09%7D
 %0A%09%7D%0A%0A%09pu
@@ -2118,17 +2118,16 @@
 tacks);%0A
-%0A
 %09%09%7D%0A%0A%09%09@
@@ -2219,15 +2219,14 @@
 ();%0A%09%09%7D%0A
-%0A
 %09%7D%0A%0A%7D%0A

fix #242 and #245 : ExtraUtilities Q.E.D. - OreDict Support and removeRecipe(<*>)