package wanion.unidict.proxy;

/*
 * Created by WanionCane(https://github.com/WanionCane).
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import net.minecraft.client.gui.recipebook.RecipeList;
import net.minecraft.client.util.RecipeBookClient;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import wanion.lib.common.Util;

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

public class ClientProxy extends CommonProxy
{
	private final Map<CreativeTabs, List<RecipeList>> RECIPES_BY_TAB = Util.getField(RecipeBookClient.class, "RECIPES_BY_TAB", "field_194086_e", null, Map.class);
	private final List<RecipeList> ALL_RECIPES = Util.getField(RecipeBookClient.class, "ALL_RECIPES", "field_194087_f", null, List.class);

	@Override
	public void postInit(final FMLPostInitializationEvent event)
	{
		super.postInit(event);

		RECIPES_BY_TAB.clear();
		ALL_RECIPES.clear();

		final Table<CreativeTabs, String, RecipeList> table = HashBasedTable.create();

		for (IRecipe irecipe : CraftingManager.REGISTRY) {
			if (!irecipe.isDynamic()) {
				CreativeTabs creativetabs = getItemStackTab(irecipe.getRecipeOutput());
				String s = irecipe.getGroup();
				RecipeList recipelist1;

				if (s.isEmpty()) {
					recipelist1 = newRecipeList(creativetabs);
				} else {
					recipelist1 = table.get(creativetabs, s);

					if (recipelist1 == null) {
						recipelist1 = newRecipeList(creativetabs);
						table.put(creativetabs, s, recipelist1);
					}
				}

				recipelist1.add(irecipe);
			}
		}
	}

	private RecipeList newRecipeList(CreativeTabs creativeTabs)
	{
		final RecipeList recipelist = new RecipeList();
		ALL_RECIPES.add(recipelist);
		(RECIPES_BY_TAB.computeIfAbsent(creativeTabs, (p_194085_0_) -> new ArrayList<>())).add(recipelist);
		(RECIPES_BY_TAB.computeIfAbsent(CreativeTabs.SEARCH, (p_194083_0_) -> new ArrayList<>())).add(recipelist);
		return recipelist;
	}

	private CreativeTabs getItemStackTab(ItemStack itemStack)
	{
		CreativeTabs creativetabs = itemStack.getItem().getCreativeTab();
		if (creativetabs != CreativeTabs.BUILDING_BLOCKS && creativetabs != CreativeTabs.TOOLS && creativetabs != CreativeTabs.REDSTONE) {
			return creativetabs == CreativeTabs.COMBAT ? CreativeTabs.TOOLS : CreativeTabs.MISC;
		} else {
			return creativetabs;
		}
	}
}
@@ -305,550 +305,152 @@
 ort 
-com.google.common.collect.HashBasedTable;%0Aimport com.google.common.collect.Table;%0Aimport net.minecraft.client.gui.recipebook.RecipeList;%0Aimport net.minecraft.client.util.RecipeBookClient;%0Aimport net.minecraft.creativetab.CreativeTabs;%0Aimport net.minecraft.item.ItemStack;%0Aimport net.minecraft.item.crafting.CraftingManager;%0Aimport net.minecraft.item.crafting.IRecipe;%0Aimport net.minecraftforge.fml.common.event.FMLPostInitializationEvent;%0Aimport wanion.lib.common.Util;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Map
+net.minecraft.client.util.RecipeBookClient;%0Aimport net.minecraftforge.fml.common.event.FMLPostInitializationEvent;%0Aimport wanion.unidict.UniDict
 ;%0A%0Ap
@@ -496,1848 +496,319 @@
 roxy
-%0A%7B%0A%09private final Map%3CCreativeTabs, List%3CRecipeList%3E%3E RECIPES_BY_TAB = Util.getField(RecipeBookClient.class, %22RECIPES_BY_TAB%22, %22field_194086_e%22, null, Map.class);%0A%09private final List%3CRecipeList%3E ALL_RECIPES = Util.getField(RecipeBookClient.class, %22ALL_RECIPES%22, %22field_194087_f%22, null, List.class);%0A%0A%09@Override%0A%09public void postInit(final FMLPostInitializationEvent event)%0A%09%7B%0A%09%09super.postInit(event);%0A%0A%09%09RECIPES_BY_TAB.clear();%0A%09%09ALL_RECIPES.clear();%0A%0A%09%09final Table%3CCreativeTabs, String, RecipeList%3E table = HashBasedTable.creat
+ %7B%0A%09@Override%0A%09public void postInit(final FMLPostInitializationEvent event)%0A%09%7B%0A%09%09super.postInit(event);%0A%0A%09%09try %7B%0A%09%09%09RecipeBookClient.rebuildTabl
 e();%0A
-%0A
 %09%09
-for (IRecipe irecipe : CraftingManager.REGISTRY) %7B%0A%09%09%09if (!irecipe.isDynamic()) %7B%0A%09%09%09%09CreativeTabs creativetabs = getItemStackTab(irecipe.getRecipeOutput());%0A%09%09%09%09String s = irecipe.getGroup();%0A%09%09%09%09RecipeList recipelist1;%0A%0A%09%09%09%09if (s.isEmpty()) %7B%0A%09%09%09%09%09recipelist1 = newRecipeList(creativetabs);%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09recipelist1 = table.get(creativetabs, s);%0A%0A%09%09%09%09%09if (recipelist1 == null) %7B%0A%09%09%09%09%09%09recipelist1 = newRecipeList(creativetabs);%0A%09%09%09%09%09%09table.put(creativetabs, s, recipelist1);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%0A%09%09%09%09recipelist1.add(irecipe);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09private RecipeList newRecipeList(CreativeTabs creativeTabs)%0A%09%7B%0A%09%09final RecipeList recipelist = new RecipeList();%0A%09%09ALL_RECIPES.add(recipelist);%0A%09%09(RECIPES_BY_TAB.computeIfAbsent(creativeTabs, (p_194085_0_) -%3E new ArrayList%3C%3E())).add(recipelist);%0A%09%09(RECIPES_BY_TAB.computeIfAbsent(CreativeTabs.SEARCH, (p_194083_0_) -%3E new ArrayList%3C%3E())).add(recipelist);%0A%09%09return recipelist;%0A%09%7D%0A%0A%09private CreativeTabs getItemStackTab(ItemStack itemStack)%0A%09%7B%0A%09%09CreativeTabs creativetabs = itemStack.getItem().getCreativeTab();%0A%09%09if (creativetabs != CreativeTabs.BUILDING_BLOCKS && creativetabs != CreativeTabs.TOOLS && creativetabs != CreativeTabs.REDSTONE) %7B%0A%09%09%09return creativetabs == CreativeTabs.COMBAT ? CreativeTabs.TOOLS : CreativeTabs.MISC;%0A%09%09%7D else %7B%0A%09%09%09return creativetabs
+%09UniDict.getLogger().info(%22Fixed the Recipe Book%22);%0A%09%09%7D%0A%09%09catch (Exception e)%7B%0A%09%09%09UniDict.getLogger().error(%22Failed to fix Recipe Book%22);%0A%09%09%09e.printStackTrace()
 ;%0A%09%09

Simplify Recipe Book fixing code