diff --git a/src/main/java/modtweaker/mods/embers/handlers/Melter.java b/src/main/java/modtweaker/mods/embers/handlers/Melter.java index 8f5ff98..7d3041b 100644 --- a/src/main/java/modtweaker/mods/embers/handlers/Melter.java +++ b/src/main/java/modtweaker/mods/embers/handlers/Melter.java @@ -1,143 +1,183 @@ package modtweaker.mods.embers.handlers; import com.blamejared.mtlib.helpers.LogHelper; -import com.blamejared.mtlib.helpers.StackHelper; -import com.blamejared.mtlib.utils.BaseListAddition; -import com.blamejared.mtlib.utils.BaseListRemoval; -import com.blamejared.mtlib.utils.BaseMapAddition; -import com.blamejared.mtlib.utils.BaseMapRemoval; - +import com.blamejared.mtlib.utils.*; import minetweaker.MineTweakerAPI; -import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.oredict.IOreDictEntry; -import modtweaker.mods.embers.Embers; import net.minecraft.item.ItemStack; -import stanhebben.zenscript.annotations.Optional; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; -import teamroots.embers.recipe.ItemMeltingOreRecipe; -import teamroots.embers.recipe.ItemMeltingRecipe; -import teamroots.embers.recipe.RecipeRegistry; +import stanhebben.zenscript.annotations.*; +import teamroots.embers.compat.jei.MeltingRecipeWrapper; +import teamroots.embers.recipe.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; import static com.blamejared.mtlib.helpers.InputHelper.*; -import static com.blamejared.mtlib.helpers.StackHelper.matches; @ZenClass("mods.embers.Melter") public class Melter { - public static String name = "Embers Melter"; - - @ZenMethod - public static void addRecipe(IItemStack input, ILiquidStack outputOne, boolean matchMeta, boolean matchNBT) { - MineTweakerAPI.apply(new Add(toStack(input), new ItemMeltingRecipe(toStack(input),toFluid(outputOne), matchMeta, matchNBT))); - } - - @ZenMethod - public static void addOreRecipe(IOreDictEntry key, ILiquidStack outputOne, boolean matchMeta, boolean matchNBT) { - MineTweakerAPI.apply(new AddOre(key.getName(), new ItemMeltingOreRecipe(key.getName(),toFluid(outputOne)))); - } - - - private static class AddOre extends BaseMapAddition { - public AddOre(String stack, ItemMeltingOreRecipe recipe) { - super(Melter.name, RecipeRegistry.meltingOreRecipes); - - this.recipes.put(stack, recipe); - } - - @Override - protected String getRecipeInfo(Entry arg0) { - // TODO Auto-generated method stub - return arg0.getValue().getOreName(); - } - } - - - private static class Add extends BaseMapAddition { - public Add(ItemStack stack, ItemMeltingRecipe recipe) { - super(Melter.name, RecipeRegistry.meltingRecipes); - - this.recipes.put(stack, recipe); - } - - @Override - protected String getRecipeInfo(Entry arg0) { - // TODO Auto-generated method stub - return LogHelper.getStackDescription(arg0.getValue().getStack()); - } - } - - @ZenMethod - public static void remove(ILiquidStack fluid) { - List recipes = new ArrayList(); - List oreRecipes = new ArrayList(); - if (fluid == null) { - LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name)); - return; - } - - for (int i = 0; i < RecipeRegistry.meltingRecipes.size(); i ++){ - if (((ItemMeltingRecipe)RecipeRegistry.meltingRecipes.values().toArray()[i]).getFluid().getFluid().getName().equals(toFluid(fluid).getFluid().getName())){ - recipes.add(((ItemStack)RecipeRegistry.meltingRecipes.keySet().toArray()[i])); - } - } - - for (int i = 0; i < RecipeRegistry.meltingOreRecipes.size(); i ++){ - if (((ItemMeltingOreRecipe)RecipeRegistry.meltingOreRecipes.values().toArray()[i]).getFluid().getFluid().getName().equals(toFluid(fluid).getFluid().getName())){ - oreRecipes.add(((String)RecipeRegistry.meltingOreRecipes.keySet().toArray()[i])); - } - } - - if (!recipes.isEmpty()) { - Map map = new HashMap(); - for (int i = 0; i < recipes.size(); i ++){ - map.put(recipes.get(i), RecipeRegistry.meltingRecipes.get(recipes.get(i))); - } - MineTweakerAPI.apply(new Remove(map)); - } else if (!oreRecipes.isEmpty()) { - Map map = new HashMap(); - for (int i = 0; i < oreRecipes.size(); i ++){ - map.put(oreRecipes.get(i), RecipeRegistry.meltingOreRecipes.get(oreRecipes.get(i))); - } - MineTweakerAPI.apply(new RemoveOre(map)); - } else { - LogHelper.logWarning(String.format("No %s Recipe found for output %s. Command ignored!", Melter.name, - fluid.toString())); - } - - } - - private static class Remove extends BaseMapRemoval { - - public Remove(Map recipes) { - super(Melter.name, RecipeRegistry.meltingRecipes, recipes); - } - - @Override - protected String getRecipeInfo(Entry arg0) { - // TODO Auto-generated method stub - return LogHelper.getStackDescription(arg0.getValue().getStack()); - } - } - - private static class RemoveOre extends BaseMapRemoval { - - public RemoveOre(Map recipes) { - super(Melter.name, RecipeRegistry.meltingOreRecipes, recipes); - } - - @Override - protected String getRecipeInfo(Entry arg0) { - // TODO Auto-generated method stub - return arg0.getValue().getOreName(); - } - } + + public static String name = "Embers Melter"; + + @ZenMethod + public static void addRecipe(IItemStack input, ILiquidStack outputOne, boolean matchMeta, boolean matchNBT) { + MineTweakerAPI.apply(new Add(toStack(input), new ItemMeltingRecipe(toStack(input), toFluid(outputOne), matchMeta, matchNBT))); + } + + @ZenMethod + public static void addOreRecipe(IOreDictEntry key, ILiquidStack outputOne, boolean matchMeta, boolean matchNBT) { + MineTweakerAPI.apply(new AddOre(key.getName(), new ItemMeltingOreRecipe(key.getName(), toFluid(outputOne)))); + } + + @ZenMethod + public static void remove(ILiquidStack fluid) { + List recipes = new ArrayList<>(); + List oreRecipes = new ArrayList<>(); + if(fluid == null) { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name)); + return; + } + + for(int i = 0; i < RecipeRegistry.meltingRecipes.size(); i++) { + if(((ItemMeltingRecipe) RecipeRegistry.meltingRecipes.values().toArray()[i]).getFluid().getFluid().getName().equals(toFluid(fluid).getFluid().getName())) { + recipes.add(((ItemStack) RecipeRegistry.meltingRecipes.keySet().toArray()[i])); + } + } + + for(int i = 0; i < RecipeRegistry.meltingOreRecipes.size(); i++) { + if(((ItemMeltingOreRecipe) RecipeRegistry.meltingOreRecipes.values().toArray()[i]).getFluid().getFluid().getName().equals(toFluid(fluid).getFluid().getName())) { + oreRecipes.add(((String) RecipeRegistry.meltingOreRecipes.keySet().toArray()[i])); + } + } + + if(!recipes.isEmpty()) { + Map map = new HashMap(); + for(int i = 0; i < recipes.size(); i++) { + map.put(recipes.get(i), RecipeRegistry.meltingRecipes.get(recipes.get(i))); + } + MineTweakerAPI.apply(new Remove(map)); + } else if(!oreRecipes.isEmpty()) { + Map map = new HashMap(); + for(int i = 0; i < oreRecipes.size(); i++) { + map.put(oreRecipes.get(i), RecipeRegistry.meltingOreRecipes.get(oreRecipes.get(i))); + } + MineTweakerAPI.apply(new RemoveOre(map)); + } else { + LogHelper.logWarning(String.format("No %s Recipe found for output %s. Command ignored!", Melter.name, fluid.toString())); + } + + } + + private static class AddOre extends BaseMapAddition { + + public AddOre(String stack, ItemMeltingOreRecipe recipe) { + super(Melter.name, RecipeRegistry.meltingOreRecipes); + + this.recipes.put(stack, recipe); + } + + @Override + public void apply() { + super.apply(); + successful.forEach((stack, recipe) -> { + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new MeltingRecipeWrapper(recipe)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach((stack, recipe) -> { + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new MeltingRecipeWrapper(recipe)); + }); + } + + @Override + protected String getRecipeInfo(Entry arg0) { + return arg0.getValue().getOreName(); + } + } + + private static class Add extends BaseMapAddition { + + public Add(ItemStack stack, ItemMeltingRecipe recipe) { + super(Melter.name, RecipeRegistry.meltingRecipes); + this.recipes.put(stack, recipe); + } + + @Override + public void apply() { + super.apply(); + successful.forEach((stack, recipe) -> { + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new MeltingRecipeWrapper(recipe)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach((stack, recipe) -> { + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new MeltingRecipeWrapper(recipe)); + }); + } + + @Override + protected String getRecipeInfo(Entry arg0) { + return LogHelper.getStackDescription(arg0.getValue().getStack()); + } + } + + private static class Remove extends BaseMapRemoval { + + public Remove(Map recipes) { + super(Melter.name, RecipeRegistry.meltingRecipes, recipes); + } + @Override + public void apply() { + super.apply(); + successful.forEach((stack, recipe) -> { + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new MeltingRecipeWrapper(recipe)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach((stack, recipe) -> { + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new MeltingRecipeWrapper(recipe)); + }); + } + @Override + protected String getRecipeInfo(Entry arg0) { + return LogHelper.getStackDescription(arg0.getValue().getStack()); + } + } + + private static class RemoveOre extends BaseMapRemoval { + + public RemoveOre(Map recipes) { + super(Melter.name, RecipeRegistry.meltingOreRecipes, recipes); + } + @Override + public void apply() { + super.apply(); + successful.forEach((stack, recipe) -> { + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new MeltingRecipeWrapper(recipe)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach((stack, recipe) -> { + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new MeltingRecipeWrapper(recipe)); + }); + } + @Override + protected String getRecipeInfo(Entry arg0) { + return arg0.getValue().getOreName(); + } + } } diff --git a/src/main/java/modtweaker/mods/embers/handlers/Mixer.java b/src/main/java/modtweaker/mods/embers/handlers/Mixer.java index 4594c3e..e3d7e12 100644 --- a/src/main/java/modtweaker/mods/embers/handlers/Mixer.java +++ b/src/main/java/modtweaker/mods/embers/handlers/Mixer.java @@ -1,107 +1,115 @@ package modtweaker.mods.embers.handlers; import com.blamejared.mtlib.helpers.LogHelper; -import com.blamejared.mtlib.helpers.StackHelper; -import com.blamejared.mtlib.utils.BaseListAddition; -import com.blamejared.mtlib.utils.BaseListRemoval; -import com.blamejared.mtlib.utils.BaseMapAddition; -import com.blamejared.mtlib.utils.BaseMapRemoval; - +import com.blamejared.mtlib.utils.*; import minetweaker.MineTweakerAPI; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; import minetweaker.api.liquid.ILiquidStack; -import minetweaker.api.oredict.IOreDictEntry; -import modtweaker.mods.embers.Embers; -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; -import teamroots.embers.item.EnumStampType; -import teamroots.embers.recipe.FluidMixingRecipe; -import teamroots.embers.recipe.ItemMeltingOreRecipe; -import teamroots.embers.recipe.ItemMeltingRecipe; -import teamroots.embers.recipe.ItemStampingOreRecipe; -import teamroots.embers.recipe.ItemStampingRecipe; -import teamroots.embers.recipe.RecipeRegistry; +import stanhebben.zenscript.annotations.*; +import teamroots.embers.compat.jei.MixingRecipeWrapper; +import teamroots.embers.recipe.*; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Map.Entry; +import java.util.*; -import static com.blamejared.mtlib.helpers.InputHelper.*; -import static com.blamejared.mtlib.helpers.StackHelper.matches; +import static com.blamejared.mtlib.helpers.InputHelper.toFluid; @ZenClass("mods.embers.Mixer") public class Mixer { - public static String name = "Embers Mixer"; - - @ZenMethod - public static void addRecipe(ILiquidStack input1, ILiquidStack input2, ILiquidStack input3, ILiquidStack input4, ILiquidStack output) { - ArrayList fluids = new ArrayList(); - if (input1 != null){ - fluids.add(toFluid(input1)); - } - if (input2 != null){ - fluids.add(toFluid(input2)); - } - if (input3 != null){ - fluids.add(toFluid(input3)); - } - if (input4 != null){ - fluids.add(toFluid(input4)); - } - MineTweakerAPI.apply(new Add(new FluidMixingRecipe(fluids.toArray(new FluidStack[fluids.size()]), toFluid(output)))); - } - - private static class Add extends BaseListAddition { - public Add(FluidMixingRecipe recipe) { - super(Mixer.name, RecipeRegistry.mixingRecipes); - - this.recipes.add(recipe); - } - - @Override - protected String getRecipeInfo(FluidMixingRecipe arg0) { - return LogHelper.getStackDescription(arg0.output); - } - } - - @ZenMethod - public static void remove(ILiquidStack output) { - List recipes = new ArrayList(); - - for (int i = 0; i < RecipeRegistry.mixingRecipes.size(); i ++){ - if (RecipeRegistry.mixingRecipes.get(i).output.getFluid().getName().equals(toFluid(output).getFluid().getName())){ - recipes.add(RecipeRegistry.mixingRecipes.get(i)); - } - } - - if (!recipes.isEmpty()) { - for (int i = 0; i < recipes.size(); i ++){ - MineTweakerAPI.apply(new Remove(recipes.get(i))); - } - } - else { - LogHelper.logWarning(String.format("No %s Recipe found for output %s. Command ignored!", Mixer.name, - output.toString())); - } - - } - - private static class Remove extends BaseListRemoval { - - public Remove(FluidMixingRecipe recipe) { - super(Mixer.name, RecipeRegistry.mixingRecipes); - this.recipes.remove(recipe); - } - - @Override - protected String getRecipeInfo(FluidMixingRecipe arg0) { - // TODO Auto-generated method stub - return LogHelper.getStackDescription(arg0.output); - } - } + + public static String name = "Embers Mixer"; + + @ZenMethod + public static void addRecipe(ILiquidStack input1, ILiquidStack input2, ILiquidStack input3, ILiquidStack input4, ILiquidStack output) { + ArrayList fluids = new ArrayList<>(); + if(input1 != null) { + fluids.add(toFluid(input1)); + } + if(input2 != null) { + fluids.add(toFluid(input2)); + } + if(input3 != null) { + fluids.add(toFluid(input3)); + } + if(input4 != null) { + fluids.add(toFluid(input4)); + } + MineTweakerAPI.apply(new Add(new FluidMixingRecipe(fluids.toArray(new FluidStack[fluids.size()]), toFluid(output)))); + } + + + @ZenMethod + public static void remove(ILiquidStack output) { + List recipes = new ArrayList<>(); + + for(int i = 0; i < RecipeRegistry.mixingRecipes.size(); i++) { + if(RecipeRegistry.mixingRecipes.get(i).output.getFluid().getName().equals(toFluid(output).getFluid().getName())) { + recipes.add(RecipeRegistry.mixingRecipes.get(i)); + } + } + + if(!recipes.isEmpty()) { + for(int i = 0; i < recipes.size(); i++) { + MineTweakerAPI.apply(new Remove(recipes.get(i))); + } + } else { + LogHelper.logWarning(String.format("No %s Recipe found for output %s. Command ignored!", Mixer.name, output.toString())); + } + + } + + private static class Add extends BaseListAddition { + + public Add(FluidMixingRecipe recipe) { + super(Mixer.name, RecipeRegistry.mixingRecipes); + this.recipes.add(recipe); + } + + @Override + public void apply() { + super.apply(); + successful.forEach(rec ->{ + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new MixingRecipeWrapper(rec)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach(rec ->{ + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new MixingRecipeWrapper(rec)); + }); + } + + @Override + protected String getRecipeInfo(FluidMixingRecipe arg0) { + return LogHelper.getStackDescription(arg0.output); + } + } + + private static class Remove extends BaseListRemoval { + + public Remove(FluidMixingRecipe recipe) { + super(Mixer.name, RecipeRegistry.mixingRecipes); + this.recipes.remove(recipe); + } + @Override + public void apply() { + super.apply(); + successful.forEach(rec ->{ + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new MixingRecipeWrapper(rec)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach(rec ->{ + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new MixingRecipeWrapper(rec)); + }); + } + @Override + protected String getRecipeInfo(FluidMixingRecipe arg0) { + return LogHelper.getStackDescription(arg0.output); + } + } } diff --git a/src/main/java/modtweaker/mods/embers/handlers/Stamper.java b/src/main/java/modtweaker/mods/embers/handlers/Stamper.java index 162c804..a650d34 100644 --- a/src/main/java/modtweaker/mods/embers/handlers/Stamper.java +++ b/src/main/java/modtweaker/mods/embers/handlers/Stamper.java @@ -1,153 +1,199 @@ package modtweaker.mods.embers.handlers; import com.blamejared.mtlib.helpers.LogHelper; -import com.blamejared.mtlib.helpers.StackHelper; -import com.blamejared.mtlib.utils.BaseListAddition; -import com.blamejared.mtlib.utils.BaseListRemoval; -import com.blamejared.mtlib.utils.BaseMapAddition; -import com.blamejared.mtlib.utils.BaseMapRemoval; - +import com.blamejared.mtlib.utils.*; import minetweaker.MineTweakerAPI; -import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.oredict.IOreDictEntry; -import modtweaker.mods.embers.Embers; import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; -import stanhebben.zenscript.annotations.Optional; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; +import teamroots.embers.compat.jei.StampingRecipeWrapper; import teamroots.embers.item.EnumStampType; -import teamroots.embers.recipe.ItemMeltingOreRecipe; -import teamroots.embers.recipe.ItemMeltingRecipe; -import teamroots.embers.recipe.ItemStampingOreRecipe; -import teamroots.embers.recipe.ItemStampingRecipe; -import teamroots.embers.recipe.RecipeRegistry; +import teamroots.embers.recipe.*; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Map.Entry; +import java.util.*; import static com.blamejared.mtlib.helpers.InputHelper.*; -import static com.blamejared.mtlib.helpers.StackHelper.matches; @ZenClass("mods.embers.Stamper") public class Stamper { - public static String name = "Embers Stamper"; - - public static EnumStampType getStampFromString(String string){ - switch (string){ - default: - return EnumStampType.TYPE_NULL; - case "flat": - return EnumStampType.TYPE_FLAT; - case "bar": - return EnumStampType.TYPE_BAR; - case "plate": - return EnumStampType.TYPE_PLATE; - case "null": - return EnumStampType.TYPE_NULL; - } - } - - @ZenMethod - public static void addRecipe(IItemStack itemInput, ILiquidStack fluidInput, String stampType, IItemStack result, boolean matchMeta, boolean matchNBT) { - MineTweakerAPI.apply(new Add(new ItemStampingRecipe(toStack(itemInput), toFluid(fluidInput), getStampFromString(stampType), toStack(result), matchMeta, matchNBT))); - } - - @ZenMethod - public static void addRecipe(IOreDictEntry key, ILiquidStack fluidInput, String stampType, IItemStack result) { - MineTweakerAPI.apply(new AddOre(new ItemStampingOreRecipe(key.getName(), toFluid(fluidInput), getStampFromString(stampType), toStack(result), false, false))); - } - - - private static class AddOre extends BaseListAddition { - public AddOre(ItemStampingOreRecipe recipe) { - super(Stamper.name, RecipeRegistry.stampingOreRecipes); - - this.recipes.add(recipe); - } - - @Override - protected String getRecipeInfo(ItemStampingOreRecipe arg0) { - // TODO Auto-generated method stub - return arg0.getOre(); - } - } - - - private static class Add extends BaseListAddition { - public Add(ItemStampingRecipe recipe) { - super(Stamper.name, RecipeRegistry.stampingRecipes); - - this.recipes.add(recipe); - } - - @Override - protected String getRecipeInfo(ItemStampingRecipe arg0) { - return LogHelper.getStackDescription(arg0.getStack()); - } - } - - @ZenMethod - public static void remove(IItemStack item) { - List recipes = new ArrayList(); - List oreRecipes = new ArrayList(); - - if (item == null) { - LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name)); - return; - } - - for (int i = 0; i < RecipeRegistry.stampingRecipes.size(); i ++){ - if (ItemStack.areItemsEqual(RecipeRegistry.stampingRecipes.get(i).result,toStack(item))){ - recipes.add(RecipeRegistry.stampingRecipes.get(i)); - } - } - - for (int i = 0; i < RecipeRegistry.stampingOreRecipes.size(); i ++){ - if (ItemStack.areItemsEqual(RecipeRegistry.stampingOreRecipes.get(i).result,toStack(item))){ - oreRecipes.add(RecipeRegistry.stampingOreRecipes.get(i)); - } - } - - if (!recipes.isEmpty()) { - MineTweakerAPI.apply(new Remove(recipes)); - } - else if (!oreRecipes.isEmpty()) { - MineTweakerAPI.apply(new RemoveOre(oreRecipes)); - } else { - LogHelper.logWarning(String.format("No %s Recipe found for output %s. Command ignored!", Stamper.name, - item.toString())); - } - - } - - private static class Remove extends BaseListRemoval { - - public Remove(List recipes) { - super(Stamper.name, RecipeRegistry.stampingRecipes, recipes); - } - - @Override - protected String getRecipeInfo(ItemStampingRecipe arg0) { - // TODO Auto-generated method stub - return LogHelper.getStackDescription(arg0.getStack()); - } - } - - private static class RemoveOre extends BaseListRemoval { - - public RemoveOre(List recipes) { - super(Stamper.name, RecipeRegistry.stampingOreRecipes, recipes); - } - - @Override - protected String getRecipeInfo(ItemStampingOreRecipe arg0) { - // TODO Auto-generated method stub - return arg0.getOre(); - } - } + + public static String name = "Embers Stamper"; + + + @ZenMethod + public static void addRecipe(IItemStack itemInput, ILiquidStack fluidInput, String stampType, IItemStack result, boolean matchMeta, boolean matchNBT) { + MineTweakerAPI.apply(new Add(new ItemStampingRecipe(toStack(itemInput), toFluid(fluidInput), getStampFromString(stampType), toStack(result), matchMeta, matchNBT))); + } + + @ZenMethod + public static void addRecipe(IOreDictEntry key, ILiquidStack fluidInput, String stampType, IItemStack result) { + MineTweakerAPI.apply(new AddOre(new ItemStampingOreRecipe(key.getName(), toFluid(fluidInput), getStampFromString(stampType), toStack(result), false, false))); + } + + @ZenMethod + public static void remove(IItemStack item) { + List recipes = new ArrayList(); + List oreRecipes = new ArrayList(); + + if(item == null) { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name)); + return; + } + + for(int i = 0; i < RecipeRegistry.stampingRecipes.size(); i++) { + if(ItemStack.areItemsEqual(RecipeRegistry.stampingRecipes.get(i).result, toStack(item))) { + recipes.add(RecipeRegistry.stampingRecipes.get(i)); + } + } + + for(int i = 0; i < RecipeRegistry.stampingOreRecipes.size(); i++) { + if(ItemStack.areItemsEqual(RecipeRegistry.stampingOreRecipes.get(i).result, toStack(item))) { + oreRecipes.add(RecipeRegistry.stampingOreRecipes.get(i)); + } + } + + if(!recipes.isEmpty()) { + MineTweakerAPI.apply(new Remove(recipes)); + } else if(!oreRecipes.isEmpty()) { + MineTweakerAPI.apply(new RemoveOre(oreRecipes)); + } else { + LogHelper.logWarning(String.format("No %s Recipe found for output %s. Command ignored!", Stamper.name, item.toString())); + } + + } + + private static class AddOre extends BaseListAddition { + + public AddOre(ItemStampingOreRecipe recipe) { + super(Stamper.name, RecipeRegistry.stampingOreRecipes); + + this.recipes.add(recipe); + } + + @Override + public void apply() { + super.apply(); + successful.forEach(rec -> { + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new StampingRecipeWrapper(rec)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach(rec -> { + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new StampingRecipeWrapper(rec)); + }); + } + + @Override + protected String getRecipeInfo(ItemStampingOreRecipe arg0) { + return arg0.getOre(); + } + } + + + private static class Add extends BaseListAddition { + + public Add(ItemStampingRecipe recipe) { + super(Stamper.name, RecipeRegistry.stampingRecipes); + + this.recipes.add(recipe); + } + + @Override + public void apply() { + super.apply(); + successful.forEach(rec -> { + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new StampingRecipeWrapper(rec)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach(rec -> { + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new StampingRecipeWrapper(rec)); + }); + } + + @Override + protected String getRecipeInfo(ItemStampingRecipe arg0) { + return LogHelper.getStackDescription(arg0.getStack()); + } + } + + private static class Remove extends BaseListRemoval { + + public Remove(List recipes) { + super(Stamper.name, RecipeRegistry.stampingRecipes, recipes); + } + + @Override + public void apply() { + super.apply(); + successful.forEach(rec -> { + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new StampingRecipeWrapper(rec)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach(rec -> { + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new StampingRecipeWrapper(rec)); + }); + } + + @Override + protected String getRecipeInfo(ItemStampingRecipe arg0) { + return LogHelper.getStackDescription(arg0.getStack()); + } + } + + private static class RemoveOre extends BaseListRemoval { + + public RemoveOre(List recipes) { + super(Stamper.name, RecipeRegistry.stampingOreRecipes, recipes); + } + + @Override + public void apply() { + super.apply(); + successful.forEach(rec -> { + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(new StampingRecipeWrapper(rec)); + }); + } + + @Override + public void undo() { + super.undo(); + successful.forEach(rec -> { + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(new StampingRecipeWrapper(rec)); + }); + } + + @Override + protected String getRecipeInfo(ItemStampingOreRecipe arg0) { + return arg0.getOre(); + } + } + + + public static EnumStampType getStampFromString(String string) { + switch(string) { + default: + return EnumStampType.TYPE_NULL; + case "flat": + return EnumStampType.TYPE_FLAT; + case "bar": + return EnumStampType.TYPE_BAR; + case "plate": + return EnumStampType.TYPE_PLATE; + case "null": + return EnumStampType.TYPE_NULL; + } + } }