Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1155,11 +1154,9 @@ protected void buildFromRecipeItems(List<List<AbstractMapIngredient>> list, @Not
} else {
// input must be represented as a list of possible stacks
List<AbstractMapIngredient> 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++) {
Expand All @@ -1185,33 +1182,30 @@ protected void buildFromRecipeItems(List<List<AbstractMapIngredient>> list, @Not
*/
protected void buildFromItemStacks(@NotNull List<List<AbstractMapIngredient>> list,
@NotNull ItemStack[] ingredients) {
AbstractMapIngredient ingredient;
for (ItemStack stack : ingredients) {
int meta = stack.getMetadata();
NBTTagCompound nbt = stack.getTagCompound();

List<AbstractMapIngredient> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Objects;

public class MapItemStackIngredient extends AbstractMapIngredient {

Expand Down Expand Up @@ -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;
Expand Down

This file was deleted.

46 changes: 46 additions & 0 deletions src/test/java/gregtech/api/recipes/RecipeMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -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<AbstractMapIngredient>> list = (List<List<AbstractMapIngredient>>) prepareRecipeFind.invoke(map,
Collections.singletonList(new ItemStack(Blocks.WOOL)),
Collections.singletonList(GTUtility.copy(dye)));

// noinspection unchecked
List<List<AbstractMapIngredient>> list2 = (List<List<AbstractMapIngredient>>) 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<ItemStack> wool = Arrays.asList(new ItemStack(Blocks.WOOL));
List<FluidStack> 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);
}
}
Loading