Skip to content

Commit

Permalink
Add ITooltipBuilder#clear to allow advanced modifications of tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Sep 3, 2024
1 parent bcc8fcc commit 95d14d0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Common/src/main/java/mezz/jei/common/gui/JeiTooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public void addAll(Collection<? extends FormattedText> components) {
}
}

@Override
public void clear() {
this.lines.clear();
this.typedIngredient = null;
}

public void addAll(JeiTooltip tooltip) {
lines.addAll(tooltip.lines);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public interface ITooltipBuilder {
*/
void setIngredient(ITypedIngredient<?> typedIngredient);

/**
* Remove all the lines and ingredients from this tooltip.
*
* @since 19.16.4
*/
void clear();

/**
* @deprecated this is only for legacy tooltip support and will be removed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public void setIngredient(ITypedIngredient<?> typedIngredient) {
// ignored for the purposes of searching tooltips
}

@Override
public void clear() {
tooltip.clear();
}

@SuppressWarnings("removal")
@Override
public List<Component> toLegacyToComponents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,11 @@ private <T> void getTooltip(ITooltipBuilder tooltip, ITypedIngredient<T> typedIn
IIngredientType<T> ingredientType = typedIngredient.getType();
IIngredientRenderer<T> ingredientRenderer = getIngredientRenderer(ingredientType);
SafeIngredientUtil.getTooltip(tooltip, ingredientManager, ingredientRenderer, typedIngredient);
addTagNameTooltip(tooltip, ingredientManager, typedIngredient);
addIngredientsToTooltip(tooltip, typedIngredient);
for (IRecipeSlotRichTooltipCallback tooltipCallback : this.tooltipCallbacks) {
tooltipCallback.onRichTooltip(this, tooltip);
}

addTagNameTooltip(tooltip, ingredientManager, typedIngredient);
addIngredientsToTooltip(tooltip, typedIngredient);
}

private <T> List<Component> legacyGetTooltip(ITypedIngredient<T> typedIngredient) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ curseHomepageUrl=https://www.curseforge.com/minecraft/mc-mods/jei
jUnitVersion=5.8.2

# Version
specificationVersion=19.16.3
specificationVersion=19.16.4

0 comments on commit 95d14d0

Please sign in to comment.