package squeek.veganoption.integration.jei.piston;

import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.*;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.BlankRecipeCategory;
import net.minecraft.util.ResourceLocation;
import squeek.veganoption.helpers.LangHelper;
import squeek.veganoption.integration.jei.VOPlugin;

import javax.annotation.Nonnull;

public class PistonRecipeCategory extends BlankRecipeCategory<PistonRecipeWrapper>
{
	private final String localizedName;
	private final IDrawable background;

	private static final int craftOutputSlot = 0;
	private static final int craftInputSlot1 = 1;

	public static final int width = 116;
	public static final int height = 54;

	private final ICraftingGridHelper craftingGridHelper;

	public PistonRecipeCategory(IGuiHelper guiHelper)
	{
		ResourceLocation location = new ResourceLocation("minecraft", "textures/gui/container/crafting_table.png");
		background = guiHelper.createDrawable(location, 29, 16, width, height);
		localizedName = LangHelper.translate("jei.pistonCrafting");
		craftingGridHelper = guiHelper.createCraftingGridHelper(craftInputSlot1, craftOutputSlot);
	}

	@Override
	@Nonnull
	public String getUid()
	{
		return VOPlugin.VORecipeCategoryUid.PISTON;
	}

	@Override
	@Nonnull
	public String getTitle()
	{
		return localizedName;
	}

	@Override
	@Nonnull
	public IDrawable getBackground()
	{
		return background;
	}

	@Override
	public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull PistonRecipeWrapper recipeWrapper, @Nonnull IIngredients ingredients)
	{
		IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
		IGuiFluidStackGroup guiFluidStacks = recipeLayout.getFluidStacks();

		if (recipeWrapper.recipe.fluidOutput != null)
			guiFluidStacks.init(craftOutputSlot, false, 95, 19, 16, 16, 1000, false, null);
		else
			guiItemStacks.init(craftOutputSlot, false, 94, 18);

		for (int y = 0; y < 3; ++y)
		{
			for (int x = 0; x < 3; ++x)
			{
				int index = craftInputSlot1 + x + (y * 3);
				if (index == craftInputSlot1 && recipeWrapper.recipe.fluidInput != null)
					guiFluidStacks.init(index, true, x * 18 + 1, y * 18 + 1, 16, 16, recipeWrapper.recipe.fluidInput.amount, false, null);
				else
					guiItemStacks.init(index, true, x * 18, y * 18);
			}
		}

		guiItemStacks.set(ingredients);
		guiFluidStacks.set(ingredients);
	}
}

@@ -242,16 +242,148 @@
 cation;%0A
+import net.minecraft.util.text.TextFormatting;%0Aimport net.minecraftforge.fluids.Fluid;%0Aimport net.minecraftforge.fluids.FluidStack;%0A
 import s
@@ -416,24 +416,24 @@
 LangHelper;%0A
-
 import squee
@@ -505,16 +505,39 @@
 Nonnull;
+%0Aimport java.util.List;
 %0A%0Apublic
@@ -1863,16 +1863,74 @@
 tacks();
+%0A%09%09guiFluidStacks.addTooltipCallback(fluidTooltipHandler);
 %0A%0A%09%09if (
@@ -2577,13 +2577,643 @@
 ients);%0A
-
 %09%7D
+%0A%0A%09public static class FluidTooltipCallback implements ITooltipCallback%3CFluidStack%3E%0A%09%7B%0A%09%09@Override%0A%09%09public void onTooltip(int slotIndex, boolean input, @Nonnull FluidStack ingredient, @Nonnull List%3CString%3E tooltip)%0A%09%09%7B%0A%09%09%09String tooltipStr;%0A%09%09%09if (input)%0A%09%09%09%09tooltipStr = LangHelper.translate(%22jei.pistonCrafting.tooltip.fluidInput%22);%0A%09%09%09else%0A%09%09%09%09tooltipStr = LangHelper.translate(%22jei.pistonCrafting.tooltip.fluidOutput%22);%0A%0A%09%09%09tooltip.add(1, TextFormatting.GOLD + TextFormatting.ITALIC.toString() + tooltipStr + TextFormatting.RESET);%0A%09%09%7D%0A%09%7D%0A%09private static FluidTooltipCallback fluidTooltipHandler = new FluidTooltipCallback();
 %0A%7D%0A

Add FluidStack tooltips to JEI piston crafting category