From f07b0c014d8dff5ecd3e789feda34ec656966a9a Mon Sep 17 00:00:00 2001 From: Zixxl Date: Fri, 12 Jun 2015 10:22:06 +0200 Subject: [PATCH] Some more tweaks - Code cleanup - Added ability to remove recipes for a liquid --- .../mods/tconstruct/handlers/Casting.java | 136 ++++++++---------- 1 file changed, 58 insertions(+), 78 deletions(-) diff --git a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java index 3d12944..5b3e479 100644 --- a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java +++ b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java @@ -15,6 +15,7 @@ import modtweaker2.mods.tconstruct.TConstructHelper; import modtweaker2.utils.BaseListAddition; import modtweaker2.utils.BaseListRemoval; import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; @@ -50,55 +51,44 @@ public class Casting { //Removing a TConstruct Casting recipe @ZenMethod public static void removeBasinRecipe(IItemStack output) { - MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.basinCasting)); + MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.basinCasting, RecipeComponent.Output)); } @ZenMethod public static void removeTableRecipe(IItemStack output) { - MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.tableCasting)); + MineTweakerAPI.apply(new Remove((toStack(output)), TConstructHelper.tableCasting, RecipeComponent.Output)); } @ZenMethod - public static void removeTableRecipes(IItemStack output) { - MineTweakerAPI.apply(new RemoveAll((toStack(output)), TConstructHelper.tableCasting)); + public static void removeBasinLiquid(ILiquidStack fluid) { + MineTweakerAPI.apply(new Remove((toFluid(fluid)), TConstructHelper.basinCasting)); } - //Removes a recipe, apply is never the same for anything, so will always need to override it - private static class Remove extends BaseListRemoval { - public Remove(ItemStack output, ArrayList list) { - super("TConstruct Casting", list, output); - } - - //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); - } - } - - @Override - public String getRecipeInfo() { - return stack.getDisplayName(); - } + @ZenMethod + public static void removeTableLiquid(ILiquidStack fluid) { + MineTweakerAPI.apply(new Remove((toFluid(fluid)), TConstructHelper.tableCasting)); } - + + @ZenMethod + public static void removeCastRecipes(IItemStack cast) { + MineTweakerAPI.apply(new Remove((toStack(cast)), TConstructHelper.tableCasting, RecipeComponent.Cast)); + } + // Removes all matching recipes, apply is never the same for anything, so will always need to override it - private static class RemoveAll extends BaseListRemoval { + private static class Remove extends BaseListRemoval { protected final LinkedList removedRecipes; + protected final RecipeComponent component; - public RemoveAll(ItemStack output, ArrayList list) { + public Remove(ItemStack output, ArrayList list, RecipeComponent component) { super("TConstruct Casting", list, output); - removedRecipes = new LinkedList(); + this.removedRecipes = new LinkedList(); + this.component = component; + } + + public Remove(FluidStack output, ArrayList list) { + super("TConstruct Casting", list, output); + this.removedRecipes = new LinkedList(); + this.component = RecipeComponent.Material; } // Loops through the registry, to find all items that matches, then removes them @@ -106,9 +96,35 @@ public class Casting { 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); + boolean removeRecipie = false; + + switch(component) + { + case Cast: + if (r.cast != null && areEqual(r.cast, stack)) { + removeRecipie = true; + } + + break; + + case Material: + if (r.castingMetal != null && r.castingMetal.isFluidEqual(fluid)) { + removeRecipie = true; + } + + break; + + case Output: + if (r.output != null && areEqual(r.output, stack)) { + removeRecipie = true; + } + + break; + } + + if(removeRecipie) { + iterator.remove(); + removedRecipes.add(r); } } } @@ -126,46 +142,10 @@ 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(); - } + public enum RecipeComponent { + Output, + Cast, + Material } }