Merge pull request #3030 from HenryLoenwind/combTheDesert

Improve handling of single-input recipes
This commit is contained in:
tterrag committed 2016-02-04 14:52:20 -05:00
commit 4d10ae129c
8 files changed
+98 -49

No files matched your search

@@ -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;
@@ -622,6 +623,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 "
@@ -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<String, IMachineRecipe> getRecipesForMachine(String machineName) {
Map<String, IMachineRecipe> res = machineRecipes.get(machineName);
if(res == null) {
res = new HashMap<String, IMachineRecipe>();
res = new LinkedHashMap<String, IMachineRecipe>();
machineRecipes.put(machineName, res);
}
return res;
@@ -77,7 +77,45 @@ public class ManyToOneRecipeManager {
List<Recipe> 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);
}
@@ -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 + "]";
}
}
@@ -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<String, RecipeElement> recipes = new HashMap<String, RecipeElement>();
private Map<String, RecipeElement> recipes = new LinkedHashMap<String, RecipeElement>();
private boolean enabled = true;
@@ -288,6 +289,8 @@ public class RecipeConfig {
private String name;
private boolean invalidated = false;
private RecipeElement(String name) {
this.name = name;
}
@@ -322,7 +325,7 @@ public class RecipeConfig {
}
public boolean isValid() {
return !inputs.isEmpty() && !outputs.isEmpty();
return !invalidated && !inputs.isEmpty() && !outputs.isEmpty();
}
public float getEnergyRequired() {
@@ -341,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 + "]";
}
}
@@ -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);
@@ -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<ItemStack> 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<ItemStack> result2 = new ArrayList<ItemStack>();
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 {