From e63d34d5f56afc557423cf24a30a47d477e8d80b Mon Sep 17 00:00:00 2001 From: Zixxl Date: Wed, 10 Jun 2015 18:03:50 +0200 Subject: [PATCH] Remove all the recipies for a casting --- .../mods/tconstruct/handlers/Casting.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java index ff5c52d..4eba1f9 100644 --- a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java +++ b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java @@ -131,4 +131,46 @@ public class Casting { return stack.getDisplayName(); } } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + // Removing TConstruct recipes for a cast + @ZenMethod + public static void removeCastRecipes(IItemStack cast) { + MineTweakerAPI.apply(new RemoveCastRecipies((toStack(cast)), TConstructHelper.tableCasting)); + } + + private static class RemoveCastRecipies extends BaseListRemoval { + protected final LinkedList removedRecipes; + + public RemoveCastRecipies(ItemStack cast, ArrayList list) { + super("TConstruct Casting", list, cast); + removedRecipes = new LinkedList(); + } + + // Loops through the registry, to find all recipies for a cast, then removes them + @Override + public void apply() { + for (Iterator iterator = ((ArrayList)list).iterator(); iterator.hasNext();) { + CastingRecipe r = iterator.next(); + if (r.cast != null && areEqual(r.cast, stack)) { + iterator.remove(); + removedRecipes.add(r); + } + } + } + + @Override + public void undo() { + for(CastingRecipe recipe : removedRecipes) { + this.list.add(recipe); + } + removedRecipes.clear(); + } + + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } }