Skip to content

Commit

Permalink
Fix #3767 Recipe ID should be shown for all recipes when advanced too…
Browse files Browse the repository at this point in the history
…ltips are enabled
  • Loading branch information
mezz committed Sep 20, 2024
1 parent e64b436 commit 4639a3f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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 <T> @Nullable String getDisplayModId(ITypedIngredient<T> typedIngredient) {
IIngredientManager ingredientManager = Internal.getJeiRuntime().getIngredientManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<T> recipeType = recipeCategory.getRecipeType();
OutputSlotTooltipCallback callback = new OutputSlotTooltipCallback(recipeName, recipeType);
slot.addRichTooltipCallback(callback);
}
}

Expand Down

0 comments on commit 4639a3f

Please sign in to comment.