Fixed recipe comparisons

This commit is contained in:
Calclavia 2014-01-05 18:33:00 +08:00
parent 355a98b089
commit f467c82f13
3 changed files with 47 additions and 6 deletions

View file

@ -1,7 +1,10 @@
package resonantinduction.api;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.item.ItemStack;
import resonantinduction.api.RecipeUtils.ItemStackResource;
@ -12,7 +15,7 @@ public final class MachineRecipes
{
public static enum RecipeType
{
GRINDER, SAWMILL, SMELTER, FURNACE, ROLLER, BLAST_FURNACE, METAL_FORMER;
GRINDER, SAWMILL, SMELTER;
}
private final Map<RecipeType, Map<Resource[], Resource[]>> recipes = new HashMap<RecipeType, Map<Resource[], Resource[]>>();
@ -57,9 +60,32 @@ public final class MachineRecipes
return new HashMap<RecipeType, Map<Resource[], Resource[]>>(this.recipes);
}
public Resource[] getRecipe(RecipeType machine, ItemStack... inputs)
public Resource[] getOutput(RecipeType machine, Resource[] input)
{
return this.getRecipes(machine).get(inputs);
Iterator<Entry<Resource[], Resource[]>> it = this.getRecipes(machine).entrySet().iterator();
while (it.hasNext())
{
Entry<Resource[], Resource[]> entry = it.next();
if (Arrays.equals(entry.getKey(), input))
{
return entry.getValue();
}
}
return new Resource[] {};
}
public Resource[] getRecipe(RecipeType machine, ItemStack... inputs)
{
Resource[] resourceInputs = new Resource[inputs.length];
for (int i = 0; i < inputs.length; i++)
{
resourceInputs[i] = new ItemStackResource(inputs[i]);
}
return this.getOutput(machine, resourceInputs);
}
}

View file

@ -53,7 +53,12 @@ public class RecipeUtils
@Override
public boolean equals(Object obj)
{
return (obj instanceof ItemStack) ? ((ItemStack) obj).equals(this.itemStack) : false;
if (obj instanceof ItemStackResource)
{
return this.itemStack.isItemEqual(((ItemStackResource) obj).itemStack);
}
return false;
}
}
@ -76,7 +81,17 @@ public class RecipeUtils
@Override
public boolean equals(Object obj)
{
return (obj instanceof ItemStack) ? OreDictionary.getOres(this.name).contains(((ItemStack) obj)) : false;
if (obj instanceof OreDictResource)
{
return this.name.equals(((OreDictResource) obj).name);
}
if (obj instanceof ItemStackResource)
{
return this.name.equals(OreDictionary.getOreName(OreDictionary.getOreID(((ItemStackResource) obj).itemStack)));
}
return false;
}
}

View file

@ -59,7 +59,7 @@ public class TileGrinderWheel extends TileElectrical
}
public boolean canGrind(ItemStack itemStack)
{System.out.println(MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack));
{
return MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack) == null ? false : MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack).length > 0;
}