Skip to content

Commit

Permalink
Fix wrong type on new methods, fix IngredientSet.removeAll
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Nov 22, 2017
1 parent be435cb commit e50e505
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Expand Up @@ -62,22 +62,22 @@ public interface IIngredientRegistry {
*
* @since JEI 4.8.2
*/
<V> void addIngredientsAtRuntime(Class<V> ingredientClass, Set<V> ingredients);
<V> void addIngredientsAtRuntime(Class<V> ingredientClass, Collection<V> ingredients);

/**
* Remove ingredients from JEI at runtime.
* Used by mods that have items created while the game is running, or use the server to define items.
*
* @since JEI 4.8.2
*/
<V> void removeIngredientsAtRuntime(Class<V> ingredientClass, Set<V> ingredients);
<V> void removeIngredientsAtRuntime(Class<V> ingredientClass, Collection<V> ingredients);

/**
* Add new ingredients to JEI at runtime.
* Used by mods that have items created while the game is running, or use the server to define items.
*
* @since JEI 4.0.2
* @deprecated since JEI 4.7.3. Use {@link #addIngredientsAtRuntime(Class, Set)}
* @deprecated since JEI 4.7.3. Use {@link #addIngredientsAtRuntime(Class, Collection)}
*/
@Deprecated
<V> void addIngredientsAtRuntime(Class<V> ingredientClass, List<V> ingredients);
Expand All @@ -87,7 +87,7 @@ public interface IIngredientRegistry {
* Used by mods that have items created while the game is running, or use the server to define items.
*
* @since JEI 4.3.5
* @deprecated since JEI 4.7.3. Use {@link #removeIngredientsAtRuntime(Class, Set)}
* @deprecated since JEI 4.7.3. Use {@link #removeIngredientsAtRuntime(Class, Collection)}
*/
@Deprecated
<V> void removeIngredientsAtRuntime(Class<V> ingredientClass, List<V> ingredients);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mezz/jei/ingredients/IngredientRegistry.java
Expand Up @@ -161,7 +161,7 @@ public <V> void addIngredientsAtRuntime(Class<V> ingredientClass, List<V> ingred
}

@Override
public <V> void addIngredientsAtRuntime(Class<V> ingredientClass, Set<V> ingredients) {
public <V> void addIngredientsAtRuntime(Class<V> ingredientClass, Collection<V> ingredients) {
ErrorUtil.assertMainThread();
addIngredientsAtRuntime(ingredientClass, ingredients, Internal.getIngredientFilter());
}
Expand Down Expand Up @@ -196,7 +196,7 @@ public <V> void removeIngredientsAtRuntime(Class<V> ingredientClass, List<V> ing
}

@Override
public <V> void removeIngredientsAtRuntime(Class<V> ingredientClass, Set<V> ingredients) {
public <V> void removeIngredientsAtRuntime(Class<V> ingredientClass, Collection<V> ingredients) {
ErrorUtil.assertMainThread();
removeIngredientsAtRuntime(ingredientClass, ingredients, Internal.getIngredientFilter());
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/mezz/jei/util/IngredientSet.java
Expand Up @@ -6,9 +6,11 @@
import net.minecraft.item.ItemStack;

import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

public class IngredientSet<V> extends AbstractSet<V> {
Expand Down Expand Up @@ -44,6 +46,19 @@ public boolean remove(Object o) {
return ingredients.remove(uid) != null;
}

@Override
public boolean removeAll(Collection<?> c) {
if (c instanceof IngredientSet) {
return super.removeAll(c);
}
Objects.requireNonNull(c);
boolean modified = false;
for (Object aC : c) {
modified |= remove(aC);
}
return modified;
}

@Override
public boolean contains(Object o) {
//noinspection unchecked
Expand Down

0 comments on commit e50e505

Please sign in to comment.