From 4b37bbc7b8087f707be844aa1da71fcec0f82dd9 Mon Sep 17 00:00:00 2001 From: Zixxl Date: Wed, 10 Jun 2015 17:56:55 +0200 Subject: [PATCH 1/6] 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 From e63d34d5f56afc557423cf24a30a47d477e8d80b Mon Sep 17 00:00:00 2001 From: Zixxl Date: Wed, 10 Jun 2015 18:03:50 +0200 Subject: [PATCH 2/6] 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(); + } + } } From 25da86db52173c7726e613d83e1f035fbed4528c Mon Sep 17 00:00:00 2001 From: Zixxl Date: Wed, 10 Jun 2015 18:06:19 +0200 Subject: [PATCH 3/6] Don't think we need removeTableRecipes --- .../java/modtweaker2/mods/tconstruct/handlers/Casting.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java index 4eba1f9..3d12944 100644 --- a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java +++ b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java @@ -52,11 +52,6 @@ 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) { From f07b0c014d8dff5ecd3e789feda34ec656966a9a Mon Sep 17 00:00:00 2001 From: Zixxl Date: Fri, 12 Jun 2015 10:22:06 +0200 Subject: [PATCH 4/6] 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 } } From be54331b31b7ca5265444af3180d00615e7b2d5e Mon Sep 17 00:00:00 2001 From: Zixxl Date: Fri, 12 Jun 2015 10:31:50 +0200 Subject: [PATCH 5/6] Bugfix - Fixed: getRecipeInfo fails for fluids - More code cleanup for Pull-Request --- .../mods/tconstruct/handlers/Casting.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java index 5b3e479..6a55d44 100644 --- a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java +++ b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java @@ -79,16 +79,16 @@ public class Casting { protected final LinkedList removedRecipes; protected final RecipeComponent component; - public Remove(ItemStack output, ArrayList list, RecipeComponent component) { - super("TConstruct Casting", list, output); + public Remove(ItemStack item, ArrayList list, RecipeComponent component) { + super("TConstruct Casting", list, item); 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; + public Remove(FluidStack fluid, ArrayList list) { + super("TConstruct Casting", list, fluid); + this.removedRecipes = new LinkedList(); + this.component = RecipeComponent.Material; } // Loops through the registry, to find all items that matches, then removes them @@ -100,31 +100,31 @@ public class Casting { switch(component) { - case Cast: - if (r.cast != null && areEqual(r.cast, stack)) { - removeRecipie = true; + case Cast: + if (r.cast != null && areEqual(r.cast, stack)) { + removeRecipie = true; } - break; - - case Material: + break; + + case Material: if (r.castingMetal != null && r.castingMetal.isFluidEqual(fluid)) { - removeRecipie = true; + removeRecipie = true; } - break; - - case Output: - if (r.output != null && areEqual(r.output, stack)) { - removeRecipie = true; + break; + + case Output: + if (r.output != null && areEqual(r.output, stack)) { + removeRecipie = true; } - break; + break; } if(removeRecipie) { - iterator.remove(); - removedRecipes.add(r); + iterator.remove(); + removedRecipes.add(r); } } } @@ -139,13 +139,16 @@ public class Casting { @Override public String getRecipeInfo() { - return stack.getDisplayName(); + if(component == RecipeComponent.Material) + return fluid.getLocalizedName(); + else + return stack.getDisplayName(); } } public enum RecipeComponent { - Output, - Cast, - Material + Output, + Cast, + Material } } From 8efaa6c92c2d5eabd407c2971ae87b14854e3b0d Mon Sep 17 00:00:00 2001 From: Zixxl Date: Fri, 12 Jun 2015 10:38:29 +0200 Subject: [PATCH 6/6] Some renaming --- .../java/modtweaker2/mods/tconstruct/handlers/Casting.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java index 6a55d44..ac76d7f 100644 --- a/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java +++ b/src/main/java/modtweaker2/mods/tconstruct/handlers/Casting.java @@ -60,12 +60,12 @@ public class Casting { } @ZenMethod - public static void removeBasinLiquid(ILiquidStack fluid) { + public static void removeBasinMaterial(ILiquidStack fluid) { MineTweakerAPI.apply(new Remove((toFluid(fluid)), TConstructHelper.basinCasting)); } @ZenMethod - public static void removeTableLiquid(ILiquidStack fluid) { + public static void removeTableMaterial(ILiquidStack fluid) { MineTweakerAPI.apply(new Remove((toFluid(fluid)), TConstructHelper.tableCasting)); }