diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/ThermalHelper.java b/src/main/java/modtweaker2/mods/thermalexpansion/ThermalHelper.java index d383efe..8b4b867 100644 --- a/src/main/java/modtweaker2/mods/thermalexpansion/ThermalHelper.java +++ b/src/main/java/modtweaker2/mods/thermalexpansion/ThermalHelper.java @@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import cofh.thermalexpansion.util.crafting.CrucibleManager.RecipeCrucible; import cofh.thermalexpansion.util.crafting.FurnaceManager.RecipeFurnace; +import cofh.thermalexpansion.util.crafting.InsolatorManager.RecipeInsolator; import cofh.thermalexpansion.util.crafting.PulverizerManager.RecipePulverizer; import cofh.thermalexpansion.util.crafting.SawmillManager.RecipeSawmill; import cofh.thermalexpansion.util.crafting.SmelterManager.RecipeSmelter; @@ -18,6 +19,7 @@ import cofh.thermalexpansion.util.crafting.TransposerManager.RecipeTransposer; public class ThermalHelper { public static Constructor crucibleRecipe; public static Constructor furanceRecipe; + public static Constructor insolatorRecipe; public static Constructor pulverizerRecipe; public static Constructor sawmillRecipe; public static Constructor smelterRecipe; @@ -27,6 +29,7 @@ public class ThermalHelper { try { crucibleRecipe = getConstructor(RecipeCrucible.class, ItemStack.class, FluidStack.class, int.class); furanceRecipe = getConstructor(RecipeFurnace.class, ItemStack.class, ItemStack.class, int.class); + insolatorRecipe = getConstructor(RecipeInsolator.class, ItemStack.class, ItemStack.class, ItemStack.class, ItemStack.class, int.class, int.class); pulverizerRecipe = getConstructor(RecipePulverizer.class, ItemStack.class, ItemStack.class, ItemStack.class, int.class, int.class); sawmillRecipe = getConstructor(RecipeSawmill.class, ItemStack.class, ItemStack.class, ItemStack.class, int.class, int.class); smelterRecipe = getConstructor(RecipeSmelter.class, ItemStack.class, ItemStack.class, ItemStack.class, ItemStack.class, int.class, int.class); @@ -185,6 +188,43 @@ public class ThermalHelper { return true; } + public static boolean equals(RecipeInsolator r1, RecipeInsolator r2) { + if(r1 == r2) { + return true; + } + + if(r1 == null || r2 == null) { + return false; + } + + if(!areEqualOrNull(r1.getPrimaryInput(), r2.getPrimaryInput())) { + return false; + } + + if(!areEqualOrNull(r1.getSecondaryInput(), r2.getSecondaryInput())) { + return false; + } + + if(r1.getEnergy() != r2.getEnergy()) { + return false; + } + + if(!areEqualOrNull(r1.getPrimaryOutput(), r2.getPrimaryOutput())) { + return false; + } + + if(!areEqualOrNull(r1.getSecondaryOutput(), r2.getSecondaryOutput())) { + return false; + } + + if(r1.getSecondaryOutput() != null && r2.getSecondaryOutput() != null && + r1.getSecondaryOutputChance() != r2.getSecondaryOutputChance()) { + return false; + } + + return true; + } + public static boolean equals(RecipeTransposer r1, RecipeTransposer r2) { if(r1 == r2) { return true; diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/commands/ThermalExpansionLogger.java b/src/main/java/modtweaker2/mods/thermalexpansion/commands/ThermalExpansionLogger.java index 6f20a1b..ac90c1c 100644 --- a/src/main/java/modtweaker2/mods/thermalexpansion/commands/ThermalExpansionLogger.java +++ b/src/main/java/modtweaker2/mods/thermalexpansion/commands/ThermalExpansionLogger.java @@ -14,6 +14,8 @@ import cofh.thermalexpansion.util.crafting.CrucibleManager; import cofh.thermalexpansion.util.crafting.CrucibleManager.RecipeCrucible; import cofh.thermalexpansion.util.crafting.FurnaceManager; import cofh.thermalexpansion.util.crafting.FurnaceManager.RecipeFurnace; +import cofh.thermalexpansion.util.crafting.InsolatorManager; +import cofh.thermalexpansion.util.crafting.InsolatorManager.RecipeInsolator; import cofh.thermalexpansion.util.crafting.PulverizerManager; import cofh.thermalexpansion.util.crafting.PulverizerManager.RecipePulverizer; import cofh.thermalexpansion.util.crafting.SawmillManager; @@ -29,6 +31,7 @@ public class ThermalExpansionLogger implements ICommandFunction { static { validArguments.add("crucible"); validArguments.add("furnace"); + validArguments.add("insolator"); validArguments.add("pulverizer"); validArguments.add("sawmill"); validArguments.add("smelter"); @@ -62,6 +65,26 @@ public class ThermalExpansionLogger implements ICommandFunction { } } + if(args.isEmpty() || args.contains("insolator")) { + for(RecipeInsolator recipe : InsolatorManager.getRecipeList()) { + if(recipe.getSecondaryOutput() != null) { + MineTweakerAPI.logCommand(String.format("mods.thermalexpansion.Insolator.addRecipe(%d, %s, %s, %s, %s, %d);", + recipe.getEnergy(), + LogHelper.getStackDescription(recipe.getPrimaryInput()), + LogHelper.getStackDescription(recipe.getSecondaryInput()), + LogHelper.getStackDescription(recipe.getPrimaryOutput()), + LogHelper.getStackDescription(recipe.getSecondaryOutput()), + recipe.getSecondaryOutputChance())); + } else { + MineTweakerAPI.logCommand(String.format("mods.thermalexpansion.Insolator.addRecipe(%d, %s, %s, %s);", + recipe.getEnergy(), + LogHelper.getStackDescription(recipe.getPrimaryInput()), + LogHelper.getStackDescription(recipe.getSecondaryInput()), + LogHelper.getStackDescription(recipe.getPrimaryOutput()))); + } + } + } + if(args.isEmpty() || args.contains("pulverizer")) { for(RecipePulverizer recipe : PulverizerManager.getRecipeList()) { if(recipe.getSecondaryOutput() != null) { diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Furnace.java b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Furnace.java index 94b2e07..d40851a 100644 --- a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Furnace.java +++ b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Furnace.java @@ -26,7 +26,7 @@ public class Furnace { public static final String name = "Thermal Expansion Furnace"; -// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @ZenMethod public static void addRecipe(int energy, IItemStack input, IItemStack output) { diff --git a/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Insolator.java b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Insolator.java new file mode 100644 index 0000000..7c49d08 --- /dev/null +++ b/src/main/java/modtweaker2/mods/thermalexpansion/handlers/Insolator.java @@ -0,0 +1,190 @@ +package modtweaker2.mods.thermalexpansion.handlers; + +import static modtweaker2.helpers.InputHelper.toIItemStack; +import static modtweaker2.helpers.InputHelper.toStack; +import static modtweaker2.helpers.StackHelper.matches; + +import java.util.LinkedList; +import java.util.List; + +import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import modtweaker2.helpers.LogHelper; +import modtweaker2.helpers.ReflectionHelper; +import modtweaker2.mods.thermalexpansion.ThermalHelper; +import modtweaker2.utils.BaseListAddition; +import modtweaker2.utils.BaseListRemoval; +import stanhebben.zenscript.annotations.Optional; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; +import cofh.thermalexpansion.util.crafting.InsolatorManager; +import cofh.thermalexpansion.util.crafting.InsolatorManager.RecipeInsolator; + +@ZenClass("mods.thermalexpansion.Insolator") +public class Insolator { + + public static final String name = "Thermal Expansion Insolator"; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void addRecipe(int energy, IItemStack primaryInput, IItemStack secondaryInput, IItemStack primaryOutput, @Optional IItemStack secondaryOutput, @Optional int secondaryChance) { + if(primaryInput == null || secondaryInput == null || primaryOutput == null) { + LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name)); + return; + } + + if(InsolatorManager.recipeExists(toStack(primaryInput), toStack(secondaryInput))) { + LogHelper.logWarning(String.format("Duplicate %s Recipe found for %s and %s. Command ignored!", name, primaryInput.toString(), secondaryInput.toString())); + return; + } + + RecipeInsolator recipe = ReflectionHelper.getInstance(ThermalHelper.insolatorRecipe, toStack(primaryInput), toStack(secondaryInput), toStack(primaryOutput), toStack(secondaryOutput), secondaryChance, energy); + + if(recipe != null) { + MineTweakerAPI.apply(new Add(recipe)); + } else { + LogHelper.logError(String.format("Error while creating instance for %s recipe.", name)); + } + } + + private static class Add extends BaseListAddition { + public Add(RecipeInsolator recipe) { + super(Insolator.name, null); + recipes.add(recipe); + } + + public void apply() { + for(RecipeInsolator recipe : recipes) { + boolean applied = InsolatorManager.addRecipe( + recipe.getEnergy(), + recipe.getPrimaryInput(), + recipe.getSecondaryInput(), + recipe.getPrimaryOutput(), + recipe.getSecondaryOutput(), + recipe.getSecondaryOutputChance(), + false); + + if(applied) { + successful.add(recipe); + } + } + + } + + public void undo() { + for(RecipeInsolator recipe : recipes) { + InsolatorManager.removeRecipe(recipe.getPrimaryInput(), recipe.getSecondaryInput()); + } + + } + + @Override + protected boolean equals(RecipeInsolator recipe, RecipeInsolator otherRecipe) { + return ThermalHelper.equals(recipe, otherRecipe); + } + + @Override + protected String getRecipeInfo(RecipeInsolator recipe) { + return LogHelper.getStackDescription(recipe.getPrimaryOutput()); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void removeRecipe(IIngredient input1, IIngredient input2) { + List recipes = new LinkedList(); + + for(RecipeInsolator recipe : InsolatorManager.getRecipeList()) { + if(recipe != null && matches(input1, toIItemStack(recipe.getPrimaryInput())) && matches(input2, toIItemStack(recipe.getSecondaryInput()))) { + recipes.add(recipe); + } + } + + if(!recipes.isEmpty()) { + MineTweakerAPI.apply(new Remove(recipes)); + } else { + LogHelper.logWarning(String.format("No %s Recipes found for %s and %s.", name, input1.toString(), input2.toString())); + } + } + + private static class Remove extends BaseListRemoval { + + public Remove(List recipes) { + super(Insolator.name, null, recipes); + } + + @Override + public void apply() { + for(RecipeInsolator recipe : recipes) { + boolean removed = InsolatorManager.removeRecipe(recipe.getPrimaryInput(), recipe.getSecondaryInput()); + + if(removed) { + successful.add(recipe); + } + } + } + + @Override + public void undo() { + for(RecipeInsolator recipe : recipes) { + InsolatorManager.addRecipe( + recipe.getEnergy(), + recipe.getPrimaryInput(), + recipe.getSecondaryInput(), + recipe.getPrimaryOutput(), + recipe.getSecondaryOutput(), + recipe.getSecondaryOutputChance()); + } + } + + @Override + protected boolean equals(RecipeInsolator recipe, RecipeInsolator otherRecipe) { + return ThermalHelper.equals(recipe, otherRecipe); + } + + @Override + public String getRecipeInfo(RecipeInsolator recipe) { + return LogHelper.getStackDescription(recipe.getPrimaryOutput()); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @ZenMethod + public static void refreshRecipes() { + MineTweakerAPI.apply(new Refresh()); + } + + private static class Refresh implements IUndoableAction { + + public void apply() { + InsolatorManager.refreshRecipes(); + } + + public boolean canUndo() { + return true; + } + + public String describe() { + return "Refreshing " + Insolator.name + " recipes"; + } + + public void undo() { + } + + public String describeUndo() { + return "Ignoring undo of " + Insolator.name + " recipe refresh"; + } + + public Object getOverrideKey() { + return null; + } + } + +}