From c6a77f9cfa767d1b8ff81ed4e8c2efb356bcb698 Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Thu, 4 Sep 2014 04:28:44 +0100 Subject: [PATCH] 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. --- .../mekanism/common/recipe/RecipeHandler.java | 27 ++++++++++--------- .../common/recipe/inputs/ItemStackInput.java | 6 +++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/mekanism/common/recipe/RecipeHandler.java b/src/main/java/mekanism/common/recipe/RecipeHandler.java index 498ee4087..f42cb063a 100644 --- a/src/main/java/mekanism/common/recipe/RecipeHandler.java +++ b/src/main/java/mekanism/common/recipe/RecipeHandler.java @@ -379,11 +379,9 @@ public final class RecipeHandler { if(itemstack != null) { - ItemStackInput input = new ItemStackInput(itemstack); - HashMap 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 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 getRecipeTryWildcard(ItemStack stack, Map 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()), diff --git a/src/main/java/mekanism/common/recipe/inputs/ItemStackInput.java b/src/main/java/mekanism/common/recipe/inputs/ItemStackInput.java index 8bfdd0e79..c214cf80b 100644 --- a/src/main/java/mekanism/common/recipe/inputs/ItemStackInput.java +++ b/src/main/java/mekanism/common/recipe/inputs/ItemStackInput.java @@ -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() {