Skip to content

Commit

Permalink
Close #729 add IRecipeCategory#getTooltipStrings
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Feb 12, 2017
1 parent e133807 commit d63d22a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -5,4 +5,4 @@ curse_project_id=238222

version_major=3
version_minor=14
version_patch=5
version_patch=6
8 changes: 8 additions & 0 deletions src/main/java/mezz/jei/api/recipe/BlankRecipeCategory.java
Expand Up @@ -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;
Expand Down Expand Up @@ -31,4 +34,9 @@ public void drawAnimations(Minecraft minecraft) {
public void setRecipe(IRecipeLayout recipeLayout, T recipeWrapper) {

}

@Override
public List<String> getTooltipStrings(int mouseX, int mouseY) {
return Collections.emptyList();
}
}
18 changes: 18 additions & 0 deletions src/main/java/mezz/jei/api/recipe/IRecipeCategory.java
Expand Up @@ -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;
Expand Down Expand Up @@ -87,4 +91,18 @@ public interface IRecipeCategory<T extends IRecipeWrapper> {
* @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<String> getTooltipStrings(int mouseX, int mouseY);
}
5 changes: 5 additions & 0 deletions src/main/java/mezz/jei/api/recipe/IRecipeWrapper.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/mezz/jei/gui/recipes/RecipeLayout.java
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -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<String> tooltipStrings = recipeWrapper.getTooltipStrings(recipeMouseX, recipeMouseY);
if (tooltipStrings != null && !tooltipStrings.isEmpty()) {
List<String> tooltipStrings = new ArrayList<String>();
try {
//noinspection unchecked
tooltipStrings.addAll(recipeCategory.getTooltipStrings(recipeMouseX, recipeMouseY));
} catch (AbstractMethodError ignored) {
// legacy recipe categories do not have this method
}
List<String> wrapperTooltip = recipeWrapper.getTooltipStrings(recipeMouseX, recipeMouseY);
if (wrapperTooltip != null) {
tooltipStrings.addAll(wrapperTooltip);
}
if (!tooltipStrings.isEmpty()) {
TooltipRenderer.drawHoveringText(minecraft, tooltipStrings, mouseX, mouseY);
}
}
Expand Down
@@ -1,5 +1,6 @@
package mezz.jei.plugins.jei.debug;

import java.util.Collections;
import java.util.List;

import mezz.jei.api.IGuiHelper;
Expand Down Expand Up @@ -137,4 +138,9 @@ public void onTooltip(int slotIndex, boolean input, DebugIngredient ingredient,

debugIngredientsGroup.set(ingredients);
}

@Override
public List<String> getTooltipStrings(int mouseX, int mouseY) {
return Collections.singletonList("Debug Recipe Category Tooltip");
}
}

0 comments on commit d63d22a

Please sign in to comment.