Primitive first pass at a ItemStack comparator, and some more functionality for the RecipeHelper

This commit is contained in:
pahimar 2013-05-18 00:33:23 -04:00
parent 97f9daccc9
commit d6367c90fd
2 changed files with 64 additions and 20 deletions

View file

@ -2,6 +2,7 @@ package com.pahimar.ee3.core.helper;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -21,6 +22,19 @@ import com.pahimar.ee3.lib.Strings;
public class ItemHelper {
private static double rand;
public static boolean compare(ItemStack first, ItemStack second) {
if ((first != null) && (second != null)) {
if (first.itemID == second.itemID) {
if (first.getItemDamage() == second.getItemDamage()) {
return true;
}
}
}
return false;
}
public static boolean hasColor(ItemStack itemStack) {

View file

@ -26,13 +26,19 @@ import cpw.mods.fml.common.registry.GameRegistry;
*/
public class RecipeHelper {
@SuppressWarnings("unchecked")
// TODO: Not ideal, can be cleaned up further
public static List getRecipeInputs(IRecipe recipe) {
/**
* Returns a list of ItemStacks that represent the itemstacks that make up the given IRecipe
*
* @param recipe The IRecipe being examined
* @return List of ItemStacks that constitute the inputs of the recipe, null if unable to access the inputs of the given IRecipe
*/
public static ArrayList<ItemStack> getRecipeInputs(IRecipe recipe) {
ArrayList<ItemStack> recipeInputs = null;
if (recipe instanceof ShapedRecipes) {
ShapedRecipes shapedRecipe = (ShapedRecipes) recipe;
ArrayList<ItemStack> recipeInputs = new ArrayList<ItemStack>();
recipeInputs = new ArrayList<ItemStack>();
for (int i = 0; i < shapedRecipe.recipeItems.length; i++) {
if (shapedRecipe.recipeItems[i] != null) {
@ -43,43 +49,67 @@ public class RecipeHelper {
return recipeInputs;
}
else if (recipe instanceof ShapelessRecipes) {
return ((ShapelessRecipes) recipe).recipeItems;
ShapelessRecipes shapelessRecipe = (ShapelessRecipes) recipe;
recipeInputs = new ArrayList<ItemStack>(shapelessRecipe.recipeItems);
return recipeInputs;
}
else if (recipe instanceof ShapedOreRecipe) {
ShapedOreRecipe shapedRecipe = (ShapedOreRecipe) recipe;
ArrayList recipeInputs = new ArrayList<ItemStack>();
ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe;
recipeInputs = new ArrayList<ItemStack>();
for (int i = 0; i < shapedRecipe.getInput().length; i++) {
if (shapedRecipe.getInput()[i] != null) {
recipeInputs.add(shapedRecipe.getInput()[i]);
for (int i = 0; i < shapedOreRecipe.getInput().length; i++) {
if (shapedOreRecipe.getInput()[i] instanceof ArrayList) {
ArrayList<ItemStack> shapedOreRecipeInputs = (ArrayList<ItemStack>) shapedOreRecipe.getInput()[i];
for (ItemStack itemStack : shapedOreRecipeInputs) {
recipeInputs.add(itemStack);
}
}
}
return recipeInputs;
}
// TODO: Ore Dict recipes should populate some sort of equivalency portion of the dynEMC system
// TODO: Recipe Inputs should populate into separate lists, so that the emc of the lists can be determined and minimized
else if (recipe instanceof ShapelessOreRecipe) {
ShapelessOreRecipe shapelessOreRecipe = (ShapelessOreRecipe) recipe;
recipeInputs = new ArrayList<ItemStack>();
for (Object recipeInput : shapelessOreRecipe.getInput()) {
if (recipeInput instanceof ArrayList) {
ArrayList<ItemStack> shapelessOreRecipeInputs = (ArrayList<ItemStack>) recipeInput;
for (ItemStack itemStack : shapelessOreRecipeInputs) {
recipeInputs.add(itemStack);
}
}
}
return ((ShapelessOreRecipe) recipe).getInput();
}
return null;
}
public static List<ItemStack> getReverseRecipes(ItemStack itemStack) {
public static ArrayList<IRecipe> getReverseRecipes(ItemStack itemStack) {
@SuppressWarnings("unchecked")
ArrayList<IRecipe> recipeList = (ArrayList<IRecipe>) CraftingManager.getInstance().getRecipeList();
ArrayList<IRecipe> craftingManagerRecipeList = new ArrayList<IRecipe>(CraftingManager.getInstance().getRecipeList());
ArrayList<IRecipe> reverseRecipeList = new ArrayList<IRecipe>();
for (IRecipe recipe : recipeList) {
for (IRecipe recipe : craftingManagerRecipeList) {
if (recipe.getRecipeOutput() != null) {
if ((recipe.getRecipeOutput().itemID == itemStack.itemID) && (recipe.getRecipeOutput().getItemDamage() == itemStack.getItemDamage())) {
System.out.println(recipe);
System.out.println(recipe.getRecipeOutput());
System.out.println(getRecipeInputs(recipe));
if (ItemHelper.compare(itemStack, recipe.getRecipeOutput())) {
reverseRecipeList.add(recipe);
}
}
}
return null;
return reverseRecipeList;
}
public static void addRecipe(ItemStack output, Object... input) {