Continuing work

- Fixed bugs in BaseMap-Addition/Removal
- Reworked handlers for TE Transposer & Smelter
- Added recipe logging for TE Transposer & Smelter
This commit is contained in:
Zixxl committed 2015-07-03 17:09:37 +02:00
1 parent 149d52bb6c
commit 40605f5fa9
13 files changed
+380 -265

No files matched your search

+6
View File
@@ -19,6 +19,7 @@ import modtweaker2.mods.tconstruct.MaterialLogger;
import modtweaker2.mods.tconstruct.commands.TConstructLogger;
import modtweaker2.mods.thaumcraft.commands.AspectLogger;
import modtweaker2.mods.thaumcraft.research.commands.ResearchLogger;
import modtweaker2.mods.thermalexpansion.commands.ThermalExpansionLogger;
import modtweaker2.utils.TweakerPlugin;
public class Commands {
@@ -66,9 +67,14 @@ public class Commands {
MineTweakerAPI.server.addMineTweakerCommand("chiselGroups", new String[] { "/minetweaker chiselGroups", " Outputs a list of chisel groups" }, new ChiselGroupLogger());
MineTweakerAPI.server.addMineTweakerCommand("chiselVariations", new String[] { "/minetweaker chiselVariations", "/minetweaker chiselVariations [GROUP]", " Outputs a list of chisel variations" }, new ChiselVariationLogger());
}
if (TweakerPlugin.isLoaded("aura")) {
MineTweakerAPI.server.addMineTweakerCommand("auras", new String[] { "/minetweaker auras", "Outputs a list of Aura Types" }, new AuraLogger());
}
if (TweakerPlugin.isLoaded("ThermalExpansion")) {
MineTweakerAPI.server.addMineTweakerCommand("texpansion", new String[] {"/minetweaker texpansion [FILTER]", " Outputs a list of all Thermal Expansion recipes."}, new ThermalExpansionLogger());
}
}
}
@@ -88,14 +88,19 @@ public class InputHelper {
}
}
public static String getArrayDescription(List objects) {
public static String getArrayDescription(List objects) {
StringBuilder sb = new StringBuilder();
sb.append('[');
for(Object object : objects) {
sb.append(InputHelper.getStackDescription(object)).append(", ");
if(objects.isEmpty()) {
sb.append("[]");
} else {
sb.append('[');
for(Object object : objects) {
sb.append(InputHelper.getStackDescription(object)).append(", ");
}
sb.setLength(sb.length() - 2);
sb.append(']');
}
sb.setLength(sb.length() - 2);
sb.append(']');
return sb.toString();
}
@@ -28,7 +28,9 @@ public class AppliedEnergisticsLogger implements ICommandFunction {
List<String> args = StringHelper.toLowerCase(Arrays.asList(arguments));
if(!validArguments.containsAll(args)) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + StringHelper.join(validArguments, ", ")));
if(player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + StringHelper.join(validArguments, ", ")));
}
} else {
if(args.isEmpty() || args.contains("grinder")) {
for(IGrinderEntry recipe : AEApi.instance().registries().grinder().getRecipes()) {
@@ -32,7 +32,9 @@ public class BotaniaLogger implements ICommandFunction {
List<String> args = StringHelper.toLowerCase(Arrays.asList(arguments));
if(!validArguments.containsAll(args)) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + StringHelper.join(validArguments, ", ")));
if(player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + StringHelper.join(validArguments, ", ")));
}
} else {
if(args.isEmpty() || args.contains("apothecary")) {
for(RecipePetals recipe : BotaniaAPI.petalRecipes) {
@@ -35,7 +35,9 @@ public class TConstructLogger implements ICommandFunction {
List<String> args = StringHelper.toLowerCase(Arrays.asList(arguments));
if(!validArguments.containsAll(args)) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + StringHelper.join(validArguments, ", ")));
if(player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + StringHelper.join(validArguments, ", ")));
}
} else {
if(args.isEmpty() || args.contains("casting")) {
for(CastingRecipe recipe : TConstructHelper.basinCasting) {
@@ -11,15 +11,16 @@ import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import cofh.lib.inventory.ComparableItemStackSafe;
import cofh.thermalexpansion.util.crafting.SmelterManager.ComparableItemStackSmelter;
import cofh.thermalexpansion.util.crafting.SmelterManager.RecipeSmelter;
import cofh.thermalexpansion.util.crafting.TransposerManager.RecipeTransposer;
public class ThermalHelper {
private static Map<List, RecipeSmelter> smelter;
public static Set<ComparableItemStackSafe> smelterValid;
private static Map<List<ComparableItemStackSmelter>, RecipeSmelter> smelter;
public static Set<ComparableItemStackSmelter> smelterValid;
private static Map crucible;
private static Map<List, RecipeTransposer> transposerFill;
private static Map<List<Integer>, RecipeTransposer> transposerFill;
private static Map<ComparableItemStackSafe, RecipeTransposer> transposerEmpty;
public static Set<ComparableItemStackSafe> transposerValid;
@@ -34,7 +35,7 @@ public class ThermalHelper {
}
/** Need to perform this reflection on the fly as the map is ALWAYS changing, thanks to the way that te handles stuff */
public static Map<List, RecipeSmelter> getSmelterMap() {
public static Map<List<ComparableItemStackSmelter>, RecipeSmelter> getSmelterMap() {
try {
smelter = getStaticObject(Class.forName("cofh.thermalexpansion.util.crafting.SmelterManager"), "recipeMap");
smelterValid = getStaticObject(Class.forName("cofh.thermalexpansion.util.crafting.SmelterManager"), "validationSet");
@@ -43,7 +44,7 @@ public class ThermalHelper {
return smelter;
}
public static Map<List, RecipeTransposer> getFillMap() {
public static Map<List<Integer>, RecipeTransposer> getFillMap() {
try {
transposerFill = getStaticObject(Class.forName("cofh.thermalexpansion.util.crafting.TransposerManager"), "recipeMapFill");
transposerValid = getStaticObject(Class.forName("cofh.thermalexpansion.util.crafting.TransposerManager"), "validationSet");
@@ -0,0 +1,81 @@
package modtweaker2.mods.thermalexpansion.commands;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import minetweaker.MineTweakerAPI;
import minetweaker.MineTweakerImplementationAPI;
import minetweaker.api.player.IPlayer;
import minetweaker.api.server.ICommandFunction;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.StringHelper;
import modtweaker2.mods.thermalexpansion.ThermalHelper;
import cofh.thermalexpansion.util.crafting.SmelterManager.RecipeSmelter;
import cofh.thermalexpansion.util.crafting.TransposerManager.RecipeTransposer;
public class ThermalExpansionLogger implements ICommandFunction {
private static final List<String> validArguments = new LinkedList<String>();
static {
validArguments.add("crucible");
validArguments.add("furnace");
validArguments.add("pulverizer");
validArguments.add("sawmill");
validArguments.add("transposer");
}
@Override
public void execute(String[] arguments, IPlayer player) {
List<String> args = StringHelper.toLowerCase(Arrays.asList(arguments));
if(!validArguments.containsAll(args)) {
if(player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("Invalid arguments for command. Valid arguments: " + StringHelper.join(validArguments, ", ")));
}
} else {
if(args.isEmpty() || args.contains("smelter")) {
for(RecipeSmelter recipe : ThermalHelper.getSmelterMap().values()) {
if(recipe.getSecondaryOutput() != null) {
MineTweakerAPI.logCommand(String.format("mods.thermalexpansion.Smelter.addRecipe(%d, %s, %s, %s, %s, %d);",
recipe.getEnergy(),
InputHelper.getStackDescription(recipe.getPrimaryInput()),
InputHelper.getStackDescription(recipe.getSecondaryInput()),
InputHelper.getStackDescription(recipe.getPrimaryOutput()),
InputHelper.getStackDescription(recipe.getSecondaryOutput()),
recipe.getSecondaryOutputChance()));
} else {
MineTweakerAPI.logCommand(String.format("mods.thermalexpansion.Smelter.addRecipe(%d, %s, %s, %s);",
recipe.getEnergy(),
InputHelper.getStackDescription(recipe.getPrimaryInput()),
InputHelper.getStackDescription(recipe.getSecondaryInput()),
InputHelper.getStackDescription(recipe.getPrimaryOutput())));
}
}
}
if(args.isEmpty() || args.contains("transposer")) {
for(RecipeTransposer recipe : ThermalHelper.getFillMap().values()) {
MineTweakerAPI.logCommand(String.format("mods.thermalexpansion.Transposer.addFillRecipe(%d, %s, %s, %s);",
recipe.getEnergy(),
InputHelper.getStackDescription(recipe.getInput()),
InputHelper.getStackDescription(recipe.getOutput()),
InputHelper.getStackDescription(recipe.getFluid())));
}
for(RecipeTransposer recipe : ThermalHelper.getExtractMap().values()) {
MineTweakerAPI.logCommand(String.format("mods.thermalexpansion.Transposer.addExtractRecipe(%d, %s, %s, %s, %d);",
recipe.getEnergy(),
InputHelper.getStackDescription(recipe.getInput()),
InputHelper.getStackDescription(recipe.getOutput()),
InputHelper.getStackDescription(recipe.getFluid()),
recipe.getChance()));
}
}
if (player != null) {
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("List generated; see minetweaker.log in your minecraft dir"));
}
}
}
}
@@ -1,38 +1,34 @@
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.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.mods.thermalexpansion.ThermalHelper;
import modtweaker2.utils.BaseMultiModification;
import modtweaker2.utils.BaseMapAddition;
import modtweaker2.utils.BaseMapRemoval;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import cofh.lib.inventory.ComparableItemStackSafe;
import cofh.thermalexpansion.util.crafting.SmelterManager;
import cofh.thermalexpansion.util.crafting.SmelterManager.ComparableItemStackSmelter;
import cofh.thermalexpansion.util.crafting.SmelterManager.RecipeSmelter;
@ZenClass("mods.thermalexpansion.Smelter")
public class Smelter {
private static boolean removeValidated(ComparableItemStackSafe stack) {
for (Map.Entry entry : ThermalHelper.getSmelterMap().entrySet()) {
if (entry != null && entry.getValue() != null) {
RecipeSmelter recipe = (RecipeSmelter) entry.getValue();
if (recipe != null) {
if (stack.equals(new ComparableItemStackSafe(recipe.getPrimaryInput()))) {
return false;
} else if (stack.equals(new ComparableItemStackSafe(recipe.getSecondaryInput()))) {
return false;
}
}
}
}
return ThermalHelper.smelterValid.remove(stack);
}
public static final String name = "Thermal Expansion Smelter";
@ZenMethod
public static void addRecipe(int energy, IItemStack input, IItemStack input2, IItemStack output) {
@@ -45,94 +41,86 @@ public class Smelter {
ItemStack in2 = toStack(input2);
ItemStack out1 = toStack(output);
ItemStack out2 = toStack(output2);
RecipeSmelter recipe = (RecipeSmelter) ThermalHelper.getTERecipe(ThermalHelper.smelterRecipe, in1, in2, out1, out2, chance, energy);
MineTweakerAPI.apply(new Add(in1, in2, recipe));
List<ComparableItemStackSmelter> key = Arrays.asList(new ComparableItemStackSmelter[] { new ComparableItemStackSmelter(in1), new ComparableItemStackSmelter(in2) });
RecipeSmelter value = (RecipeSmelter) ThermalHelper.getTERecipe(ThermalHelper.smelterRecipe, in1, in2, out1, out2, chance, energy);
Map<List<ComparableItemStackSmelter>, RecipeSmelter> recipes = new HashMap<List<ComparableItemStackSmelter>, RecipeSmelter>();
recipes.put(key, value);
MineTweakerAPI.apply(new Add(recipes));
}
private static class Add extends BaseMultiModification {
private final ComparableItemStackSafe input1;
private final ComparableItemStackSafe input2;
private final List key;
private final RecipeSmelter recipe;
public Add(ItemStack input1, ItemStack input2, RecipeSmelter recipe) {
super("Induction Smelter");
this.input1 = new ComparableItemStackSafe(input1);
this.input2 = new ComparableItemStackSafe(input2);
this.key = (Arrays.asList(new ComparableItemStackSafe[] { this.input1, this.input2 }));
this.recipe = recipe;
private static class Add extends BaseMapAddition<List<ComparableItemStackSmelter>, RecipeSmelter> {
public Add(Map<List<ComparableItemStackSmelter>, RecipeSmelter> recipes) {
super(Smelter.name, ThermalHelper.getSmelterMap(), recipes);
}
@Override
public void apply() {
ThermalHelper.getSmelterMap().put(key, recipe);
ThermalHelper.smelterValid.add(input1);
ThermalHelper.smelterValid.add(input2);
}
@Override
public boolean canUndo() {
return ThermalHelper.getSmelterMap() != null;
map = ThermalHelper.getSmelterMap();
super.apply();
SmelterManager.refreshRecipes();
}
@Override
public void undo() {
ThermalHelper.getSmelterMap().remove(key);
removeValidated(input1);
removeValidated(input2);
map = ThermalHelper.getSmelterMap();
super.undo();
SmelterManager.refreshRecipes();
}
@Override
public String getRecipeInfo() {
return ((RecipeSmelter) recipe).getPrimaryOutput().getDisplayName();
public String getRecipeInfo(Entry<List<ComparableItemStackSmelter>, RecipeSmelter> recipe) {
return InputHelper.getStackDescription(recipe.getValue().getPrimaryOutput());
}
}
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeRecipe(IItemStack input, IItemStack input2) {
MineTweakerAPI.apply(new Remove(toStack(input), toStack(input2)));
public static void removeRecipe(IIngredient input1, IIngredient input2) {
Map<List<ComparableItemStackSmelter>, RecipeSmelter> recipes = new HashMap<List<ComparableItemStackSmelter>, RecipeSmelter>();
for(Entry<List<ComparableItemStackSmelter>, RecipeSmelter> entry : ThermalHelper.getSmelterMap().entrySet()) {
RecipeSmelter recipe = entry.getValue();
if(recipe != null && matches(input1, toIItemStack(recipe.getPrimaryInput())) && matches(input2, toIItemStack(recipe.getSecondaryInput()))) {
recipes.put(entry.getKey(), entry.getValue());
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new Remove(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipes found for %s and %s. Command ignored!", Smelter.name, input1.toString(), input2.toString()));
}
}
private static class Remove extends BaseMultiModification {
private final ComparableItemStackSafe input1;
private final ComparableItemStackSafe input2;
private final List key;
private RecipeSmelter recipe;
private static class Remove extends BaseMapRemoval<List<ComparableItemStackSmelter>, RecipeSmelter> {
public Remove(ItemStack input1, ItemStack input2) {
super("Induction Smelter");
this.input1 = new ComparableItemStackSafe(input1);
this.input2 = new ComparableItemStackSafe(input2);
this.key = (Arrays.asList(new ComparableItemStackSafe[] { this.input1, this.input2 }));
public Remove(Map<List<ComparableItemStackSmelter>, RecipeSmelter> recipes) {
super(Smelter.name, ThermalHelper.getSmelterMap(), recipes);
}
@Override
public void apply() {
recipe = ThermalHelper.getSmelterMap().get(key);
ThermalHelper.getSmelterMap().remove(key);
removeValidated(input1);
removeValidated(input2);
map = ThermalHelper.getSmelterMap();
super.apply();
SmelterManager.refreshRecipes();
}
@Override
public boolean canUndo() {
return ThermalHelper.getSmelterMap() != null;
}
@Override
public void undo() {
ThermalHelper.getSmelterMap().put(key, recipe);
ThermalHelper.smelterValid.add(input1);
ThermalHelper.smelterValid.add(input2);
map = ThermalHelper.getSmelterMap();
super.undo();
SmelterManager.refreshRecipes();
}
@Override
public String getRecipeInfo() {
return input1.toItemStack().getDisplayName() + " + " + input2.toItemStack().getDisplayName();
}
@Override
public String getRecipeInfo(Entry<List<ComparableItemStackSmelter>, RecipeSmelter> recipe) {
return InputHelper.getStackDescription(recipe.getValue().getPrimaryOutput());
}
}
}
@@ -1,182 +1,208 @@
package modtweaker2.mods.thermalexpansion.handlers;
import static modtweaker2.helpers.InputHelper.toFluid;
import static modtweaker2.helpers.InputHelper.toIItemStack;
import static modtweaker2.helpers.InputHelper.toILiquidStack;
import static modtweaker2.helpers.InputHelper.toStack;
import static modtweaker2.helpers.StackHelper.matches;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import minetweaker.api.liquid.ILiquidStack;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.mods.thermalexpansion.ThermalHelper;
import modtweaker2.utils.BaseUndoable;
import modtweaker2.utils.BaseMapAddition;
import modtweaker2.utils.BaseMapRemoval;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import cofh.lib.inventory.ComparableItemStackSafe;
import cofh.thermalexpansion.util.crafting.TransposerManager;
import cofh.thermalexpansion.util.crafting.TransposerManager.RecipeTransposer;
@ZenClass("mods.thermalexpansion.Transposer")
public class Transposer {
private static boolean removeValidated(ComparableItemStackSafe stack) {
// Check if there is a recipe that requires this in the validation set
// for filling
for (Map.Entry entry : ThermalHelper.getFillMap().entrySet()) {
RecipeTransposer recipe = (RecipeTransposer) entry.getValue();
if (stack.equals(new ComparableItemStackSafe(recipe.getInput()))) {
return false;
}
}
// Check if there is a recipe that requires this in the validation set
// for extracting
for (Map.Entry entry : ThermalHelper.getExtractMap().entrySet()) {
RecipeTransposer recipe = (RecipeTransposer) entry.getValue();
if (stack.equals(new ComparableItemStackSafe(recipe.getInput()))) {
return false;
}
}
return ThermalHelper.transposerValid.remove(stack);
}
public static final String nameFill = "Thermal Expansion Transposer (Fill)";
public static final String nameExtract = "Thermal Expansion Transposer (Extract)";
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void addFillRecipe(int energy, IItemStack input, IItemStack output, ILiquidStack liquid) {
addRecipe(energy, input, output, liquid, 100, true);
Map<List<Integer>, RecipeTransposer> recipes = new HashMap<List<Integer>, RecipeTransposer>();
ItemStack in = toStack(input);
ItemStack out = toStack(output);
FluidStack fluid = toFluid(liquid);
List<Integer> key = Arrays.asList(new Integer[] { Integer.valueOf(new ComparableItemStackSafe(in).hashCode()), Integer.valueOf(fluid.fluidID) });
RecipeTransposer value = (RecipeTransposer) ThermalHelper.getTERecipe(ThermalHelper.transposerRecipe, in, out, fluid, energy, 100);
recipes.put(key, value);
MineTweakerAPI.apply(new AddFill(recipes));
}
@ZenMethod
public static void addExtractRecipe(int energy, IItemStack input, IItemStack output, ILiquidStack liquid, int chance) {
addRecipe(energy, input, output, liquid, chance, false);
Map<ComparableItemStackSafe, RecipeTransposer> recipes = new HashMap<ComparableItemStackSafe, RecipeTransposer>();
ItemStack in = toStack(input);
ItemStack out = toStack(output);
FluidStack fluid = toFluid(liquid);
ComparableItemStackSafe key = new ComparableItemStackSafe(in);
RecipeTransposer value = (RecipeTransposer) ThermalHelper.getTERecipe(ThermalHelper.transposerRecipe, in, out, fluid, energy, 100);
recipes.put(key, value);
MineTweakerAPI.apply(new AddExtract(recipes));
}
private static class AddFill extends BaseMapAddition<List<Integer>, RecipeTransposer> {
protected AddFill(Map<List<Integer>, RecipeTransposer> recipes) {
super(Transposer.nameFill, ThermalHelper.getFillMap());
recipes.putAll(recipes);
}
@Override
public void apply() {
map = ThermalHelper.getFillMap();
super.apply();
TransposerManager.refreshRecipes();
}
@Override
public void undo() {
map = ThermalHelper.getFillMap();
super.undo();
TransposerManager.refreshRecipes();
}
@Override
protected String getRecipeInfo(Entry<List<Integer>, RecipeTransposer> recipe) {
return InputHelper.getStackDescription(recipe.getValue().getOutput());
}
}
private static class AddExtract extends BaseMapAddition<ComparableItemStackSafe, RecipeTransposer> {
protected AddExtract(Map<ComparableItemStackSafe, RecipeTransposer> recipes) {
super(Transposer.nameFill, ThermalHelper.getExtractMap());
recipes.putAll(recipes);
}
@Override
public void apply() {
map = ThermalHelper.getExtractMap();
super.apply();
TransposerManager.refreshRecipes();
}
@Override
public void undo() {
map = ThermalHelper.getExtractMap();
super.undo();
TransposerManager.refreshRecipes();
}
@Override
protected String getRecipeInfo(Entry<ComparableItemStackSafe, RecipeTransposer> recipe) {
return InputHelper.getStackDescription(recipe.getValue().getInput());
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeFillRecipe(IIngredient input, IIngredient liquid) {
Map<List<Integer>, RecipeTransposer> recipes = new HashMap<List<Integer>, RecipeTransposer>();
for(Entry<List<Integer>, RecipeTransposer> recipe : ThermalHelper.getFillMap().entrySet()) {
if(recipe != null && recipe.getValue() != null && matches(input, toIItemStack(recipe.getValue().getInput())) && matches(liquid, toILiquidStack(recipe.getValue().getFluid()))) {
recipes.put(recipe.getKey(), recipe.getValue());
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new RemoveFill(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipe found for %s and %s. Command ignored!", nameFill, input.toString(), liquid.toString()));
}
}
@ZenMethod
public static void addRecipe(int energy, IItemStack input, IItemStack output, ILiquidStack liquid, int chance, boolean isFillRecipe) {
ItemStack in = toStack(input);
ItemStack out = toStack(output);
FluidStack fluid = toFluid(liquid);
RecipeTransposer recipe = (RecipeTransposer) ThermalHelper.getTERecipe(ThermalHelper.transposerRecipe, in, out, fluid, energy, chance);
MineTweakerAPI.apply(new Add(in, fluid, recipe, isFillRecipe));
public static void removeExtractRecipe(IIngredient input) {
Map<ComparableItemStackSafe, RecipeTransposer> recipes = new HashMap<ComparableItemStackSafe, RecipeTransposer>();
for(Entry<ComparableItemStackSafe, RecipeTransposer> recipe : ThermalHelper.getExtractMap().entrySet()) {
if(recipe != null && recipe.getValue() != null && matches(input, toIItemStack(recipe.getValue().getInput()))) {
recipes.put(recipe.getKey(), recipe.getValue());
}
}
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new RemoveExtract(recipes));
} else {
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", nameFill, input.toString()));
}
}
private static class Add extends BaseUndoable {
private List key;
private boolean isFillRecipe;
private final ComparableItemStackSafe input;
private final RecipeTransposer recipe;
private static class RemoveFill extends BaseMapRemoval<List<Integer>, RecipeTransposer> {
public Add(ItemStack input, FluidStack fluid, RecipeTransposer recipe, boolean isFillRecipe) {
super("Transposer");
this.isFillRecipe = isFillRecipe;
this.input = new ComparableItemStackSafe(input);
protected RemoveFill(Map<List<Integer>, RecipeTransposer> recipes) {
super(nameFill, ThermalHelper.getFillMap(), recipes);
}
@Override
public void apply() {
map = ThermalHelper.getFillMap();
super.apply();
TransposerManager.refreshRecipes();
}
@Override
public void undo() {
map = ThermalHelper.getFillMap();
super.undo();
TransposerManager.refreshRecipes();
}
this.recipe = recipe;
if (this.isFillRecipe) {
this.key = Arrays.asList(new Integer[] { Integer.valueOf(new ComparableItemStackSafe(input).hashCode()), Integer.valueOf(fluid.fluidID) });
}
}
@Override
public void apply() {
if (isFillRecipe) {
ThermalHelper.getFillMap().put(key, recipe);
} else {
ThermalHelper.getExtractMap().put(input, recipe);
}
ThermalHelper.transposerValid.add(input);
}
@Override
public boolean canUndo() {
return input != null;
}
@Override
public void undo() {
if (isFillRecipe) {
ThermalHelper.getFillMap().remove(key);
} else {
ThermalHelper.getExtractMap().remove(input);
}
removeValidated(input);
}
@Override
public String getRecipeInfo() {
return ((RecipeTransposer) recipe).getOutput().getDisplayName();
}
@Override
protected String getRecipeInfo(Entry<List<Integer>, RecipeTransposer> recipe) {
return InputHelper.getStackDescription(recipe.getValue().getOutput());
}
}
private static class RemoveExtract extends BaseMapRemoval<ComparableItemStackSafe, RecipeTransposer> {
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ZenMethod
public static void removeFillRecipe(IItemStack input, ILiquidStack liquid) {
removeRecipe(input, liquid, true);
}
protected RemoveExtract(Map<ComparableItemStackSafe, RecipeTransposer> recipes) {
super(nameExtract, ThermalHelper.getExtractMap(), recipes);
}
@Override
public void apply() {
map = ThermalHelper.getExtractMap();
super.apply();
TransposerManager.refreshRecipes();
}
@Override
public void undo() {
map = ThermalHelper.getExtractMap();
super.undo();
TransposerManager.refreshRecipes();
}
@ZenMethod
public static void removeExtractRecipe(IItemStack input) {
removeRecipe(input, null, false);
}
@ZenMethod
public static void removeRecipe(IItemStack input, ILiquidStack liquid, boolean isFillRecipe) {
MineTweakerAPI.apply(new Remove(toStack(input), toFluid(liquid), isFillRecipe));
}
private static class Remove extends BaseUndoable {
private final boolean isFillRecipe;
private final ComparableItemStackSafe input;
private List key;
private RecipeTransposer recipe;
public Remove(ItemStack input, FluidStack fluid, boolean isFillRecipe) {
super("Transposer");
this.isFillRecipe = isFillRecipe;
this.input = new ComparableItemStackSafe(input);
if (this.isFillRecipe) {
this.key = Arrays.asList(new Integer[] { Integer.valueOf(new ComparableItemStackSafe(input).hashCode()), Integer.valueOf(fluid.fluidID) });
}
}
@Override
public void apply() {
if (isFillRecipe) {
recipe = ThermalHelper.getFillMap().get(key);
ThermalHelper.getFillMap().remove(key);
} else {
recipe = ThermalHelper.getExtractMap().get(input);
ThermalHelper.getExtractMap().remove(input);
}
removeValidated(input);
}
@Override
public boolean canUndo() {
return input != null;
}
@Override
public void undo() {
if (isFillRecipe) {
ThermalHelper.getFillMap().put(key, recipe);
} else {
ThermalHelper.getExtractMap().put(input, recipe);
}
ThermalHelper.transposerValid.add(input);
}
@Override
public String getRecipeInfo() {
return input.toItemStack().getDisplayName();
}
}
@Override
protected String getRecipeInfo(Entry<ComparableItemStackSafe, RecipeTransposer> recipe) {
return InputHelper.getStackDescription(recipe.getValue().getInput());
}
}
}
@@ -25,13 +25,13 @@ public abstract class BaseListAddition<T> extends BaseListModification<T> {
for(T recipe : recipes) {
if(recipe != null) {
if(this.list.add(recipe)) {
if(list.add(recipe)) {
successful.add(recipe);
} else {
LogHelper.logError(String.format("Error adding %s Recipe for %s", this.name, this.getRecipeInfo(recipe)));
LogHelper.logError(String.format("Error adding %s Recipe for %s", name, getRecipeInfo(recipe)));
}
} else {
LogHelper.logError(String.format("Error adding %s Recipe: null object", this.name));
LogHelper.logError(String.format("Error adding %s Recipe: null object", name));
}
}
}
@@ -44,22 +44,22 @@ public abstract class BaseListAddition<T> extends BaseListModification<T> {
for(T recipe : successful) {
if(recipe != null) {
if(!this.list.remove(recipe)) {
LogHelper.logError(String.format("Error removing %s Recipe for %s", this.name, this.getRecipeInfo(recipe)));
if(!list.remove(recipe)) {
LogHelper.logError(String.format("Error removing %s Recipe for %s", name, this.getRecipeInfo(recipe)));
}
} else {
LogHelper.logError(String.format("Error removing %s Recipe: null object", this.name));
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
}
}
}
@Override
public String describe() {
return String.format("[ModTweaker2] Adding %d %s Recipe(s) for %s", this.recipes.size(), this.name, this.getRecipeInfo());
return String.format("[ModTweaker2] Adding %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
}
@Override
public String describeUndo() {
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", this.recipes.size(), this.name, this.getRecipeInfo());
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
}
}
@@ -18,7 +18,7 @@ public abstract class BaseMapAddition<K, V> extends BaseMapModification<K, V> {
protected BaseMapAddition(String name, Map<K, V> map, Map<K, V> recipes) {
this(name, map);
recipes.putAll(recipes);
this.recipes.putAll(recipes);
}
@Override
@@ -27,37 +27,39 @@ public abstract class BaseMapAddition<K, V> extends BaseMapModification<K, V> {
return;
for(Entry<K, V> entry : recipes.entrySet()) {
V value = map.put(entry.getKey(), entry.getValue());
if(value != null) {
K key = entry.getKey();
V value = entry.getValue();
V oldValue = map.put(key, value);
if(oldValue != null) {
LogHelper.logWarning(String.format("Overwritten %s Recipe for %s", name, getRecipeInfo( new AbstractMap.SimpleEntry<K, V>(entry.getKey(), value))));
overwritten.put(entry.getKey(), value);
overwritten.put(key, oldValue);
}
successful.put(entry.getKey(), entry.getValue());
successful.put(key, value);
}
}
@Override
public void undo() {
if(successful.isEmpty() || overwritten.isEmpty())
if(successful.isEmpty() && overwritten.isEmpty())
return;
for(K key : recipes.keySet()) {
map.remove(key);
}
for(Entry<K, V> entry : successful.entrySet()) {
V value = map.remove(entry.getKey());
K key = entry.getKey();
V value = map.remove(key);
if(value == null) {
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
}
}
for(Entry<K, V> entry : overwritten.entrySet()) {
V value = map.put(entry.getKey(), entry.getValue());
K key = entry.getKey();
V value = entry.getValue();
V oldValue = map.put(key, value);
if(value != null) {
if(oldValue != null) {
LogHelper.logWarning(String.format("Overwritten %s Recipe which should not exist for %s", name, getRecipeInfo(new AbstractMap.SimpleEntry<K, V>(entry.getKey(), value))));
}
}
@@ -65,11 +67,11 @@ public abstract class BaseMapAddition<K, V> extends BaseMapModification<K, V> {
@Override
public String describe() {
return String.format("Adding %d %s Recipe(s) for %d", recipes.size(), name, getRecipeInfo());
return String.format("Adding %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
}
@Override
public String describeUndo() {
return String.format("Removing %d %s Recipe(s) for %d", recipes.size(), name, getRecipeInfo());
return String.format("Removing %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
}
}
@@ -5,7 +5,7 @@ import java.util.Map;
import java.util.Map.Entry;
public abstract class BaseMapModification<K, V> extends BaseUndoable {
protected final Map<K, V> map;
protected Map<K, V> map;
protected final HashMap<K, V> recipes;
protected final HashMap<K, V> successful;
@@ -25,10 +25,10 @@ public abstract class BaseMapRemoval<K, V> extends BaseMapModification<K, V> {
return;
for(K key : recipes.keySet()) {
V value = map.remove(key);
V oldValue = map.remove(key);
if(value != null) {
successful.put(key, value);
if(oldValue != null) {
successful.put(key, oldValue);
} else {
LogHelper.logError(String.format("Error removing %s Recipe : null object", name));
}
@@ -42,8 +42,8 @@ public abstract class BaseMapRemoval<K, V> extends BaseMapModification<K, V> {
for(Entry<K, V> entry : successful.entrySet()) {
if(entry != null) {
V value = map.put(entry.getKey(), entry.getValue());
if(value != null) {
V oldValue = map.put(entry.getKey(), entry.getValue());
if(oldValue != null) {
LogHelper.logWarning(String.format("Overwritten %s Recipe for %s while restoring.", name, getRecipeInfo(entry)));
}
}
@@ -52,11 +52,11 @@ public abstract class BaseMapRemoval<K, V> extends BaseMapModification<K, V> {
@Override
public String describe() {
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %d", this.recipes.size(), this.name);
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
}
@Override
public String describeUndo() {
return String.format("[ModTweaker2] Restoring %d %s Recipe(s) for %d", this.recipes.size(), this.name);
return String.format("[ModTweaker2] Restoring %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
}
}