Added Thermal Expansion Insolator support

This commit is contained in:
Zixxl 2015-07-13 21:36:01 +02:00
parent 3c7d6c120e
commit 9a9f6ccaf2
4 changed files with 254 additions and 1 deletions

View file

@ -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<RecipeCrucible> crucibleRecipe;
public static Constructor<RecipeFurnace> furanceRecipe;
public static Constructor<RecipeInsolator> insolatorRecipe;
public static Constructor<RecipePulverizer> pulverizerRecipe;
public static Constructor<RecipeSawmill> sawmillRecipe;
public static Constructor<RecipeSmelter> 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;

View file

@ -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) {

View file

@ -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) {

View file

@ -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<RecipeInsolator> {
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<RecipeInsolator> recipes = new LinkedList<RecipeInsolator>();
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<RecipeInsolator> {
public Remove(List<RecipeInsolator> 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;
}
}
}