More Thermal Expansion rework

- Equals method
- refreshRecipes for all machines
This commit is contained in:
Zixxl committed 2015-07-07 15:40:03 +02:00
1 parent 615e96d27f
commit 9f61304258
8 files changed
+437 -6

No files matched your search

@@ -7,6 +7,7 @@ import minetweaker.api.liquid.ILiquidStack;
import modtweaker2.mods.botania.Botania;
import modtweaker2.utils.TweakerPlugin;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public class StackHelper {
/**
@@ -22,6 +23,14 @@ public class StackHelper {
}
}
public static boolean areEqual(FluidStack stack1, FluidStack stack2) {
if(stack1 == null || stack2 == null) {
return false;
}
return stack1.isFluidEqual(stack2);
}
/**
* Compares two ItemStack instances if they reference the same object or
* are both null. If false, the method areEqual() is called to check if the
@@ -36,6 +45,15 @@ public class StackHelper {
return(areEqual(stack1, stack2));
}
public static boolean areEqualOrNull(FluidStack stack1, FluidStack stack2) {
// Check if they reference the same object or are are both null
if(stack1 == stack2) {
return true;
}
return(areEqual(stack1, stack2));
}
/**
* Adds extra check to IIngredient matches() for Botania special flowers
*/
@@ -1,6 +1,7 @@
package modtweaker2.mods.thermalexpansion;
import static modtweaker2.helpers.ReflectionHelper.getConstructor;
import static modtweaker2.helpers.StackHelper.areEqualOrNull;
import java.lang.reflect.Constructor;
@@ -32,4 +33,187 @@ public class ThermalHelper {
transposerRecipe = getConstructor(RecipeTransposer.class, ItemStack.class, ItemStack.class, FluidStack.class, int.class, int.class);
} catch (Exception e) { LogHelper.logError("Exception getting constructor for Thermal Expansion recipes!", e); }
}
public static boolean equals(RecipeCrucible r1, RecipeCrucible r2) {
if(r1 == r2) {
return true;
}
if(r1 == null || r2 == null) {
return false;
}
if(!areEqualOrNull(r1.getInput(), r2.getInput())) {
return false;
}
if(r1.getEnergy() != r2.getEnergy()) {
return false;
}
if(!areEqualOrNull(r1.getOutput(), r2.getOutput())) {
return false;
}
return true;
}
public static boolean equals(RecipeFurnace r1, RecipeFurnace r2) {
if(r1 == r2) {
return true;
}
if(r1 == null || r2 == null) {
return false;
}
if(!areEqualOrNull(r1.getInput(), r2.getInput())) {
return false;
}
if(r1.getEnergy() != r2.getEnergy()) {
return false;
}
if(!areEqualOrNull(r1.getOutput(), r2.getOutput())) {
return false;
}
return true;
}
public static boolean equals(RecipePulverizer r1, RecipePulverizer r2) {
if(r1 == r2) {
return true;
}
if(r1 == null || r2 == null) {
return false;
}
if(!areEqualOrNull(r1.getInput(), r2.getInput())) {
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(RecipeSawmill r1, RecipeSawmill r2) {
if(r1 == r2) {
return true;
}
if(r1 == null || r2 == null) {
return false;
}
if(!areEqualOrNull(r1.getInput(), r2.getInput())) {
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(RecipeSmelter r1, RecipeSmelter 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;
}
if(r1 == null || r2 == null) {
return false;
}
if(!areEqualOrNull(r1.getInput(), r2.getInput())) {
return false;
}
if(r1.getEnergy() != r2.getEnergy()) {
return false;
}
if(!areEqualOrNull(r1.getOutput(), r2.getOutput())) {
return false;
}
if(!areEqualOrNull(r1.getFluid(), r2.getFluid())) {
return false;
}
if(r1.getChance() != r2.getChance()) {
return false;
}
return true;
}
}
@@ -8,6 +8,7 @@ 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;
@@ -69,13 +70,18 @@ public class Crucible {
}
}
@Override
protected boolean equals(RecipeCrucible recipe, RecipeCrucible otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
protected String getRecipeInfo(RecipeCrucible recipe) {
return InputHelper.getStackDescription(recipe.getInput());
}
}
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeRecipe(IIngredient input) {
@@ -119,9 +125,47 @@ public class Crucible {
}
}
@Override
protected boolean equals(RecipeCrucible recipe, RecipeCrucible otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
protected String getRecipeInfo(RecipeCrucible recipe) {
return InputHelper.getStackDescription(recipe.getInput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void refreshRecipes() {
MineTweakerAPI.apply(new Refresh());
}
private static class Refresh implements IUndoableAction {
public void apply() {
CrucibleManager.refreshRecipes();
}
public boolean canUndo() {
return true;
}
public String describe() {
return "Refreshing " + Crucible.name + " recipes";
}
public void undo() {
}
public String describeUndo() {
return "Ignoring undo of " + Crucible.name + " recipe refresh";
}
public Object getOverrideKey() {
return null;
}
}
}
@@ -71,6 +71,11 @@ public class Furnace {
}
}
@Override
protected boolean equals(RecipeFurnace recipe, RecipeFurnace otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
protected String getRecipeInfo(RecipeFurnace recipe) {
@@ -121,6 +126,11 @@ public class Furnace {
false);
}
}
@Override
protected boolean equals(RecipeFurnace recipe, RecipeFurnace otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
protected String getRecipeInfo(RecipeFurnace recipe) {
@@ -138,22 +148,22 @@ public class Furnace {
private static class Refresh implements IUndoableAction {
public void apply() {
FurnaceManager.loadRecipes();
FurnaceManager.refreshRecipes();
}
public boolean canUndo() {
return false;
return true;
}
public String describe() {
return "Refreshing Redstone Furnace Recipes";
return "Refreshing " + Furnace.name + " recipes";
}
public void undo() {
}
public String describeUndo() {
return "Can't Undo Redstone Furnace Refresh";
return "Ignoring undo of " + Furnace.name + " recipe refresh";
}
public Object getOverrideKey() {
@@ -7,6 +7,7 @@ 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;
@@ -74,6 +75,11 @@ public class Pulverizer {
PulverizerManager.removeRecipe(recipe.getInput());
}
}
@Override
protected boolean equals(RecipePulverizer recipe, RecipePulverizer otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
protected String getRecipeInfo(RecipePulverizer recipe) {
@@ -127,10 +133,48 @@ public class Pulverizer {
recipe.getSecondaryOutputChance());
}
}
@Override
protected boolean equals(RecipePulverizer recipe, RecipePulverizer otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
protected String getRecipeInfo(RecipePulverizer recipe) {
return InputHelper.getStackDescription(recipe.getInput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void refreshRecipes() {
MineTweakerAPI.apply(new Refresh());
}
private static class Refresh implements IUndoableAction {
public void apply() {
PulverizerManager.refreshRecipes();
}
public boolean canUndo() {
return true;
}
public String describe() {
return "Refreshing " + Pulverizer.name + " recipes";
}
public void undo() {
}
public String describeUndo() {
return "Ignoring undo of " + Pulverizer.name + " recipe refresh";
}
public Object getOverrideKey() {
return null;
}
}
}
@@ -7,6 +7,7 @@ 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;
@@ -75,7 +76,11 @@ public class Sawmill {
for(RecipeSawmill recipe : successful) {
SawmillManager.removeRecipe(recipe.getInput());
}
}
@Override
protected boolean equals(RecipeSawmill recipe, RecipeSawmill otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
@@ -131,9 +136,47 @@ public class Sawmill {
}
}
@Override
protected boolean equals(RecipeSawmill recipe, RecipeSawmill otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
protected String getRecipeInfo(RecipeSawmill recipe) {
return InputHelper.getStackDescription(recipe.getInput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void refreshRecipes() {
MineTweakerAPI.apply(new Refresh());
}
private static class Refresh implements IUndoableAction {
public void apply() {
SawmillManager.refreshRecipes();
}
public boolean canUndo() {
return true;
}
public String describe() {
return "Refreshing " + Sawmill.name + " recipes";
}
public void undo() {
}
public String describeUndo() {
return "Ignoring undo of " + Sawmill.name + " recipe refresh";
}
public Object getOverrideKey() {
return null;
}
}
}
@@ -7,6 +7,7 @@ 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;
@@ -77,6 +78,11 @@ public class Smelter {
SmelterManager.removeRecipe(recipe.getPrimaryInput(), recipe.getSecondaryInput());
}
}
@Override
protected boolean equals(RecipeSmelter recipe, RecipeSmelter otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
public String getRecipeInfo(RecipeSmelter recipe) {
@@ -132,10 +138,48 @@ public class Smelter {
recipe.getSecondaryOutputChance());
}
}
@Override
protected boolean equals(RecipeSmelter recipe, RecipeSmelter otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
public String getRecipeInfo(RecipeSmelter recipe) {
return InputHelper.getStackDescription(recipe.getPrimaryOutput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void refreshRecipes() {
MineTweakerAPI.apply(new Refresh());
}
private static class Refresh implements IUndoableAction {
public void apply() {
SmelterManager.refreshRecipes();
}
public boolean canUndo() {
return true;
}
public String describe() {
return "Refreshing " + Smelter.name + " recipes";
}
public void undo() {
}
public String describeUndo() {
return "Ignoring undo of " + Smelter.name + " recipe refresh";
}
public Object getOverrideKey() {
return null;
}
}
}
@@ -9,6 +9,7 @@ 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;
@@ -118,6 +119,11 @@ public class Transposer {
}
}
@Override
protected boolean equals(RecipeTransposer recipe, RecipeTransposer otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
protected String getRecipeInfo(RecipeTransposer recipe) {
return InputHelper.getStackDescription(recipe.getInput());
@@ -205,6 +211,11 @@ public class Transposer {
}
}
@Override
protected boolean equals(RecipeTransposer recipe, RecipeTransposer otherRecipe) {
return ThermalHelper.equals(recipe, otherRecipe);
}
@Override
protected String getRecipeInfo(RecipeTransposer recipe) {
return InputHelper.getStackDescription(recipe.getOutput());
@@ -215,4 +226,37 @@ public class Transposer {
Fill,
Extract
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void refreshRecipes() {
MineTweakerAPI.apply(new Refresh());
}
private static class Refresh implements IUndoableAction {
public void apply() {
TransposerManager.refreshRecipes();
}
public boolean canUndo() {
return true;
}
public String describe() {
return "Refreshing " + Transposer.nameFill + " & " + Transposer.nameExtract + " recipes";
}
public void undo() {
}
public String describeUndo() {
return "Ignoring undo of " + Transposer.nameFill + " & " + Transposer.nameExtract + " recipe refresh";
}
public Object getOverrideKey() {
return null;
}
}
}