Added preferences for Ore Dictionary outputs for the SAG Mill and Alloy Furnace. Defaults to Thermal Foundation when available, see OreDictionaryPreferences_Core.xml

This commit is contained in:
CrazyPants committed 2014-12-09 19:03:55 +08:00
1 parent da7ff462b6
commit 25169811df
4 files changed
+120 -5

No files matched your search

@@ -17,6 +17,7 @@ import crazypants.enderio.machine.recipe.IRecipe;
import crazypants.enderio.machine.recipe.Recipe;
import crazypants.enderio.machine.recipe.RecipeInput;
import crazypants.enderio.machine.recipe.RecipeOutput;
import crazypants.enderio.material.OreDictionaryPreferences;
public class VanillaSmeltingRecipe implements IMachineRecipe {
@@ -103,6 +104,7 @@ public class VanillaSmeltingRecipe implements IMachineRecipe {
if(output == null) {
return new ResultStack[0];
}
output = OreDictionaryPreferences.instance.getPreferred(output);
ItemStack result = output.copy();
result.stackSize = result.stackSize * getNumInputs(inputs);
return new ResultStack[] { new ResultStack(result) };
@@ -165,7 +167,9 @@ public class VanillaSmeltingRecipe implements IMachineRecipe {
List<IRecipe> result = new ArrayList<IRecipe>();
Map<ItemStack, ItemStack> metaList = FurnaceRecipes.smelting().getSmeltingList();
for (Entry<ItemStack, ItemStack> entry : metaList.entrySet()) {
result.add(new Recipe(new RecipeInput(entry.getKey()), RF_PER_ITEM, new RecipeOutput(entry.getValue())));
ItemStack output = entry.getValue();
output = OreDictionaryPreferences.instance.getPreferred(output);
result.add(new Recipe(new RecipeInput(entry.getKey()), RF_PER_ITEM, new RecipeOutput(output)));
}
return result;
}
@@ -4,9 +4,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import crazypants.util.OreDictionaryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import crazypants.util.OreDictionaryHelper;
public final class OreDictionaryPreferences {
@@ -17,6 +18,7 @@ public final class OreDictionaryPreferences {
}
private Map<String, ItemStack> preferences = new HashMap<String, ItemStack>();
private Map<StackKey, ItemStack> stackCache = new HashMap<StackKey, ItemStack>();
public void setPreference(String oreDictName, ItemStack stack) {
if(oreDictName == null || stack == null) {
@@ -39,4 +41,77 @@ public final class OreDictionaryPreferences {
return result;
}
public ItemStack getPreferred(ItemStack stack) {
if(stack == null) {
return null;
}
StackKey key = new StackKey(stack);
if(stackCache.containsKey(key)) {
return stackCache.get(key);
}
ItemStack result = null;
int[] ids = OreDictionary.getOreIDs(stack);
if(ids != null) {
for (int i = 0; i < ids.length && result == null; i++) {
String oreDict = OreDictionary.getOreName(ids[i]);
if(preferences.containsKey(oreDict)) {
result = preferences.get(oreDict);
}
}
}
if(result == null) {
result = stack;
}
stackCache.put(key, result);
return stack;
}
private static class StackKey {
Item item;
int damage;
StackKey(ItemStack stack) {
item = stack.getItem();
damage = stack.getItemDamage();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + damage;
result = prime * result + ((item == null) ? 0 : item.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if(this == obj) {
return true;
}
if(obj == null) {
return false;
}
if(getClass() != obj.getClass()) {
return false;
}
StackKey other = (StackKey) obj;
if(damage != other.damage) {
return false;
}
if(item == null) {
if(other.item != null) {
return false;
}
} else if(!item.equals(other.item)) {
return false;
}
return true;
}
}
}