From 900b9f90e7cfb44413cc02b492f560f8f7465b9d Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Tue, 3 Feb 2026 14:38:35 +0100 Subject: [PATCH 1/2] Added show all handlers and recipes function (#852) Co-authored-by: Martin Robertz --- .../nei/recipe/GuiCraftingRecipe.java | 23 +++++++++++- .../codechicken/nei/recipe/GuiRecipe.java | 36 ++++++++++++++++++- .../nei/recipe/GuiUsageRecipe.java | 29 ++++++++++++--- src/main/resources/assets/nei/lang/en_US.lang | 1 + 4 files changed, 83 insertions(+), 6 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/GuiCraftingRecipe.java b/src/main/java/codechicken/nei/recipe/GuiCraftingRecipe.java index 22cde1e5..3bc0781a 100644 --- a/src/main/java/codechicken/nei/recipe/GuiCraftingRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiCraftingRecipe.java @@ -21,6 +21,7 @@ import codechicken.nei.NEIClientUtils; import codechicken.nei.bookmark.BookmarkItem.BookmarkItemType; import codechicken.nei.bookmark.BookmarksGridSlot; import codechicken.nei.recipe.Recipe.RecipeId; +import codechicken.nei.recipe.TemplateRecipeHandler.RecipeTransferRect; public class GuiCraftingRecipe extends GuiRecipe { @@ -77,7 +78,9 @@ public class GuiCraftingRecipe extends GuiRecipe { ArrayList serialCraftingHandlers = GuiCraftingRecipe.serialCraftingHandlers; UnaryOperator recipeHandlerFunction; - if ("recipeId".equals(outputId)) { + if ("all".equals(outputId)) { + recipeHandlerFunction = GuiCraftingRecipe::buildAllRecipesHandler; + } else if ("recipeId".equals(outputId)) { ItemStack stack = (ItemStack) results[0]; RecipeId recipeId = (RecipeId) results[1]; craftinghandlers = filterByHandlerName(craftinghandlers, recipeId.getHandleName()); @@ -98,6 +101,24 @@ public class GuiCraftingRecipe extends GuiRecipe { return recipeQuery.runWithProfiling(NEIClientUtils.translate("recipe.concurrent.crafting")); } + private static ICraftingHandler buildAllRecipesHandler(ICraftingHandler handler) { + if (handler instanceof TemplateRecipeHandler templateHandler) { + TemplateRecipeHandler allHandler = templateHandler.newInstance(); + if (allHandler.transferRects.isEmpty()) { + allHandler.loadCraftingRecipes("all"); + return allHandler; + } + for (RecipeTransferRect rect : allHandler.transferRects) { + if (allHandler.specifyTransferRect() == null + || allHandler.specifyTransferRect().equals(rect.outputId)) { + allHandler.loadCraftingRecipes(rect.outputId, rect.results); + return allHandler; + } + } + } + return handler.getRecipeHandler("all"); + } + private static ArrayList filterByHandlerName(ArrayList craftinghandlers, String handlerName) { return craftinghandlers.stream().filter(h -> getHandlerName(h).equals(handlerName)) diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index 55808b38..4cf5e9c9 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -17,6 +17,7 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @@ -603,6 +604,15 @@ public abstract class GuiRecipe extends GuiContainer i return; } + if (button == 0 && isHandlerTitleHovered(mousex, mousey)) { + if (this instanceof GuiCraftingRecipe) { + GuiCraftingRecipe.openRecipeGui("all"); + } else if (this instanceof GuiUsageRecipe) { + GuiUsageRecipe.openRecipeGui("all"); + } + return; + } + super.mouseClicked(mousex, mousey, button); } @@ -708,6 +718,10 @@ public abstract class GuiRecipe extends GuiContainer i this.recipeTabs.handleTooltip(mousex, mousey, currenttip); + if (currenttip.isEmpty() && isHandlerTitleHovered(mousex, mousey)) { + currenttip.add(NEIClientUtils.translate("recipe.tab.view_all.tooltip")); + } + if (currenttip.isEmpty() && GuiRecipe.searchField.isVisible() && new Rectangle(GuiRecipe.searchField.x + GuiRecipe.searchField.w, 15, 44, 16) .contains(mousex - this.guiLeft, mousey - this.guiTop)) { @@ -822,9 +836,11 @@ public abstract class GuiRecipe extends GuiContainer i this.prevpage.yPosition + BUTTON_HEIGHT, 0x30000000); + final String handlerTitle = this.handler.original.getRecipeName().trim(); + final String titleColorCode = getHandlerTitleColorCode(isHandlerTitleHovered(mouseX, mouseY)); drawCenteredString( this.fontRendererObj, - this.handler.original.getRecipeName().trim(), + titleColorCode + handlerTitle + EnumChatFormatting.RESET, this.guiLeft + this.xSize / 2, this.prevtype.yPosition + textMiddle, 0xffffff); @@ -872,6 +888,24 @@ public abstract class GuiRecipe extends GuiContainer i } } + private boolean isHandlerTitleHovered(int mousex, int mousey) { + final String handlerTitle = this.handler.original.getRecipeName().trim(); + final int titleWidth = this.fontRendererObj.getStringWidth(handlerTitle); + final int textMiddle = (BUTTON_WIDTH - this.fontRendererObj.FONT_HEIGHT) / 2; + final int titleX = this.guiLeft + (this.xSize - titleWidth) / 2; + final int titleY = this.prevtype.yPosition + textMiddle; + return new Rectangle(titleX, titleY, titleWidth, this.fontRendererObj.FONT_HEIGHT).contains(mousex, mousey); + } + + private String getHandlerTitleColorCode(boolean hovered) { + final String key = hovered ? "recipe.title.color.hover" : "recipe.title.color.normal"; + final String translated = NEIClientUtils.translate(key); + if (!translated.startsWith("nei.")) { // Optional localization string for resource packs + return translated; + } + return hovered ? EnumChatFormatting.YELLOW.toString() : EnumChatFormatting.WHITE.toString(); + } + @Override public GuiContainer getFirstScreen() { return this.firstGui; diff --git a/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java b/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java index 03513db5..743240da 100644 --- a/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiUsageRecipe.java @@ -12,6 +12,7 @@ import codechicken.nei.ItemPanels; import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientUtils; import codechicken.nei.recipe.Recipe.RecipeId; +import codechicken.nei.recipe.TemplateRecipeHandler.RecipeTransferRect; public class GuiUsageRecipe extends GuiRecipe { @@ -38,12 +39,10 @@ public class GuiUsageRecipe extends GuiRecipe { && ingredients[0] instanceof ItemStack stack) { ItemPanels.itemPanel.historyPanel.addItem(stack); } - mc.displayGuiScreen(gui); gui.openTargetRecipe(recipeId); return true; } - return false; } @@ -55,14 +54,36 @@ public class GuiUsageRecipe extends GuiRecipe { public static ArrayList getUsageHandlers(String inputId, Object... ingredients) { final RecipeHandlerQuery recipeQuery = new RecipeHandlerQuery<>( - h -> getUsageOrCatalystHandler(h, inputId, ingredients), + "all".equals(inputId) ? GuiUsageRecipe::buildAllRecipesHandler + : h -> getUsageOrCatalystHandler(h, inputId, ingredients), GuiUsageRecipe.usagehandlers, GuiUsageRecipe.serialUsageHandlers, "Error while looking up usage recipe", "inputId: " + inputId, "ingredients: " + Arrays.toString(ingredients)); - return recipeQuery.runWithProfiling(NEIClientUtils.translate("recipe.concurrent.usage")); + ArrayList handlers = recipeQuery + .runWithProfiling(NEIClientUtils.translate("recipe.concurrent.usage")); + return handlers; + } + + private static IUsageHandler buildAllRecipesHandler(IUsageHandler handler) { + if (handler instanceof TemplateRecipeHandler templateHandler) { + TemplateRecipeHandler allHandler = templateHandler.newInstance(); + if (allHandler.transferRects.isEmpty()) { + allHandler.loadCraftingRecipes("all"); + return allHandler; + } + for (RecipeTransferRect rect : allHandler.transferRects) { + if (allHandler.specifyTransferRect() == null + || allHandler.specifyTransferRect().equals(rect.outputId)) { + allHandler.loadCraftingRecipes(rect.outputId, rect.results); + return allHandler; + } + } + + } + return handler.getUsageHandler("all"); } public static void registerUsageHandler(IUsageHandler handler) { diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index 7d659aeb..33913424 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -521,6 +521,7 @@ nei.options.tools.dump.handlers.mode.1=Json nei.recipe.page=Page %s/%s nei.recipe.tooltip=Recipes +nei.recipe.tab.view_all.tooltip=View all categories nei.recipe.shaped=Shaped Crafting nei.recipe.shapeless=Shapeless Crafting nei.recipe.furnace=Smelting From 805b90d6f8f184df3ca26f9525fa2b603535f5ef Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Tue, 3 Feb 2026 16:58:20 +0100 Subject: [PATCH 2/2] Add debug text localization and tooltips (#854) --- .../nei/recipe/DebugHandlerWidget.java | 59 +++++++++++++++++-- src/main/resources/assets/nei/lang/en_US.lang | 14 +++++ 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/DebugHandlerWidget.java b/src/main/java/codechicken/nei/recipe/DebugHandlerWidget.java index 0c624ba9..5ea84073 100644 --- a/src/main/java/codechicken/nei/recipe/DebugHandlerWidget.java +++ b/src/main/java/codechicken/nei/recipe/DebugHandlerWidget.java @@ -17,6 +17,7 @@ import java.util.stream.Collectors; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.util.EnumChatFormatting; import org.apache.commons.io.IOUtils; import org.lwjgl.input.Keyboard; @@ -133,6 +134,23 @@ public class DebugHandlerWidget extends Widget implements IContainerInputHandler private static final int BORDER_PADDING = 6; private static final int TRANSPARENCY_BORDER = 4; + private static final String TOOLTIP_PREFIX = "debug.RecipeHandler."; + private static final Map TOOLTIP_KEYS = new HashMap<>(); + + static { + TOOLTIP_KEYS.put("Name", TOOLTIP_PREFIX + "Name"); + TOOLTIP_KEYS.put("ID", TOOLTIP_PREFIX + "Id"); + TOOLTIP_KEYS.put("Key", TOOLTIP_PREFIX + "Key"); + TOOLTIP_KEYS.put("H.Hack", TOOLTIP_PREFIX + "HHack"); + TOOLTIP_KEYS.put("Mod Name", TOOLTIP_PREFIX + "ModName"); + TOOLTIP_KEYS.put("Mod ID", TOOLTIP_PREFIX + "ModId"); + TOOLTIP_KEYS.put("Order", TOOLTIP_PREFIX + "Order"); + TOOLTIP_KEYS.put("yShift", TOOLTIP_PREFIX + "yShift"); + TOOLTIP_KEYS.put("Multi Widgets", TOOLTIP_PREFIX + "MultiWidgets"); + TOOLTIP_KEYS.put("Height", TOOLTIP_PREFIX + "Height"); + TOOLTIP_KEYS.put("Width", TOOLTIP_PREFIX + "Width"); + TOOLTIP_KEYS.put("Use Custom Scroll", TOOLTIP_PREFIX + "UseCustomScroll"); + } private final DrawableResource BG_TEXTURE = new DrawableBuilder( "nei:textures/gui/recipebg.png", 0, @@ -277,8 +295,9 @@ public class DebugHandlerWidget extends Widget implements IContainerInputHandler } private void drawKeyLabel(String keyLabel, int topShift) { + final String displayLabel = translateDisplayLabel(keyLabel); GuiDraw.drawString( - NEIClientUtils.cropText(GuiDraw.fontRenderer, keyLabel, LABEL_WIDTH), + NEIClientUtils.cropText(GuiDraw.fontRenderer, displayLabel, LABEL_WIDTH), this.x + INLINE_PADDING, topShift, 0x66555555, @@ -306,6 +325,24 @@ public class DebugHandlerWidget extends Widget implements IContainerInputHandler field.w = this.w - INLINE_PADDING * 2 - LABEL_WIDTH - spaceWidth; } + private static String translateTooltipLabel(String label) { + String key = TOOLTIP_KEYS.get(label); + String text = label; + if (key == null) { + return EnumChatFormatting.WHITE + EnumChatFormatting.getTextWithoutFormattingCodes(text); + } + text = NEIClientUtils.translate(key); + return EnumChatFormatting.WHITE + EnumChatFormatting.getTextWithoutFormattingCodes(text); + } + + private static String translateDisplayLabel(String label) { + String key = TOOLTIP_KEYS.get(label); + if (key == null) { + return label; + } + return NEIClientUtils.translate(key); + } + @Override public void draw(int mx, int my) { @@ -331,7 +368,11 @@ public class DebugHandlerWidget extends Widget implements IContainerInputHandler this.w - INLINE_PADDING * 2, 12, 0x30000000); - GuiDraw.drawStringC("Debug Recipe Handler", this.x + this.w / 2, this.y + BORDER_PADDING + 2, 0xffffff); + GuiDraw.drawStringC( + NEIClientUtils.translate("debug.RecipeHandler.title"), + this.x + this.w / 2, + this.y + BORDER_PADDING + 2, + 0xffffff); for (Map.Entry entry : getDetailsInfo().entrySet()) { drawDetail(entry.getKey(), entry.getValue(), topShift, spaceWidth); @@ -424,12 +465,22 @@ public class DebugHandlerWidget extends Widget implements IContainerInputHandler if (my >= topShift && my < topShift + LINE_HEIGHT) { if (mx < leftShift + LABEL_WIDTH + spaceWidth) { - tooltip.add(String.valueOf(entry.getKey())); + tooltip.add(translateTooltipLabel(entry.getKey())); } else { tooltip.add(String.valueOf(entry.getValue())); } - break; + return tooltip; + } + topShift += LINE_HEIGHT; + } + + String[] controlLabels = new String[] { "Order", "yShift", "Multi Widgets", "Height", "Width", + "Use Custom Scroll" }; + for (String label : controlLabels) { + if (my >= topShift && my < topShift + LINE_HEIGHT) { + tooltip.add(translateTooltipLabel(label)); + return tooltip; } topShift += LINE_HEIGHT; } diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index 33913424..174f2c61 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -519,6 +519,20 @@ nei.options.tools.dump.handlers.dumped=handlers were dumped to %s nei.options.tools.dump.handlers.mode.0=CSV nei.options.tools.dump.handlers.mode.1=Json +nei.debug.RecipeHandler.title=Debug Recipe Handler +nei.debug.RecipeHandler.Name=Name +nei.debug.RecipeHandler.Id=ID +nei.debug.RecipeHandler.Key=Key +nei.debug.RecipeHandler.HHack=H.Hack +nei.debug.RecipeHandler.ModName=Mod Name +nei.debug.RecipeHandler.ModId=Mod ID +nei.debug.RecipeHandler.Order=Order +nei.debug.RecipeHandler.yShift=yShift +nei.debug.RecipeHandler.MultiWidgets=Multi Widgets +nei.debug.RecipeHandler.Height=Height +nei.debug.RecipeHandler.Width=Width +nei.debug.RecipeHandler.UseCustomScroll=Use Custom Scroll + nei.recipe.page=Page %s/%s nei.recipe.tooltip=Recipes nei.recipe.tab.view_all.tooltip=View all categories