Skip to content

Commit c8c5fd1

Browse files
committed
loosen up the equals impl a bit by testing against stack
make test more specific to chem bath recipe map
1 parent 0f9e8f3 commit c8c5fd1

File tree

2 files changed

+34
-38
lines changed

2 files changed

+34
-38
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public boolean equals(Object o) {
5454
return Objects.equals(this.tag, other.tag);
5555
} else if (this.gtRecipeInput == null) {
5656
return other.gtRecipeInput.acceptsStack(this.stack);
57-
} else if (other.gtRecipeInput != null) {
58-
return gtRecipeInput.equalIgnoreAmount(other.gtRecipeInput);
57+
} else {
58+
return this.gtRecipeInput.acceptsStack(other.stack);
5959
}
6060
}
6161
return false;

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

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import gregtech.Bootstrap;
44
import gregtech.api.GTValues;
5+
import gregtech.api.items.metaitem.MetaItem;
56
import gregtech.api.recipes.builders.SimpleRecipeBuilder;
67
import gregtech.api.recipes.map.AbstractMapIngredient;
78
import gregtech.api.recipes.map.MapFluidIngredient;
89
import gregtech.api.recipes.map.MapItemStackIngredient;
910
import gregtech.api.recipes.map.MapOreDictIngredient;
1011
import gregtech.api.unification.material.Materials;
1112
import gregtech.api.util.GTUtility;
13+
import gregtech.common.items.MetaItems;
14+
import gregtech.loaders.recipe.VanillaStandardRecipes;
1215

1316
import net.minecraft.init.Blocks;
1417
import net.minecraft.item.ItemStack;
@@ -24,6 +27,7 @@
2427
import org.junit.jupiter.api.Test;
2528

2629
import java.lang.reflect.Field;
30+
import java.lang.reflect.InvocationTargetException;
2731
import java.lang.reflect.Method;
2832
import java.util.Arrays;
2933
import java.util.Collection;
@@ -281,46 +285,38 @@ public void wildcardInput() {
281285
}
282286

283287
@Test
284-
public void testInputs() {
288+
public void testInputs() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
289+
for (MetaItem<?> item : MetaItems.ITEMS) {
290+
item.registerSubItems();
291+
}
292+
293+
Method dyingCleaningRecipes = VanillaStandardRecipes.class.getDeclaredMethod("dyingCleaningRecipes");
294+
dyingCleaningRecipes.setAccessible(true);
295+
dyingCleaningRecipes.invoke(null);
296+
285297
FluidStack dye = Materials.CHEMICAL_DYES[1].getFluid(GTValues.L);
286298

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();
299+
Method prepareRecipeFind = RecipeMap.class.getDeclaredMethod("prepareRecipeFind", Collection.class,
300+
Collection.class);
301+
prepareRecipeFind.setAccessible(true);
293302

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();
303+
// noinspection unchecked
304+
List<List<AbstractMapIngredient>> list = (List<List<AbstractMapIngredient>>) prepareRecipeFind.invoke(map,
305+
Collections.singletonList(new ItemStack(Blocks.WOOL)),
306+
Collections.singletonList(GTUtility.copy(dye)));
300307

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);
308+
// noinspection unchecked
309+
List<List<AbstractMapIngredient>> list2 = (List<List<AbstractMapIngredient>>) prepareRecipeFind.invoke(map,
310+
Collections.singletonList(new ItemStack(Blocks.WOOL)),
311+
Collections.singletonList(Chlorine.getFluid(50)));
312+
313+
MatcherAssert.assertThat("the first two ingredients are not equal!",
314+
list.get(0).get(0).equals(list2.get(0).get(0)));
315+
316+
List<ItemStack> wool = Arrays.asList(new ItemStack(Blocks.WOOL));
317+
List<FluidStack> fluidDye = Arrays.asList(GTUtility.copy(dye));
318+
Recipe recipe = RecipeMaps.CHEMICAL_BATH_RECIPES.find(
319+
wool, fluidDye, r -> r.matches(false, wool, fluidDye));
324320

325321
MatcherAssert.assertThat("recipe could not be found!", recipe != null);
326322
}

0 commit comments

Comments
 (0)