Skip to content

Commit 0f9e8f3

Browse files
committed
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
1 parent c622751 commit 0f9e8f3

File tree

4 files changed

+58
-85
lines changed

4 files changed

+58
-85
lines changed

src/main/java/gregtech/api/recipes/RecipeMap.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import gregtech.api.recipes.map.Either;
1717
import gregtech.api.recipes.map.MapFluidIngredient;
1818
import gregtech.api.recipes.map.MapItemStackIngredient;
19-
import gregtech.api.recipes.map.MapItemStackNBTIngredient;
2019
import gregtech.api.recipes.map.MapOreDictIngredient;
2120
import gregtech.api.recipes.map.MapOreDictNBTIngredient;
2221
import gregtech.api.recipes.ui.RecipeMapUI;
@@ -1155,11 +1154,9 @@ protected void buildFromRecipeItems(List<List<AbstractMapIngredient>> list, @Not
11551154
} else {
11561155
// input must be represented as a list of possible stacks
11571156
List<AbstractMapIngredient> ingredients;
1157+
ingredients = MapItemStackIngredient.from(r);
11581158
if (r.hasNBTMatchingCondition()) {
1159-
ingredients = MapItemStackNBTIngredient.from(r);
11601159
hasNBTMatcherInputs = true;
1161-
} else {
1162-
ingredients = MapItemStackIngredient.from(r);
11631160
}
11641161

11651162
for (int i = 0; i < ingredients.size(); i++) {
@@ -1211,7 +1208,7 @@ protected void buildFromItemStacks(@NotNull List<List<AbstractMapIngredient>> li
12111208
}
12121209
if (hasNBTMatcherInputs) {
12131210
// add the nbt input for the regular input
1214-
ls.add(new MapItemStackNBTIngredient(stack, meta, nbt));
1211+
ls.add(new MapItemStackIngredient(stack, meta, nbt));
12151212
}
12161213
if (!ls.isEmpty()) list.add(ls);
12171214
}

src/main/java/gregtech/api/recipes/map/MapItemStackIngredient.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.jetbrains.annotations.NotNull;
1010

1111
import java.util.List;
12+
import java.util.Objects;
1213

1314
public class MapItemStackIngredient extends AbstractMapIngredient {
1415

@@ -49,12 +50,12 @@ public boolean equals(Object o) {
4950
if (this.meta != other.meta) {
5051
return false;
5152
}
52-
if (this.gtRecipeInput != null) {
53-
if (other.gtRecipeInput != null) {
54-
return gtRecipeInput.equalIgnoreAmount(other.gtRecipeInput);
55-
}
56-
} else if (other.gtRecipeInput != null) {
53+
if (this.gtRecipeInput == other.gtRecipeInput) {
54+
return Objects.equals(this.tag, other.tag);
55+
} else if (this.gtRecipeInput == null) {
5756
return other.gtRecipeInput.acceptsStack(this.stack);
57+
} else if (other.gtRecipeInput != null) {
58+
return gtRecipeInput.equalIgnoreAmount(other.gtRecipeInput);
5859
}
5960
}
6061
return false;

src/main/java/gregtech/api/recipes/map/MapItemStackNBTIngredient.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/test/java/gregtech/api/recipes/RecipeMapTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import gregtech.api.recipes.map.MapFluidIngredient;
88
import gregtech.api.recipes.map.MapItemStackIngredient;
99
import gregtech.api.recipes.map.MapOreDictIngredient;
10+
import gregtech.api.unification.material.Materials;
11+
import gregtech.api.util.GTUtility;
1012

1113
import net.minecraft.init.Blocks;
1214
import net.minecraft.item.ItemStack;
@@ -22,8 +24,11 @@
2224
import org.junit.jupiter.api.Test;
2325

2426
import java.lang.reflect.Field;
27+
import java.lang.reflect.Method;
2528
import java.util.Arrays;
29+
import java.util.Collection;
2630
import java.util.Collections;
31+
import java.util.List;
2732

2833
import static gregtech.api.unification.material.Materials.*;
2934
import static org.hamcrest.CoreMatchers.*;
@@ -274,4 +279,49 @@ public void wildcardInput() {
274279
MatcherAssert.assertThat(recipe, notNullValue());
275280
}
276281
}
282+
283+
@Test
284+
public void testInputs() {
285+
FluidStack dye = Materials.CHEMICAL_DYES[1].getFluid(GTValues.L);
286+
287+
map.recipeBuilder()
288+
.inputs(new ItemStack(Blocks.WOOL))
289+
.fluidInputs(GTUtility.copy(dye))
290+
.outputs(new ItemStack(Blocks.WOOL, 1, 1))
291+
.duration(1).EUt(1)
292+
.buildAndRegister();
293+
294+
map.recipeBuilder()
295+
.input(Blocks.WOOL, 1, true)
296+
.fluidInputs(Chlorine.getFluid(50))
297+
.output(Blocks.WOOL)
298+
.duration(1).EUt(1)
299+
.buildAndRegister();
300+
301+
try {
302+
Method prepareRecipeFind = RecipeMap.class.getDeclaredMethod("prepareRecipeFind", Collection.class,
303+
Collection.class);
304+
prepareRecipeFind.setAccessible(true);
305+
306+
// noinspection unchecked
307+
List<List<AbstractMapIngredient>> list = (List<List<AbstractMapIngredient>>) prepareRecipeFind.invoke(map,
308+
Collections.singletonList(new ItemStack(Blocks.WOOL)),
309+
Collections.singletonList(GTUtility.copy(dye)));
310+
311+
// noinspection unchecked
312+
List<List<AbstractMapIngredient>> list2 = (List<List<AbstractMapIngredient>>) prepareRecipeFind.invoke(map,
313+
Collections.singletonList(new ItemStack(Blocks.WOOL)),
314+
Collections.singletonList(Chlorine.getFluid(50)));
315+
316+
MatcherAssert.assertThat("the first two ingredients are not equal!",
317+
list.get(0).get(0).equals(list2.get(0).get(0)));
318+
} catch (ReflectiveOperationException ignored) {}
319+
320+
Recipe recipe = map.find(
321+
Collections.singleton(new ItemStack(Blocks.WOOL)),
322+
Collections.singleton(GTUtility.copy(dye)),
323+
r -> true);
324+
325+
MatcherAssert.assertThat("recipe could not be found!", recipe != null);
326+
}
277327
}

0 commit comments

Comments
 (0)