diff --git a/gradle.properties b/gradle.properties index bdabcd729..7f0e2f919 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,4 +5,4 @@ curse_project_id=238222 version_major=3 version_minor=14 -version_patch=5 +version_patch=6 diff --git a/src/main/java/mezz/jei/api/recipe/BlankRecipeCategory.java b/src/main/java/mezz/jei/api/recipe/BlankRecipeCategory.java index d97d37642..8ae656737 100644 --- a/src/main/java/mezz/jei/api/recipe/BlankRecipeCategory.java +++ b/src/main/java/mezz/jei/api/recipe/BlankRecipeCategory.java @@ -2,6 +2,9 @@ import javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; + import mezz.jei.api.gui.IDrawable; import mezz.jei.api.gui.IRecipeLayout; import net.minecraft.client.Minecraft; @@ -31,4 +34,9 @@ public void drawAnimations(Minecraft minecraft) { public void setRecipe(IRecipeLayout recipeLayout, T recipeWrapper) { } + + @Override + public List getTooltipStrings(int mouseX, int mouseY) { + return Collections.emptyList(); + } } diff --git a/src/main/java/mezz/jei/api/recipe/IRecipeCategory.java b/src/main/java/mezz/jei/api/recipe/IRecipeCategory.java index 68b040ee9..848818dc3 100644 --- a/src/main/java/mezz/jei/api/recipe/IRecipeCategory.java +++ b/src/main/java/mezz/jei/api/recipe/IRecipeCategory.java @@ -2,11 +2,15 @@ import javax.annotation.Nullable; +import java.util.List; + import mezz.jei.api.IGuiHelper; import mezz.jei.api.IModRegistry; import mezz.jei.api.gui.IDrawable; import mezz.jei.api.gui.IDrawableAnimated; +import mezz.jei.api.gui.IGuiIngredientGroup; import mezz.jei.api.gui.IRecipeLayout; +import mezz.jei.api.gui.ITooltipCallback; import mezz.jei.api.ingredients.IIngredients; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; @@ -87,4 +91,18 @@ public interface IRecipeCategory { * @since JEI 3.11.0 */ void setRecipe(IRecipeLayout recipeLayout, T recipeWrapper, IIngredients ingredients); + + /** + * Get the tooltip for whatever's under the mouse. + * ItemStack and fluid tooltips are already handled by JEI, this is for anything else. + * + * To add to ingredient tooltips, see {@link IGuiIngredientGroup#addTooltipCallback(ITooltipCallback)} + * To add tooltips for a recipe wrapper, see {@link IRecipeWrapper#getTooltipStrings(int, int)} + * + * @param mouseX the X position of the mouse, relative to the recipe. + * @param mouseY the Y position of the mouse, relative to the recipe. + * @return tooltip strings. If there is no tooltip at this position, return an empty list. + * @since JEI 4.2.5, backported to JEI 3.14.6 + */ + List getTooltipStrings(int mouseX, int mouseY); } diff --git a/src/main/java/mezz/jei/api/recipe/IRecipeWrapper.java b/src/main/java/mezz/jei/api/recipe/IRecipeWrapper.java index f4d56b4e8..9ad47587c 100644 --- a/src/main/java/mezz/jei/api/recipe/IRecipeWrapper.java +++ b/src/main/java/mezz/jei/api/recipe/IRecipeWrapper.java @@ -6,6 +6,8 @@ import mezz.jei.api.IGuiHelper; import mezz.jei.api.gui.IDrawable; import mezz.jei.api.gui.IDrawableAnimated; +import mezz.jei.api.gui.IGuiIngredientGroup; +import mezz.jei.api.gui.ITooltipCallback; import mezz.jei.api.ingredients.IIngredients; import net.minecraft.client.Minecraft; import net.minecraftforge.fluids.FluidStack; @@ -89,6 +91,9 @@ public interface IRecipeWrapper { * Get the tooltip for whatever's under the mouse. * ItemStack and fluid tooltips are already handled by JEI, this is for anything else. * + * To add to ingredient tooltips, see {@link IGuiIngredientGroup#addTooltipCallback(ITooltipCallback)} + * To add tooltips for a recipe category, see {@link IRecipeCategory#getTooltipStrings(int, int)} + * * @param mouseX the X position of the mouse, relative to the recipe. * @param mouseY the Y position of the mouse, relative to the recipe. * @return tooltip strings. If there is no tooltip at this position, return null or an empty list. diff --git a/src/main/java/mezz/jei/gui/recipes/RecipeLayout.java b/src/main/java/mezz/jei/gui/recipes/RecipeLayout.java index 1960b90f8..8de52fcd1 100644 --- a/src/main/java/mezz/jei/gui/recipes/RecipeLayout.java +++ b/src/main/java/mezz/jei/gui/recipes/RecipeLayout.java @@ -2,6 +2,7 @@ import javax.annotation.Nullable; import java.util.HashMap; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -137,8 +138,18 @@ public void draw(Minecraft minecraft, final int mouseX, final int mouseY) { if (hoveredIngredient != null) { hoveredIngredient.drawHovered(minecraft, posX, posY, recipeMouseX, recipeMouseY); } else if (isMouseOver(mouseX, mouseY)) { - List tooltipStrings = recipeWrapper.getTooltipStrings(recipeMouseX, recipeMouseY); - if (tooltipStrings != null && !tooltipStrings.isEmpty()) { + List tooltipStrings = new ArrayList(); + try { + //noinspection unchecked + tooltipStrings.addAll(recipeCategory.getTooltipStrings(recipeMouseX, recipeMouseY)); + } catch (AbstractMethodError ignored) { + // legacy recipe categories do not have this method + } + List wrapperTooltip = recipeWrapper.getTooltipStrings(recipeMouseX, recipeMouseY); + if (wrapperTooltip != null) { + tooltipStrings.addAll(wrapperTooltip); + } + if (!tooltipStrings.isEmpty()) { TooltipRenderer.drawHoveringText(minecraft, tooltipStrings, mouseX, mouseY); } } diff --git a/src/main/java/mezz/jei/plugins/jei/debug/DebugRecipeCategory.java b/src/main/java/mezz/jei/plugins/jei/debug/DebugRecipeCategory.java index 3d0b01b29..cdb80f79e 100644 --- a/src/main/java/mezz/jei/plugins/jei/debug/DebugRecipeCategory.java +++ b/src/main/java/mezz/jei/plugins/jei/debug/DebugRecipeCategory.java @@ -1,5 +1,6 @@ package mezz.jei.plugins.jei.debug; +import java.util.Collections; import java.util.List; import mezz.jei.api.IGuiHelper; @@ -137,4 +138,9 @@ public void onTooltip(int slotIndex, boolean input, DebugIngredient ingredient, debugIngredientsGroup.set(ingredients); } + + @Override + public List getTooltipStrings(int mouseX, int mouseY) { + return Collections.singletonList("Debug Recipe Category Tooltip"); + } }