From 0f9e8f39513ad7bb8b4e2a1e553ccdcde8338575 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 6 Nov 2025 23:43:45 -0700 Subject: [PATCH 1/4] add new test for checking ingredient equals check gt recipe input and tag in equals impl remove MapItemStackNBTIngredient.java as it seemed to be redundant --- .../java/gregtech/api/recipes/RecipeMap.java | 7 +- .../recipes/map/MapItemStackIngredient.java | 11 +-- .../map/MapItemStackNBTIngredient.java | 75 ------------------- .../gregtech/api/recipes/RecipeMapTest.java | 50 +++++++++++++ 4 files changed, 58 insertions(+), 85 deletions(-) delete mode 100644 src/main/java/gregtech/api/recipes/map/MapItemStackNBTIngredient.java diff --git a/src/main/java/gregtech/api/recipes/RecipeMap.java b/src/main/java/gregtech/api/recipes/RecipeMap.java index 9b920a7239f..ba50a0148b0 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++) { @@ -1211,7 +1208,7 @@ protected void buildFromItemStacks(@NotNull List> li } 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..123e1c62858 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,12 @@ 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 (this.gtRecipeInput == other.gtRecipeInput) { + return Objects.equals(this.tag, other.tag); + } else if (this.gtRecipeInput == null) { return other.gtRecipeInput.acceptsStack(this.stack); + } else if (other.gtRecipeInput != null) { + return gtRecipeInput.equalIgnoreAmount(other.gtRecipeInput); } } 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..bf6af80e365 100644 --- a/src/test/java/gregtech/api/recipes/RecipeMapTest.java +++ b/src/test/java/gregtech/api/recipes/RecipeMapTest.java @@ -7,6 +7,8 @@ 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 net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -22,8 +24,11 @@ import org.junit.jupiter.api.Test; import java.lang.reflect.Field; +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 +279,49 @@ public void wildcardInput() { MatcherAssert.assertThat(recipe, notNullValue()); } } + + @Test + public void testInputs() { + FluidStack dye = Materials.CHEMICAL_DYES[1].getFluid(GTValues.L); + + map.recipeBuilder() + .inputs(new ItemStack(Blocks.WOOL)) + .fluidInputs(GTUtility.copy(dye)) + .outputs(new ItemStack(Blocks.WOOL, 1, 1)) + .duration(1).EUt(1) + .buildAndRegister(); + + map.recipeBuilder() + .input(Blocks.WOOL, 1, true) + .fluidInputs(Chlorine.getFluid(50)) + .output(Blocks.WOOL) + .duration(1).EUt(1) + .buildAndRegister(); + + try { + 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))); + } catch (ReflectiveOperationException ignored) {} + + Recipe recipe = map.find( + Collections.singleton(new ItemStack(Blocks.WOOL)), + Collections.singleton(GTUtility.copy(dye)), + r -> true); + + MatcherAssert.assertThat("recipe could not be found!", recipe != null); + } } From c8c5fd11d4bf1370a70f8d4e1b8f6d5875f41d4a Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 7 Nov 2025 02:28:04 -0700 Subject: [PATCH 2/4] loosen up the equals impl a bit by testing against stack make test more specific to chem bath recipe map --- .../recipes/map/MapItemStackIngredient.java | 4 +- .../gregtech/api/recipes/RecipeMapTest.java | 68 +++++++++---------- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java b/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java index 123e1c62858..a4d8a23b975 100644 --- a/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java +++ b/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java @@ -54,8 +54,8 @@ public boolean equals(Object o) { return Objects.equals(this.tag, other.tag); } else if (this.gtRecipeInput == null) { return other.gtRecipeInput.acceptsStack(this.stack); - } else if (other.gtRecipeInput != null) { - return gtRecipeInput.equalIgnoreAmount(other.gtRecipeInput); + } else { + return this.gtRecipeInput.acceptsStack(other.stack); } } return false; diff --git a/src/test/java/gregtech/api/recipes/RecipeMapTest.java b/src/test/java/gregtech/api/recipes/RecipeMapTest.java index bf6af80e365..ef16aab6a94 100644 --- a/src/test/java/gregtech/api/recipes/RecipeMapTest.java +++ b/src/test/java/gregtech/api/recipes/RecipeMapTest.java @@ -2,6 +2,7 @@ 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; @@ -9,6 +10,8 @@ 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; @@ -24,6 +27,7 @@ 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; @@ -281,46 +285,38 @@ public void wildcardInput() { } @Test - public void testInputs() { + 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); - map.recipeBuilder() - .inputs(new ItemStack(Blocks.WOOL)) - .fluidInputs(GTUtility.copy(dye)) - .outputs(new ItemStack(Blocks.WOOL, 1, 1)) - .duration(1).EUt(1) - .buildAndRegister(); + Method prepareRecipeFind = RecipeMap.class.getDeclaredMethod("prepareRecipeFind", Collection.class, + Collection.class); + prepareRecipeFind.setAccessible(true); - map.recipeBuilder() - .input(Blocks.WOOL, 1, true) - .fluidInputs(Chlorine.getFluid(50)) - .output(Blocks.WOOL) - .duration(1).EUt(1) - .buildAndRegister(); + // noinspection unchecked + List> list = (List>) prepareRecipeFind.invoke(map, + Collections.singletonList(new ItemStack(Blocks.WOOL)), + Collections.singletonList(GTUtility.copy(dye))); - try { - 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))); - } catch (ReflectiveOperationException ignored) {} - - Recipe recipe = map.find( - Collections.singleton(new ItemStack(Blocks.WOOL)), - Collections.singleton(GTUtility.copy(dye)), - r -> true); + // 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); } From 05f6301f3cf24df88d88c4dd271c3d5909f354d3 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 7 Nov 2025 17:47:55 -0700 Subject: [PATCH 3/4] move tag up in equals --- .../gregtech/api/recipes/map/MapItemStackIngredient.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java b/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java index a4d8a23b975..a53ec0a78d7 100644 --- a/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java +++ b/src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java @@ -50,8 +50,11 @@ public boolean equals(Object o) { if (this.meta != other.meta) { return false; } + if (!Objects.equals(this.tag, other.tag)) { + return false; + } if (this.gtRecipeInput == other.gtRecipeInput) { - return Objects.equals(this.tag, other.tag); + return true; } else if (this.gtRecipeInput == null) { return other.gtRecipeInput.acceptsStack(this.stack); } else { From ee62d19740693e9ce7e97030e77ddb3fa8a7fbab Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 17 Nov 2025 14:37:30 -0700 Subject: [PATCH 4/4] remove comment set regular input with null nbt not sure why an ingredient is declared outside of the for loop, so i removed it hope it doesn't break anything --- src/main/java/gregtech/api/recipes/RecipeMap.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/RecipeMap.java b/src/main/java/gregtech/api/recipes/RecipeMap.java index ba50a0148b0..e0192512161 100644 --- a/src/main/java/gregtech/api/recipes/RecipeMap.java +++ b/src/main/java/gregtech/api/recipes/RecipeMap.java @@ -1182,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(); @@ -1190,24 +1189,22 @@ 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 MapItemStackIngredient(stack, meta, nbt)); } if (!ls.isEmpty()) list.add(ls);