From f3d92bdc6889625eb620f80a328b9e630cc311e7 Mon Sep 17 00:00:00 2001 From: mezz Date: Fri, 20 Sep 2024 14:45:55 +0900 Subject: [PATCH] Fix #3767 Recipe ID should be shown for all recipes when advanced tooltips are enabled --- .../recipes/OutputSlotTooltipCallback.java | 39 ++++++++++++------- .../layout/builder/RecipeLayoutBuilder.java | 9 ++--- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Library/src/main/java/mezz/jei/library/gui/recipes/OutputSlotTooltipCallback.java b/Library/src/main/java/mezz/jei/library/gui/recipes/OutputSlotTooltipCallback.java index e95265b76..06d22ea8c 100644 --- a/Library/src/main/java/mezz/jei/library/gui/recipes/OutputSlotTooltipCallback.java +++ b/Library/src/main/java/mezz/jei/library/gui/recipes/OutputSlotTooltipCallback.java @@ -8,6 +8,7 @@ import mezz.jei.api.ingredients.IIngredientType; import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.recipe.RecipeIngredientRole; +import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.runtime.IIngredientManager; import mezz.jei.common.Internal; import mezz.jei.common.util.ErrorUtil; @@ -27,9 +28,11 @@ public class OutputSlotTooltipCallback implements IRecipeSlotRichTooltipCallback private static final Logger LOGGER = LogManager.getLogger(); private final ResourceLocation recipeName; + private final boolean recipeFromSameModAsCategory; - public OutputSlotTooltipCallback(ResourceLocation recipeName) { + public OutputSlotTooltipCallback(ResourceLocation recipeName, RecipeType recipeType) { this.recipeName = recipeName; + this.recipeFromSameModAsCategory = recipeName.getNamespace().equals(recipeType.getUid().getNamespace()); } @Override @@ -42,18 +45,7 @@ public void onRichTooltip(IRecipeSlotView recipeSlotView, ITooltipBuilder toolti return; } - IModIdHelper modIdHelper = Internal.getJeiRuntime().getJeiHelpers().getModIdHelper(); - if (modIdHelper.isDisplayingModNameEnabled()) { - String ingredientModId = getDisplayModId(displayedIngredient.get()); - if (ingredientModId != null) { - String recipeModId = recipeName.getNamespace(); - if (!recipeModId.equals(ingredientModId)) { - String modName = modIdHelper.getFormattedModNameForModId(recipeModId); - MutableComponent recipeBy = Component.translatable("jei.tooltip.recipe.by", modName); - tooltip.add(recipeBy.withStyle(ChatFormatting.GRAY)); - } - } - } + addRecipeBy(tooltip, displayedIngredient.get()); Minecraft minecraft = Minecraft.getInstance(); boolean showAdvanced = minecraft.options.advancedItemTooltips || Screen.hasShiftDown(); @@ -63,6 +55,27 @@ public void onRichTooltip(IRecipeSlotView recipeSlotView, ITooltipBuilder toolti } } + private void addRecipeBy(ITooltipBuilder tooltip, ITypedIngredient displayedIngredient) { + if (recipeFromSameModAsCategory) { + return; + } + IModIdHelper modIdHelper = Internal.getJeiRuntime().getJeiHelpers().getModIdHelper(); + if (!modIdHelper.isDisplayingModNameEnabled()) { + return; + } + String ingredientModId = getDisplayModId(displayedIngredient); + if (ingredientModId == null) { + return; + } + String recipeModId = recipeName.getNamespace(); + if (recipeModId.equals(ingredientModId)) { + return; + } + String modName = modIdHelper.getFormattedModNameForModId(recipeModId); + MutableComponent recipeBy = Component.translatable("jei.tooltip.recipe.by", modName); + tooltip.add(recipeBy.withStyle(ChatFormatting.GRAY)); + } + private @Nullable String getDisplayModId(ITypedIngredient typedIngredient) { IIngredientManager ingredientManager = Internal.getJeiRuntime().getIngredientManager(); diff --git a/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java b/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java index a21d6bf83..9d127190c 100644 --- a/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java +++ b/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java @@ -17,6 +17,7 @@ import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.recipe.IFocusGroup; import mezz.jei.api.recipe.RecipeIngredientRole; +import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.recipe.category.IRecipeCategory; import mezz.jei.api.recipe.category.extensions.IRecipeCategoryDecorator; import mezz.jei.api.runtime.IIngredientManager; @@ -97,11 +98,9 @@ public IRecipeSlotBuilder addSlotToWidget(RecipeIngredientRole role, ISlottedWid private void addOutputSlotTooltipCallback(RecipeSlotBuilder slot) { ResourceLocation recipeName = recipeCategory.getRegistryName(recipe); if (recipeName != null) { - ResourceLocation recipeTypeUid = recipeCategory.getRecipeType().getUid(); - if (!recipeTypeUid.getNamespace().equals(recipeName.getNamespace())) { - OutputSlotTooltipCallback callback = new OutputSlotTooltipCallback(recipeName); - slot.addRichTooltipCallback(callback); - } + RecipeType recipeType = recipeCategory.getRecipeType(); + OutputSlotTooltipCallback callback = new OutputSlotTooltipCallback(recipeName, recipeType); + slot.addRichTooltipCallback(callback); } }