Compare commits

..
Author SHA1 Message Date
Martin Robertz 8870f095e1 Merge remote-tracking branch 'origin/recipe-tooltip' into dev
# Conflicts:
#	src/main/java/codechicken/nei/recipe/GuiRecipe.java
2023-07-08 21:20:10 +02:00
Martin Robertz c91f8ff386 Merge remote-tracking branch 'origin/legacy-handler-compatibility-improvements' into dev 2023-07-08 21:18:31 +02:00
Wilhelm Schuster cd1823712d Fix Thermal Expansion recipe handlers
These handlers expect only two recipes to be displayed at a time. This can only be fixed through asm AFAICT.
2023-07-08 17:21:08 +02:00
Wilhelm Schuster e294abd0a7 Fix Ex Nihilo recipe handlers 2023-07-08 17:21:08 +02:00
Wilhelm Schuster 69c8a653e3 Fix Immersive Engineering recipe handlers 2023-07-08 17:20:30 +02:00
Wilhelm Schuster f7c5b73728 Extend the height hack to also cover guiTop and getRecipePosition
Certain legacy recipe handlers hardcode even more of the NEI recipe
screen layout, requiring only the singular recipe handler switcher
widget at the top, whereas this improved NEI moves the recipe pager to
the top as well expecting recipe handler to move down another 16px. One
such mod that breaks is Immersive Engineering. To fix it we move the top
edge of the gui (guiTop) down by 16px so that the old gap calculation
works correctly. This required special handling in getRecipePosition()
and refreshSlots().
2023-07-08 17:20:30 +02:00
Wilhelm Schuster c11f51624d Store serialhandlers.cfg as an internal asset instead of an array of strings
Is copied into the config directory upon first launch. Also, comments
are now allowed (only from the beginning of the file).

Removes GTNH-specific code to be replaced with a configuration file.
2023-07-08 17:17:39 +02:00
Wilhelm Schuster b63b2d082b Store heighthackhandlers.cfg as an internal asset instead of an array of strings
Is copied into the config directory upon first launch. Also, comments
are now allowed (only from the beginning of the file).
2023-07-08 17:17:39 +02:00
Raven Szewczyk e748c6779b Fix wildcard import 2023-07-04 20:11:20 +01:00
Raven Szewczyk 75e8270bad Fix layout relative to tooltip boxes 2023-07-04 20:08:42 +01:00
Raven Szewczyk c4c7d6d055 Make recipe tooltips configurable and only show in the bookmarks panel 2023-07-04 19:42:08 +01:00
Raven Szewczyk 2630d887eb Show a full recipe widget in item tooltips for bookmarked recipes 2023-07-02 22:50:55 +01:00
Raven Szewczyk f8cc9bd0e6 Update buildscript 2023-06-30 20:59:51 +01:00
9 changed files with 25 additions and 75 deletions

No files matched your search

