From 4b37bbc7b8087f707be844aa1da71fcec0f82dd9 Mon Sep 17 00:00:00 2001 From: Zixxl Date: Wed, 10 Jun 2015 17:56:55 +0200 Subject: [PATCH] Tweaks for TinkersConstruct casting - Fixed: Script crash if recipe is not present (maybe fixes issue #144) - Added: Support to remove all recipies --- .../mods/tconstruct/handlers/Casting.java | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java index c21b2e5..ff5c52d 100644 --- a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java +++ b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java @@ -5,6 +5,8 @@ import static modtweaker2.helpers.InputHelper.toStack; import static modtweaker2.helpers.StackHelper.areEqual; import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Iterator; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; @@ -50,11 +52,21 @@ public class Casting { public static void removeBasinRecipe(IItemStack output) { MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.basinCasting)); } + + @ZenMethod + public static void removeBasinRecipes(IItemStack output) { + MineTweakerAPI.apply(new RemoveAll((toStack(output)), TConstructHelper.basinCasting)); + } @ZenMethod public static void removeTableRecipe(IItemStack output) { MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.tableCasting)); } + + @ZenMethod + public static void removeTableRecipes(IItemStack output) { + MineTweakerAPI.apply(new RemoveAll((toStack(output)), TConstructHelper.tableCasting)); + } //Removes a recipe, apply is never the same for anything, so will always need to override it private static class Remove extends BaseListRemoval { @@ -65,14 +77,53 @@ public class Casting { //Loops through the registry, to find the item that matches, saves that recipe then removes it @Override public void apply() { + recipe = null; + for (CastingRecipe r : (ArrayList) list) { if (r.output != null && areEqual(r.output, stack)) { recipe = r; break; } } + + if (recipe != null) { + list.remove(recipe); + } + } - list.remove(recipe); + @Override + public String getRecipeInfo() { + return stack.getDisplayName(); + } + } + + // Removes all matching recipes, apply is never the same for anything, so will always need to override it + private static class RemoveAll extends BaseListRemoval { + protected final LinkedList removedRecipes; + + public RemoveAll(ItemStack output, ArrayList list) { + super("TConstruct Casting", list, output); + removedRecipes = new LinkedList(); + } + + // Loops through the registry, to find all items that matches, then removes them + @Override + public void apply() { + for (Iterator iterator = ((ArrayList)list).iterator(); iterator.hasNext();) { + CastingRecipe r = iterator.next(); + if (r.output != null && areEqual(r.output, stack)) { + iterator.remove(); + removedRecipes.add(r); + } + } + } + + @Override + public void undo() { + for(CastingRecipe recipe : removedRecipes) { + this.list.add(recipe); + } + removedRecipes.clear(); } @Override