From 4d3d59e4bb403717e9b46efccc969f8ec17ed77d Mon Sep 17 00:00:00 2001 From: HenryLoenwind Date: Sun, 22 Nov 2015 15:19:07 +0100 Subject: [PATCH 1/2] Improve handling of single-input recipes * Single input alloy smelter recipes now will get multi-slot variants added automatically * There's a config flag to disable this * Removed existing partila multi-slot recipes * Fixed code that depends on the order of recipes in a HashMap * Fixed code that depends on the order of machineRecipes in a HashMap --- .../config/AlloySmelterRecipes_Core.xml | 38 ---------------- .../crazypants/enderio/config/Config.java | 8 ++++ .../machine/MachineRecipeRegistry.java | 3 +- .../recipe/ManyToOneRecipeManager.java | 43 +++++++++++++++++-- .../recipe/OreDictionaryRecipeInput.java | 3 +- .../enderio/machine/recipe/RecipeConfig.java | 3 +- .../nei/AlloySmelterRecipeHandler.java | 37 ++++++++++++++-- 7 files changed, 88 insertions(+), 47 deletions(-) diff --git a/resources/assets/enderio/config/AlloySmelterRecipes_Core.xml b/resources/assets/enderio/config/AlloySmelterRecipes_Core.xml index 177d3331..127aa41f 100644 --- a/resources/assets/enderio/config/AlloySmelterRecipes_Core.xml +++ b/resources/assets/enderio/config/AlloySmelterRecipes_Core.xml @@ -145,25 +145,6 @@ - - - - - - - - - - - - - - - - - - - @@ -172,25 +153,6 @@ - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java index 4e9b9f6e..5875ced0 100644 --- a/src/main/java/crazypants/enderio/config/Config.java +++ b/src/main/java/crazypants/enderio/config/Config.java @@ -108,6 +108,7 @@ public final class Config { public static boolean useHardRecipes = false; public static boolean addPeacefulRecipes = false; public static boolean allowExternalTickSpeedup = true; + public static boolean crateSyntheticRecipes = true; public static boolean useSteelInChassi = false; @@ -611,6 +612,13 @@ public final class Config { "The number of conduits crafted per recipe.").getInt(numConduitsPerRecipe); transceiverUseEasyRecipe= config.get(sectionRecipe.name, "transceiverUseEasyRecipe", transceiverUseEasyRecipe, "When enabled the dim trans. will use a cheaper recipe") .getBoolean(useHardRecipes); + crateSyntheticRecipes = config + .get( + sectionRecipe.name, + "crateSyntheticRecipes", + crateSyntheticRecipes, + "Automatically create alloy smelter recipes with double and tripple inputs and different slot allocations (1+1+1, 2+1, 1+2, 3 and 2) for single-input recipes.") + .getBoolean(crateSyntheticRecipes); allowExternalTickSpeedup = config.get(sectionMisc.name, "allowExternalTickSpeedup", allowExternalTickSpeedup, "Allows machines to run faster if another mod speeds up the tickrate. Running at higher tickrates is " diff --git a/src/main/java/crazypants/enderio/machine/MachineRecipeRegistry.java b/src/main/java/crazypants/enderio/machine/MachineRecipeRegistry.java index 793111b8..4fea088e 100644 --- a/src/main/java/crazypants/enderio/machine/MachineRecipeRegistry.java +++ b/src/main/java/crazypants/enderio/machine/MachineRecipeRegistry.java @@ -3,6 +3,7 @@ package crazypants.enderio.machine; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -19,7 +20,7 @@ public class MachineRecipeRegistry { public Map getRecipesForMachine(String machineName) { Map res = machineRecipes.get(machineName); if(res == null) { - res = new HashMap(); + res = new LinkedHashMap(); machineRecipes.put(machineName, res); } return res; diff --git a/src/main/java/crazypants/enderio/machine/recipe/ManyToOneRecipeManager.java b/src/main/java/crazypants/enderio/machine/recipe/ManyToOneRecipeManager.java index fc92da7d..f41e2e96 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/ManyToOneRecipeManager.java +++ b/src/main/java/crazypants/enderio/machine/recipe/ManyToOneRecipeManager.java @@ -77,7 +77,45 @@ public class ManyToOneRecipeManager { List newRecipes = config.getRecipes(false); Log.info("Found " + newRecipes.size() + " valid " + managerName + " recipes in config."); for (Recipe rec : newRecipes) { - addRecipe(new BasicManyToOneRecipe(rec)); + if (Config.crateSyntheticRecipes // + && rec.getInputs().length == 1 && !rec.getInputs()[0].isFluid() + && rec.getInputs()[0].getInput().stackSize <= 21 + && rec.getOutputs().length == 1 && !rec.getOutputs()[0].isFluid() // + && rec.getOutputs()[0].getOutput().stackSize <= 21) { + + IRecipe dupe = getRecipeForInputs(rec.getInputStacks()); + if (dupe != null) { + // do it here because we will add "dupes" and the check need to be + // done on the supplied recipe---which is added last + Log.warn("The supplied recipe " + rec + " for " + managerName + " may be a duplicate to: " + dupe); + } + + int er = rec.getEnergyRequired(); + RecipeBonusType bns = rec.getBonusType(); + RecipeOutput out = rec.getOutputs()[0]; + RecipeInput in = rec.getInputs()[0]; + + RecipeInput in2 = in.copy(); + in2.getInput().stackSize *= 2; + RecipeOutput out2 = new RecipeOutput(out.getOutput(), out.getChance(), out.getExperiance()); + out2.getOutput().stackSize *= 2; + + RecipeInput in3 = in.copy(); + in3.getInput().stackSize *= 3; + RecipeOutput out3 = new RecipeOutput(out.getOutput(), out.getChance(), out.getExperiance()); + out3.getOutput().stackSize *= 3; + + recipes.add(new BasicManyToOneRecipe(new Recipe(out3, er * 3, bns, new RecipeInput[] { in.copy(), in.copy(), in.copy() }))); + recipes.add(new BasicManyToOneRecipe(new Recipe(out3, er * 3, bns, new RecipeInput[] { in.copy(), in2.copy() }))); + recipes.add(new BasicManyToOneRecipe(new Recipe(out3, er * 3, bns, new RecipeInput[] { in2.copy(), in.copy() }))); + recipes.add(new BasicManyToOneRecipe(new Recipe(out2, er * 2, bns, new RecipeInput[] { in.copy(), in.copy() }))); + recipes.add(new BasicManyToOneRecipe(new Recipe(out3, er * 3, bns, new RecipeInput[] { in3.copy() }))); + recipes.add(new BasicManyToOneRecipe(new Recipe(out2, er * 2, bns, new RecipeInput[] { in2.copy() }))); + recipes.add(new BasicManyToOneRecipe(rec)); + Log.info("Created 6 synthetic recipes for " + in.getInput() + " => " + out.getOutput()); + } else { + addRecipe(new BasicManyToOneRecipe(rec)); + } } Log.info("Finished processing " + managerName + " recipes. " + recipes.size() + " recipes avaliable."); } @@ -89,8 +127,7 @@ public class ManyToOneRecipeManager { } IRecipe rec = getRecipeForInputs(recipe.getInputStacks()); if(rec != null) { - Log.warn("Not adding supplied recipe to " + managerName + " as a recipe already exists for the inputs: " + recipe); - return; + Log.warn("The supplied recipe " + recipe + " for " + managerName + " may be a duplicate to: " + rec); } recipes.add(recipe); } diff --git a/src/main/java/crazypants/enderio/machine/recipe/OreDictionaryRecipeInput.java b/src/main/java/crazypants/enderio/machine/recipe/OreDictionaryRecipeInput.java index cb269c50..9f7b04b6 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/OreDictionaryRecipeInput.java +++ b/src/main/java/crazypants/enderio/machine/recipe/OreDictionaryRecipeInput.java @@ -64,7 +64,8 @@ public class OreDictionaryRecipeInput extends RecipeInput { @Override public String toString() { - return "OreDictionaryRecipeInput [oreId=" + oreId + " name=" + OreDictionary.getOreName(oreId) + "]"; + return "OreDictionaryRecipeInput [oreId=" + oreId + " name=" + OreDictionary.getOreName(oreId) + " amount=" + + getInput().stackSize + "]"; } } diff --git a/src/main/java/crazypants/enderio/machine/recipe/RecipeConfig.java b/src/main/java/crazypants/enderio/machine/recipe/RecipeConfig.java index 6bd0b3ef..181254fc 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/RecipeConfig.java +++ b/src/main/java/crazypants/enderio/machine/recipe/RecipeConfig.java @@ -11,6 +11,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -217,7 +218,7 @@ public class RecipeConfig { private final String name; - private Map recipes = new HashMap(); + private Map recipes = new LinkedHashMap(); private boolean enabled = true; diff --git a/src/main/java/crazypants/enderio/nei/AlloySmelterRecipeHandler.java b/src/main/java/crazypants/enderio/nei/AlloySmelterRecipeHandler.java index b873a009..61d3d28d 100644 --- a/src/main/java/crazypants/enderio/nei/AlloySmelterRecipeHandler.java +++ b/src/main/java/crazypants/enderio/nei/AlloySmelterRecipeHandler.java @@ -7,12 +7,15 @@ import java.util.List; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; +import net.minecraftforge.oredict.OreDictionary; import org.lwjgl.opengl.GL11; import com.enderio.core.client.render.EnderWidget; +import com.enderio.core.common.util.ItemUtil; import codechicken.lib.gui.GuiDraw; +import codechicken.nei.ItemList; import codechicken.nei.PositionedStack; import codechicken.nei.recipe.TemplateRecipeHandler; import crazypants.enderio.gui.IconEIO; @@ -122,11 +125,39 @@ public class AlloySmelterRecipeHandler extends TemplateRecipeHandler { result.add(input.getInput()); ItemStack[] equivs = input.getEquivelentInputs(); if(equivs != null) { - for (ItemStack st : equivs) { - result.add(st); + for (ItemStack item : equivs) { + if (item.getItemDamage() == OreDictionary.WILDCARD_VALUE) { + List permutations = ItemList.itemMap.get(item.getItem()); + if (permutations.isEmpty()) { + ItemStack base = new ItemStack(item.getItem(), item.stackSize); + base.stackTagCompound = item.stackTagCompound; + result.add(base); + } else { + for (ItemStack stack : permutations) { + ItemStack perm = stack.copy(); + perm.stackSize = item.stackSize; + result.add(perm); + } + } + } else { + result.add(item.copy()); + } } + List result2 = new ArrayList(); + for (ItemStack candidate : result) { + boolean skip = false; + for (ItemStack existing : result2) { + skip = skip || ItemUtil.areStacksEqual(candidate, existing); + } + if (!skip) { + System.out.println("Adding " + candidate + " for " + input); + result2.add(candidate); + } + } + return result2; + } else { + return result; } - return result; } public class AlloySmelterRecipe extends TemplateRecipeHandler.CachedRecipe { From 396730becd6092f782692c6f9f80e8a07294c3b4 Mon Sep 17 00:00:00 2001 From: HenryLoenwind Date: Sun, 22 Nov 2015 20:01:18 +0100 Subject: [PATCH 2/2] Invalidate recipes where part of the input is missing Otherwise you can craft enderium base with just 2 tin... re IRC --- .../enderio/machine/recipe/RecipeConfig.java | 11 +++++++++-- .../enderio/machine/recipe/RecipeConfigParser.java | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/crazypants/enderio/machine/recipe/RecipeConfig.java b/src/main/java/crazypants/enderio/machine/recipe/RecipeConfig.java index 181254fc..6ddbdcd0 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/RecipeConfig.java +++ b/src/main/java/crazypants/enderio/machine/recipe/RecipeConfig.java @@ -289,6 +289,8 @@ public class RecipeConfig { private String name; + private boolean invalidated = false; + private RecipeElement(String name) { this.name = name; } @@ -323,7 +325,7 @@ public class RecipeConfig { } public boolean isValid() { - return !inputs.isEmpty() && !outputs.isEmpty(); + return !invalidated && !inputs.isEmpty() && !outputs.isEmpty(); } public float getEnergyRequired() { @@ -342,9 +344,14 @@ public class RecipeConfig { this.bonusType = bonusType; } + public void invalidate() { + invalidated = true; + } + @Override public String toString() { - return "Recipe [input=" + inputs + ", outputs=" + outputs + ", energyRequired=" + energyRequired + ", bonusType=" + bonusType + "]"; + return "Recipe [" + (invalidated ? "INVALID " : "") + "input=" + inputs + ", outputs=" + outputs + ", energyRequired=" + + energyRequired + ", bonusType=" + bonusType + "]"; } } diff --git a/src/main/java/crazypants/enderio/machine/recipe/RecipeConfigParser.java b/src/main/java/crazypants/enderio/machine/recipe/RecipeConfigParser.java index cffd72ab..fd31f38b 100644 --- a/src/main/java/crazypants/enderio/machine/recipe/RecipeConfigParser.java +++ b/src/main/java/crazypants/enderio/machine/recipe/RecipeConfigParser.java @@ -342,6 +342,7 @@ public class RecipeConfigParser extends DefaultHandler { private void addInputStack(Attributes attributes) { RecipeInput stack = getItemStack(attributes); if(stack == null) { + recipe.invalidate(); return; } recipe.addInput(stack);