Compare commits

...
Author SHA1 Message Date
Ranzu 805b90d6f8 Add debug text localization and tooltips (#854) 2026-02-03 17:58:20 +02:00
RanzuandMartin Robertz 900b9f90e7 Added show all handlers and recipes function (#852)
Co-authored-by: Martin Robertz <[email protected]>
2026-02-03 15:38:35 +02:00
5 changed files with 152 additions and 10 deletions

No files matched your search

@@ -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<String, String> 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<String, String> 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;
}
@@ -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<ICraftingHandler> {
@@ -77,7 +78,9 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
ArrayList<ICraftingHandler> serialCraftingHandlers = GuiCraftingRecipe.serialCraftingHandlers;
UnaryOperator<ICraftingHandler> 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<ICraftingHandler> {
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<ICraftingHandler> filterByHandlerName(ArrayList<ICraftingHandler> craftinghandlers,
String handlerName) {
return craftinghandlers.stream().filter(h -> getHandlerName(h).equals(handlerName))
@@ -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<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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<H extends IRecipeHandler> 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;
@@ -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<IUsageHandler> {
@@ -38,12 +39,10 @@ public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
&& 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<IUsageHandler> {
public static ArrayList<IUsageHandler> getUsageHandlers(String inputId, Object... ingredients) {
final RecipeHandlerQuery<IUsageHandler> 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<IUsageHandler> 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) {
@@ -519,8 +519,23 @@ 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
nei.recipe.shaped=Shaped Crafting
nei.recipe.shapeless=Shapeless Crafting
nei.recipe.furnace=Smelting