package mezz.jei.load.registration;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.minecraft.util.ResourceLocation;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import mezz.jei.api.helpers.IJeiHelpers;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.api.registration.IRecipeCategoryRegistration;
import mezz.jei.util.ErrorUtil;

public class RecipeCategoryRegistration implements IRecipeCategoryRegistration {
	private final List<IRecipeCategory> recipeCategories = new ArrayList<>();
	private final Map<ResourceLocation, IRecipeCategory> recipeCategoriesByUid = new HashMap<>();
	private final Set<Class<?>> recipeClasses = new HashSet<>();
	private final IJeiHelpers jeiHelpers;

	public RecipeCategoryRegistration(IJeiHelpers jeiHelpers) {
		this.jeiHelpers = jeiHelpers;
	}

	@Override
	public void addRecipeCategories(IRecipeCategory... recipeCategories) {
		ErrorUtil.checkNotEmpty(recipeCategories, "recipeCategories");

		for (IRecipeCategory recipeCategory : recipeCategories) {
			ResourceLocation uid = recipeCategory.getUid();
			Preconditions.checkNotNull(uid, "Recipe category UID cannot be null %s", recipeCategory);
			Class<?> recipeClass = recipeCategory.getRecipeClass();
			Preconditions.checkNotNull(recipeClass, "Recipe class cannot be null %s", recipeCategory);
			if (!recipeClasses.add(recipeClass)) {
				throw new IllegalArgumentException("A RecipeCategory for recipe class \"" + recipeClass + "\" has already been registered.");
			}
			if (recipeCategoriesByUid.containsKey(uid)) {
				throw new IllegalArgumentException("A RecipeCategory with UID \"" + uid + "\" has already been registered.");
			} else {
				recipeCategoriesByUid.put(uid, recipeCategory);
			}
		}

		Collections.addAll(this.recipeCategories, recipeCategories);
	}

	@Override
	public IJeiHelpers getJeiHelpers() {
		return jeiHelpers;
	}

	public ImmutableList<IRecipeCategory> getRecipeCategories() {
		return ImmutableList.copyOf(recipeCategories);
	}

	public ImmutableMap<ResourceLocation, IRecipeCategory> getRecipeCategoriesByUid() {
		return ImmutableMap.copyOf(recipeCategoriesByUid);
	}
}

@@ -118,34 +118,8 @@
 ap;%0A
-import java.util.HashSet;%0A
 impo
@@ -162,30 +162,8 @@
 Map;
-%0Aimport java.util.Set;
 %0A%0Aim
@@ -789,70 +789,8 @@
 ();%0A
-%09private final Set%3CClass%3C?%3E%3E recipeClasses = new HashSet%3C%3E();%0A
 %09pri
@@ -1432,185 +1432,8 @@
 y);%0A
-%09%09%09if (!recipeClasses.add(recipeClass)) %7B%0A%09%09%09%09throw new IllegalArgumentException(%22A RecipeCategory for recipe class %5C%22%22 + recipeClass + %22%5C%22 has already been registered.%22);%0A%09%09%09%7D%0A
 %09%09%09i

Remove restriction that recipe categories can't handle the same recipe class as another