Skip to content
Permalink
Browse files

Fix ingredients with subtypes missing from the ingredient list

  • Loading branch information...
mezz committed Aug 7, 2017
1 parent f8dc270 commit 6fe23ac7083d26e359e66cd2c5d2f9bbdefe2d08
@@ -158,7 +158,7 @@ public boolean isKnownIngredientType(Object ingredient) {
//noinspection unchecked
IngredientSet<V> set = ingredientsMap.get(ingredientClass);
if (set == null) {
set = new IngredientSet<V>(ingredientHelper);
set = IngredientSet.create(ingredientClass, ingredientHelper);
ingredientsMap.put(ingredientClass, set);
}

@@ -1,12 +1,9 @@
package mezz.jei.startup;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Collection;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;

import mezz.jei.api.ingredients.IIngredientHelper;
@@ -38,7 +35,7 @@ public IngredientRegistry createIngredientRegistry(IModIdHelper modIdHelper) {
for (Class ingredientClass : allIngredientsMap.keySet()) {
IIngredientHelper ingredientHelper = ingredientHelperMap.get(ingredientClass);
Collection ingredients = allIngredientsMap.get(ingredientClass);
IngredientSet ingredientSet = new IngredientSet(ingredientHelper);
IngredientSet ingredientSet = IngredientSet.create(ingredientClass, ingredientHelper);
ingredientSet.addAll(ingredients);
ingredientsMap.put(ingredientClass, ingredientSet);
}
@@ -1,38 +1,66 @@
package mezz.jei.util;

import mezz.jei.Internal;
import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.startup.StackHelper;
import net.minecraft.item.ItemStack;

import java.util.AbstractSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

import mezz.jei.api.ingredients.IIngredientHelper;

public class IngredientSet<V> extends AbstractSet<V> {
private final IIngredientHelper<V> ingredientHelper;
public static <V> IngredientSet<V> create(Class<V> ingredientClass, final IIngredientHelper<V> ingredientHelper) {
final UidGenerator<V> uidGenerator;
if (ingredientClass == ItemStack.class) {
final StackHelper stackHelper = Internal.getStackHelper();
uidGenerator = new UidGenerator<V>() {
@Override
public String getUniqueId(V ingredient) {
return stackHelper.getUniqueIdentifierForStack((ItemStack) ingredient, StackHelper.UidMode.FULL);
}
};
} else {
uidGenerator = new UidGenerator<V>() {
@Override
public String getUniqueId(V ingredient) {
return ingredientHelper.getUniqueId(ingredient);
}
};
}
return new IngredientSet<V>(uidGenerator);
}

private interface UidGenerator<V> {
String getUniqueId(V ingredient);
}

private final UidGenerator<V> uidGenerator;
private final Map<String, V> ingredients;
public IngredientSet(IIngredientHelper<V> ingredientHelper) {
this.ingredientHelper = ingredientHelper;

private IngredientSet(UidGenerator<V> uidGenerator) {
this.uidGenerator = uidGenerator;
this.ingredients = new LinkedHashMap<String, V>();
}

@Override
public boolean add(V v) {
String uid = ingredientHelper.getUniqueId(v);
String uid = uidGenerator.getUniqueId(v);
return ingredients.put(uid, v) == null;
}

@Override
public boolean remove(Object o) {
//noinspection unchecked
String uid = ingredientHelper.getUniqueId((V) o);
String uid = uidGenerator.getUniqueId((V) o);
return ingredients.remove(uid) != null;
}

@Override
public boolean contains(Object o) {
//noinspection unchecked
String uid = ingredientHelper.getUniqueId((V) o);
String uid = uidGenerator.getUniqueId((V) o);
return ingredients.containsKey(uid);
}

0 comments on commit 6fe23ac

Please sign in to comment.
You can’t perform that action at this time.