Fix handling of Wildcarded recipes.

Disadvantage of the new system is it does require checking exactly the metadata on ItemStacks that is in the recipe.
This commit is contained in:
Ben Spiers 2014-09-04 04:28:44 +01:00
parent ce6946c669
commit c6a77f9cfa
2 changed files with 21 additions and 12 deletions

View file

@ -379,11 +379,9 @@ public final class RecipeHandler
{
if(itemstack != null)
{
ItemStackInput input = new ItemStackInput(itemstack);
HashMap<ItemStackInput, DissolutionRecipe> recipes = Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get();
DissolutionRecipe recipe = recipes.get(input);
DissolutionRecipe recipe = getRecipeTryWildcard(itemstack, recipes);
if(recipe != null)
{
@ -414,11 +412,9 @@ public final class RecipeHandler
{
if(itemstack != null)
{
ItemStackInput input = new ItemStackInput(itemstack);
HashMap<ItemStackInput, OxidationRecipe> recipes = Recipe.CHEMICAL_OXIDIZER.get();
OxidationRecipe recipe = recipes.get(input);
OxidationRecipe recipe = getRecipeTryWildcard(itemstack, recipes);
if(recipe != null)
{
@ -450,9 +446,7 @@ public final class RecipeHandler
{
if(itemstack != null)
{
ItemStackInput input = new ItemStackInput(itemstack);
ChanceMachineRecipe recipe = recipes.get(input);
ChanceMachineRecipe recipe = getRecipeTryWildcard(itemstack, recipes);
if(recipe != null)
{
@ -484,9 +478,7 @@ public final class RecipeHandler
{
if(itemstack != null)
{
ItemStackInput input = new ItemStackInput(itemstack);
BasicMachineRecipe recipe = recipes.get(input);
BasicMachineRecipe recipe = getRecipeTryWildcard(itemstack, recipes);
if(recipe != null)
{
@ -633,6 +625,17 @@ public final class RecipeHandler
return false;
}
public static <RECIPE extends MachineRecipe<ItemStackInput, ?>> RECIPE getRecipeTryWildcard(ItemStack stack, Map<ItemStackInput, RECIPE> recipes)
{
ItemStackInput input = new ItemStackInput(stack);
RECIPE recipe = recipes.get(input);
if(recipe == null)
{
recipe = recipes.get(input.wildCopy());
}
return recipe;
}
public static enum Recipe
{
ENRICHMENT_CHAMBER(new HashMap<ItemStackInput, EnrichmentRecipe>()),

View file

@ -3,6 +3,7 @@ package mekanism.common.recipe.inputs;
import mekanism.api.util.StackUtils;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class ItemStackInput extends MachineInput
{
@ -13,6 +14,11 @@ public class ItemStackInput extends MachineInput
ingredient = stack;
}
public ItemStackInput wildCopy()
{
return new ItemStackInput(new ItemStack(ingredient.getItem(), ingredient.stackSize, OreDictionary.WILDCARD_VALUE));
}
@Override
public int hashIngredients()
{