package gtPlusPlus.nei;
import java.awt.Point;
import java.awt.Rectangle;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.lwjgl.opengl.GL11;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.PositionedStack;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;
import codechicken.nei.guihook.IContainerTooltipHandler;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.TemplateRecipeHandler;
import cpw.mods.fml.common.event.FMLInterModComms;
import gregtech.api.enums.GT_Values;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.gui.GT_GUIContainer_BasicMachine;
import gregtech.api.objects.ItemData;
import gregtech.api.util.GT_LanguageManager;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.core.util.math.MathUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public class GTPP_NEI_DefaultHandler extends TemplateRecipeHandler {
public static final int sOffsetX = 5;
public static final int sOffsetY = 11;
private SoftReference<List<CachedDefaultRecipe>> mCachedRecipes = null;
private static final HashMap<Integer, Pair<Integer, Integer>> mInputSlotMap = new HashMap<Integer, Pair<Integer, Integer>>();
private static final HashMap<Integer, Pair<Integer, Integer>> mOutputSlotMap = new HashMap<Integer, Pair<Integer, Integer>>();
static {
GuiContainerManager.addInputHandler(new GT_RectHandler());
GuiContainerManager.addTooltipHandler(new GT_RectHandler());
int[] aSlotX = new int[] {12, 30, 48};
int[] aSlotY = new int[] {5, 23, 41, 64};
// Input slots
int aIndex = 0;
for (int y=0; y<aSlotY.length;y++) {
for (int x=0; x<aSlotX.length;x++) {
mInputSlotMap.put(aIndex++, new Pair<Integer, Integer>(aSlotX[x], aSlotY[y]));
}
}
// Output slots
aSlotX = new int[] {102, 120, 138};
aIndex = 0;
for (int y=0; y<aSlotY.length;y++) {
for (int x=0; x<aSlotX.length;x++) {
mOutputSlotMap.put(aIndex++, new Pair<Integer, Integer>(aSlotX[x], aSlotY[y]));
}
}
}
protected final GT_Recipe_Map mRecipeMap;
public GTPP_NEI_DefaultHandler(final GT_Recipe_Map tMap) {
this.mRecipeMap = tMap;
this.transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(65, 13, 36, 18), this.getOverlayIdentifier(), new Object[0]));
if (!NEI_GT_Config.sIsAdded) {
FMLInterModComms.sendRuntimeMessage(GT_Values.GT, "NEIPlugins", "register-crafting-handler", "gregtechplusplus@" + this.getRecipeName() + "@" + this.getOverlayIdentifier());
GuiCraftingRecipe.craftinghandlers.add(this);
GuiUsageRecipe.usagehandlers.add(this);
}
}
public static void drawText(final int aX, final int aY, final String aString, final int aColor) {
Minecraft.getMinecraft().fontRenderer.drawString(aString, aX, aY, aColor);
}
@Override
public TemplateRecipeHandler newInstance() {
return new GTPP_NEI_DefaultHandler(this.mRecipeMap);
}
public List<GT_Recipe> getSortedRecipes() {
List<GT_Recipe> result = new ArrayList<>(this.mRecipeMap.mRecipeList);
Collections.sort(result);
return result;
}
public List<CachedDefaultRecipe> getCache() {
List<CachedDefaultRecipe> cache;
if (mCachedRecipes == null || (cache = mCachedRecipes.get()) == null) {
cache = mRecipeMap.mRecipeList.stream() // do not use parallel stream. This is already parallelized by NEI
.