@@ -468,7 +468,7 @@ public class BookmarkPanel extends PanelWidget {
final ItemStack normalizedA = StackInfo.loadFromNBT(nbTagA);
BookmarkRecipeId recipeId = null;
if (handlerName != "" && ingredients != null) {
if (handlerName != "" && ingredients != null && !ingredients.isEmpty()) {
recipeId = new BookmarkRecipeId(handlerName, ingredients);
}
@@ -478,7 +478,7 @@ public class BookmarkPanel extends PanelWidget {
BGrid.removeRecipe(idx, saveIngredients);
} else {
if (saveIngredients && handlerName != "" && ingredients != null) {
if (saveIngredients && handlerName != "" && ingredients != null && !ingredients.isEmpty()) {
final Map<NBTTagCompound, Integer> unique = new HashMap<>();
final ArrayList<NBTTagCompound> sorted = new ArrayList<>();
+11 -13
View File
@@ -276,11 +276,7 @@ public class ItemsGrid {
return listOrNull == null ? Collections.emptyList() : listOrNull;
}
private void drawRecipeTooltip(int mousex, int mousey, List<String> itemTooltip) {
if (!NEIClientConfig.isLoaded()) {
return;
}
private void drawRecipeTooltip(int mousex, int mousey) {
final Minecraft mc = Minecraft.getMinecraft();
ItemPanelSlot focused = getSlotMouseOver(mousex, mousey);
if (focused == null) {
@@ -330,7 +326,12 @@ public class ItemsGrid {
recipeTooltipGui.guiTop = 0;
recipeTooltipGui.guiLeft = 0;
}
recipeTooltipLines = Math.max(1, itemTooltip.size());
recipeTooltipLines = 2;
if (focused.item != null && mc.currentScreen instanceof GuiContainer) {
final List<String> tooltip = GuiContainerManager
.itemDisplayNameMultiline(focused.item, (GuiContainer) mc.currentScreen, true);
recipeTooltipLines = tooltip.size();
}
};
}
if (recipeTooltipGui == null) {
@@ -339,12 +340,12 @@ public class ItemsGrid {
GL11.glPushMatrix();
final float tooltipYOffset;
if (mousey - marginTop > height / 2) {
if (mousey > height / 2) {
tooltipYOffset = mousey - recipeTooltipGui.getHeightAsWidget() + 8;
} else {
tooltipYOffset = mousey + ((recipeTooltipLines < 2) ? 1 : 3 + ((recipeTooltipLines - 1) * 10));
tooltipYOffset = mousey - 7 + (recipeTooltipLines * 10);
}
GL11.glTranslatef(mousex, tooltipYOffset, 500);
GL11.glTranslatef(mousex, tooltipYOffset, 100);
final GuiContainer gui;
if (mc.currentScreen instanceof GuiRecipe) {
@@ -454,12 +455,9 @@ public class ItemsGrid {
drawSlotOutlines(mousex, mousey);
drawItems();
}
}
public void postDrawTooltips(int mousex, int mousey, List<String> tooltip) {
if (NEIClientConfig.showRecipeTooltips() && showRecipeTooltips) {
try {
drawRecipeTooltip(mousex, mousey, tooltip);
drawRecipeTooltip(mousex, mousey);
} catch (Exception e) {
NEIClientConfig.logger.warn("Cannot draw recipe tooltip", e);
}
@@ -280,13 +280,6 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
}
}
@Override
public void postRenderTooltips(GuiContainer gui, int mousex, int mousey, List<String> tooltip) {
if (!isHidden() && isEnabled()) {
for (Widget widget : drawWidgets) widget.postDrawTooltips(mousex, mousey, tooltip);
}
}
@Override
public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
if (!isHidden() && isEnabled() && GuiContainerManager.shouldShowTooltip(gui)) {
@@ -1,7 +1,6 @@
package codechicken.nei;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
@@ -191,11 +190,6 @@ public abstract class PanelWidget extends Widget {
}
}
@Override
public void postDrawTooltips(int mx, int my, List<String> tooltip) {
grid.postDrawTooltips(mx, my, tooltip);
}
@Override
public void mouseDragged(int mousex, int mousey, int button, long heldTime) {
if (mouseDownSlot >= 0 && draggedStack == null
@@ -14,8 +14,6 @@ public abstract class Widget {
public void postDraw(int mx, int my) {}
public void postDrawTooltips(int mx, int my, List<String> tooltip) {}
public boolean handleClick(int mx, int my, int button) {
return true;
}
@@ -20,10 +20,6 @@ public abstract class ShortcutInputHandler {
public static boolean handleKeyEvent(ItemStack stackover) {
if (!NEIClientConfig.isLoaded()) {
return false;
}
if (NEIClientConfig.isKeyHashDown("gui.overlay_hide")) {
return hideOverlayRecipe();
}
@@ -71,10 +67,6 @@ public abstract class ShortcutInputHandler {
public static boolean handleMouseClick(ItemStack stackover) {
if (!NEIClientConfig.isLoaded()) {
return false;
}
if (stackover != null) {
final int button = Mouse.getEventButton();
stackover = stackover.copy();
@@ -514,10 +514,6 @@ public class GuiContainerManager {
if (tooltip.size() > 0) tooltip.set(0, tooltip.get(0) + GuiDraw.TOOLTIP_LINESPACE); // add space after 'title'
drawPagedTooltip(font, mousex + 12, mousey - 12, tooltip);
for (IContainerDrawHandler drawHandler : drawHandlers) {
drawHandler.postRenderTooltips(window, mousex, mousey, tooltip);
}
}
private static int tooltipPage;
@@ -1,7 +1,5 @@
package codechicken.nei.guihook;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
@@ -32,17 +30,6 @@ public interface IContainerDrawHandler {
*/
public void postRenderObjects(GuiContainer gui, int mousex, int mousey);
/**
* Use this to draw things that should be drawn just after vanilla slot tooltips, on top of buttons and other
* usually always-on-top widgets.
*
* @param gui An instance of the currentscreen
* @param mousex The x position of the mouse in pixels from left
* @param mousey The y position of the mouse in pixels from top
* @param tooltip The contents of the tooltip that has previously been drawn
*/
default void postRenderTooltips(GuiContainer gui, int mousex, int mousey, List<String> tooltip) {}
/**
* Render something over a slot before the item in the slot.
*
@@ -146,29 +146,27 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
private final int trueHeight;
private final int trueGuiTop;
private final GuiScreen trueGui;
private HeightHack() {
trueHeight = height;
trueGuiTop = guiTop;
trueGui = Minecraft.getMinecraft().currentScreen;
isHeightHackApplied = NEIClientConfig.heightHackHandlerRegex.stream()
.map(pattern -> pattern.matcher(handler.getHandlerId())).anyMatch(Matcher::matches);
if (isHeightHackApplied) {
// guiTop is the top edge of the recipe screen on the y-axis. Old recipe handlers expect a single paging
// widget at the top and at the bottom of the recipe screen with a height of 16px each, but GTNH NEI
// moved the bottom paging widget to the top following JEI's design, increasing the "forbidden" zone at
// the top to 32px. To fix these old recipe handlers we move guiTop down 16px so that they can keep
// working with the old 16px gap.
// widget at the top and at the bottom of the recipe screen with a height of 16px, but GTNH NEI move the
// bottom paging widget to the top following JEI's UI increasing the forbidden zone at the top to 32px.
// To fix these old recipe handlers we move guiTop down 16px so that they can keep working with the old
// 16px gap.
guiTop += 16;
// The old NEI recipe screen had a fixed width and height and was always centered on the screen. Legacy
// recipe handlers use the calculation ((height - 166) / 2) to compute the y-value of the top edge of
// the NEI window. GTNH NEI changes the layout so that the recipe screen length now has a flexible
// length and is no longer centered vertically. In order for the top-of-screen calculation to return the
// correct result, we have to hack the height field with an inverse of the calculation using the actual
// top of the recipe screen stored in guiTop.
// the NEI recipe screen. GTNH NEI now has a flexible recipe screen length and is no longer centered
// vertically, so in order for the top-of-screen calculation to return the correct result, we have to
// hack the height field with an inverse of the calculation using the actual top of the recipe screen
// stored in guiTop.
height = (2 * guiTop) + 166;
// For reference, in case we ever need to modify width as well:
@@ -176,12 +174,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
// guiWidth (the x-value of the left edge of the NEI recipe screen). So if we wanted to override width
// as well, we'd do this:
// width = (2 * guiWidth) + 176;
// Recipe handlers may assume the current screen is the GuiRecipe object, which is not the case in
// recipe tooltips drawn on the bookmarks panel with the main inventory open.
if (limitToOneRecipe) {
Minecraft.getMinecraft().currentScreen = GuiRecipe.this;
}
}
}
@@ -189,7 +181,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
public void close() {
guiTop = trueGuiTop;
height = trueHeight;
Minecraft.getMinecraft().currentScreen = trueGui;
isHeightHackApplied = false;
}
}
@@ -252,14 +243,15 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
final int recipesPerPage = getRecipesPerPage();
overlayButtons = new GuiButton[recipesPerPage];
final int xOffset = limitToOneRecipe ? ((xSize / 2) - 2) : (width / 2);
final int xOffset = limitToOneRecipe ? (xSize / 2) : (width / 2);
final int yOffset = limitToOneRecipe ? -14 : guiTop;
final String overlayKeyName = NEIClientConfig
.getKeyName(NEIClientConfig.getKeyBinding("gui.overlay_use"), true);
for (int i = 0; i < recipesPerPage; i++) {
overlayButtons[i] = new GuiNEIButton(
OVERLAY_BUTTON_ID_START + i,
xOffset + 65,
16 + (handlerInfo.getHeight() * (i + 1)) - 2,
yOffset + 16 + (handlerInfo.getHeight() * (i + 1)) - 2,
buttonWidth,
buttonHeight,
"?");
@@ -748,7 +740,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
}
public int getHeightAsWidget() {
return (handlerInfo == null) ? ySize : (handlerInfo.getHeight() + 56);
return (handlerInfo == null) ? ySize : (handlerInfo.getHeight() + 40);
}
@Override