diff --git a/src/main/java/gregtech/api/recipes/RecipeMap.java b/src/main/java/gregtech/api/recipes/RecipeMap.java index 9b920a7239f..e0192512161 100644 --- a/src/main/java/gregtech/api/recipes/RecipeMap.java +++ b/src/main/java/gregtech/api/recipes/RecipeMap.java @@ -16,7 +16,6 @@ import gregtech.api.recipes.map.Either; import gregtech.api.recipes.map.MapFluidIngredient; import gregtech.api.recipes.map.MapItemStackIngredient; -import gregtech.api.recipes.map.MapItemStackNBTIngredient; import gregtech.api.recipes.map.MapOreDictIngredient; import gregtech.api.recipes.map.MapOreDictNBTIngredient; import gregtech.api.recipes.ui.RecipeMapUI; @@ -1155,11 +1154,9 @@ protected void buildFromRecipeItems(List> list, @Not } else { // input must be represented as a list of possible stacks List ingredients; + ingredients = MapItemStackIngredient.from(r); if (r.hasNBTMatchingCondition()) { - ingredients = MapItemStackNBTIngredient.from(r); hasNBTMatcherInputs = true; - } else { - ingredients = MapItemStackIngredient.from(r); } for (int i = 0; i < ingredients.size(); i++) { @@ -1185,7 +1182,6 @@ protected void buildFromRecipeItems(List> list, @Not */ protected void buildFromItemStacks(@NotNull List> list, @NotNull ItemStack[] ingredients) { - AbstractMapIngredient ingredient; for (ItemStack stack : ingredients) { int meta = stack.getMetadata(); NBTTagCompound nbt = stack.getTagCompound(); @@ -1193,25 +1189,23 @@ protected void buildFromItemStacks(@NotNull List> li List ls = new ObjectArrayList<>(1); // add the regular input - ls.add(new MapItemStackIngredient(stack, meta, nbt)); + // tag should be null, right? + ls.add(new MapItemStackIngredient(stack, meta, null)); if (hasOreDictedInputs) { // add the ore dict inputs for (int i : OreDictionary.getOreIDs(stack)) { - ingredient = new MapOreDictIngredient(i); - ls.add(ingredient); + ls.add(new MapOreDictIngredient(i)); if (hasNBTMatcherInputs) { // add the nbt inputs for the oredict inputs - ingredient = new MapOreDictNBTIngredient(i, nbt); - ls.add(ingredient); + ls.add(new MapOreDictNBTIngredient(i, nbt)); } } } if (hasNBTMatcherInputs) { - // add the nbt input for the regular input - ls.add(new MapItemStackNBTIngredient(stack, meta, nbt)); + ls.add(new MapItemStackIngredient(stack, meta, nbt)); } if (!ls.isEmpty()) list.add(ls); } diff --git a/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java b/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java index d3be9c1bb7b..a53ec0a78d7 100644 --- a/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java +++ b/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Objects; public class MapItemStackIngredient extends AbstractMapIngredient { @@ -49,12 +50,15 @@ public boolean equals(Object o) { if (this.meta != other.meta) { return false; } - if (this.gtRecipeInput != null) { - if (other.gtRecipeInput != null) { - return gtRecipeInput.equalIgnoreAmount(other.gtRecipeInput); - } - } else if (other.gtRecipeInput != null) { + if (!Objects.equals(this.tag, other.tag)) { + return false; + } + if (this.gtRecipeInput == other.gtRecipeInput) { + return true; + } else if (this.gtRecipeInput == null) { return other.gtRecipeInput.acceptsStack(this.stack); + } else { + return this.gtRecipeInput.acceptsStack(other.stack); } } return false; diff --git a/src/main/java/gregtech/api/recipes/map/MapItemStackNBTIngredient.java b/src/main/java/gregtech/api/recipes/map/MapItemStackNBTIngredient.java deleted file mode 100644 index c64920b0794..00000000000 --- a/src/main/java/gregtech/api/recipes/map/MapItemStackNBTIngredient.java +++ /dev/null @@ -1,75 +0,0 @@ -package gregtech.api.recipes.map; - -import gregtech.api.recipes.ingredients.GTRecipeInput; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class MapItemStackNBTIngredient extends MapItemStackIngredient { - - protected GTRecipeInput gtRecipeInput = null; - - public MapItemStackNBTIngredient(ItemStack stack, int meta, NBTTagCompound tag) { - super(stack, meta, tag); - } - - public MapItemStackNBTIngredient(ItemStack s, GTRecipeInput gtRecipeInput) { - super(s, s.getMetadata(), null); - this.gtRecipeInput = gtRecipeInput; - } - - @NotNull - public static List from(@NotNull GTRecipeInput r) { - ObjectArrayList list = new ObjectArrayList<>(); - for (ItemStack s : r.getInputStacks()) { - list.add(new MapItemStackNBTIngredient(s, r)); - } - return list; - } - - @Override - protected int hash() { - int hash = stack.getItem().hashCode() * 31; - hash += 31 * meta; - return hash; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof MapItemStackNBTIngredient) { - MapItemStackNBTIngredient other = (MapItemStackNBTIngredient) obj; - if (this.stack.getItem() != other.stack.getItem()) { - return false; - } - if (this.meta != other.meta) { - return false; - } - if (this.gtRecipeInput != null) { - if (other.gtRecipeInput != null) { - return gtRecipeInput.equalIgnoreAmount(other.gtRecipeInput); - } - } else if (other.gtRecipeInput != null) { - return other.gtRecipeInput.acceptsStack(this.stack); - } - } - return false; - } - - @Override - public String toString() { - return "MapItemStackNBTIngredient{" + "item=" + stack.getItem().getRegistryName() + "}" + "{meta=" + meta + "}"; - } - - @Override - public boolean isSpecialIngredient() { - return true; - } -} diff --git a/src/test/java/gregtech/api/recipes/RecipeMapTest.java b/src/test/java/gregtech/api/recipes/RecipeMapTest.java index 3330c1fd57d..ef16aab6a94 100644 --- a/src/test/java/gregtech/api/recipes/RecipeMapTest.java +++ b/src/test/java/gregtech/api/recipes/RecipeMapTest.java @@ -2,11 +2,16 @@ import gregtech.Bootstrap; import gregtech.api.GTValues; +import gregtech.api.items.metaitem.MetaItem; import gregtech.api.recipes.builders.SimpleRecipeBuilder; import gregtech.api.recipes.map.AbstractMapIngredient; import gregtech.api.recipes.map.MapFluidIngredient; import gregtech.api.recipes.map.MapItemStackIngredient; import gregtech.api.recipes.map.MapOreDictIngredient; +import gregtech.api.unification.material.Materials; +import gregtech.api.util.GTUtility; +import gregtech.common.items.MetaItems; +import gregtech.loaders.recipe.VanillaStandardRecipes; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -22,8 +27,12 @@ import org.junit.jupiter.api.Test; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.List; import static gregtech.api.unification.material.Materials.*; import static org.hamcrest.CoreMatchers.*; @@ -274,4 +283,41 @@ public void wildcardInput() { MatcherAssert.assertThat(recipe, notNullValue()); } } + + @Test + public void testInputs() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + for (MetaItem item : MetaItems.ITEMS) { + item.registerSubItems(); + } + + Method dyingCleaningRecipes = VanillaStandardRecipes.class.getDeclaredMethod("dyingCleaningRecipes"); + dyingCleaningRecipes.setAccessible(true); + dyingCleaningRecipes.invoke(null); + + FluidStack dye = Materials.CHEMICAL_DYES[1].getFluid(GTValues.L); + + Method prepareRecipeFind = RecipeMap.class.getDeclaredMethod("prepareRecipeFind", Collection.class, + Collection.class); + prepareRecipeFind.setAccessible(true); + + // noinspection unchecked + List> list = (List>) prepareRecipeFind.invoke(map, + Collections.singletonList(new ItemStack(Blocks.WOOL)), + Collections.singletonList(GTUtility.copy(dye))); + + // noinspection unchecked + List> list2 = (List>) prepareRecipeFind.invoke(map, + Collections.singletonList(new ItemStack(Blocks.WOOL)), + Collections.singletonList(Chlorine.getFluid(50))); + + MatcherAssert.assertThat("the first two ingredients are not equal!", + list.get(0).get(0).equals(list2.get(0).get(0))); + + List wool = Arrays.asList(new ItemStack(Blocks.WOOL)); + List fluidDye = Arrays.asList(GTUtility.copy(dye)); + Recipe recipe = RecipeMaps.CHEMICAL_BATH_RECIPES.find( + wool, fluidDye, r -> r.matches(false, wool, fluidDye)); + + MatcherAssert.assertThat("recipe could not be found!", recipe != null); + } }