From 75e8270badee3e4b79b2532b2e2650831d3499e0 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Tue, 4 Jul 2023 20:08:42 +0100 Subject: [PATCH] Fix layout relative to tooltip boxes --- src/main/java/codechicken/nei/ItemsGrid.java | 20 ++++++++++++++----- .../codechicken/nei/recipe/GuiRecipe.java | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/codechicken/nei/ItemsGrid.java b/src/main/java/codechicken/nei/ItemsGrid.java index 8dc665b0..23a04e5d 100644 --- a/src/main/java/codechicken/nei/ItemsGrid.java +++ b/src/main/java/codechicken/nei/ItemsGrid.java @@ -258,6 +258,7 @@ public class ItemsGrid { } private int recipeTooltipSlotIdx = -1; + private int recipeTooltipLines = 2; private Runnable recipeTooltipUpdater = null; private GuiRecipe recipeTooltipGui = null; @@ -276,6 +277,7 @@ public class ItemsGrid { } private void drawRecipeTooltip(int mousex, int mousey) { + final Minecraft mc = Minecraft.getMinecraft(); ItemPanelSlot focused = getSlotMouseOver(mousex, mousey); if (focused == null) { recipeTooltipSlotIdx = -1; @@ -324,6 +326,12 @@ public class ItemsGrid { recipeTooltipGui.guiTop = 0; recipeTooltipGui.guiLeft = 0; } + recipeTooltipLines = 2; + if (focused.item != null && mc.currentScreen instanceof GuiContainer) { + final List tooltip = GuiContainerManager + .itemDisplayNameMultiline(focused.item, (GuiContainer) mc.currentScreen, true); + recipeTooltipLines = tooltip.size(); + } }; } if (recipeTooltipGui == null) { @@ -331,12 +339,14 @@ public class ItemsGrid { } GL11.glPushMatrix(); - GL11.glTranslatef( - mousex, - (mousey > height / 2) ? mousey - recipeTooltipGui.getHeightAsWidget() : mousey + 32, - 100); + final float tooltipYOffset; + if (mousey > height / 2) { + tooltipYOffset = mousey - recipeTooltipGui.getHeightAsWidget() + 8; + } else { + tooltipYOffset = mousey - 7 + (recipeTooltipLines * 10); + } + GL11.glTranslatef(mousex, tooltipYOffset, 100); - final Minecraft mc = Minecraft.getMinecraft(); final GuiContainer gui; if (mc.currentScreen instanceof GuiRecipe) { gui = ((GuiRecipe) mc.currentScreen).firstGui; diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index 0f3a72ca..992bed3b 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -226,7 +226,7 @@ public abstract class GuiRecipe extends GuiContainer i final int recipesPerPage = getRecipesPerPage(); overlayButtons = new GuiButton[recipesPerPage]; final int xOffset = limitToOneRecipe ? (xSize / 2) : (width / 2); - final int yOffset = limitToOneRecipe ? 0 : guiTop; + final int yOffset = limitToOneRecipe ? -14 : guiTop; final String overlayKeyName = NEIClientConfig .getKeyName(NEIClientConfig.getKeyBinding("gui.overlay_use"), true); for (int i = 0; i < recipesPerPage; i++) {