From 7526075847597874fcd2a7b29851c7857e935161 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sat, 15 Jul 2023 08:32:21 +0100 Subject: [PATCH 01/10] Unconditionally override Minecraft.currentScreen when drawing tooltips --- .gitignore | 11 +- build.gradle | 122 +++++++++++++++--- .../codechicken/nei/recipe/GuiRecipe.java | 10 +- 3 files changed, 120 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 1a2b7a06..5f5fc937 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .gradle .settings /.idea/ +/.vscode/ /run/ /build/ /eclipse/ @@ -25,6 +26,12 @@ whitelist.json *.iml *.ipr *.iws -src/main/resources/mixins.*.json +src/main/resources/mixins.*([!.]).json *.bat -.DS_Store +*.DS_Store +!gradlew.bat +.factorypath +addon.local.gradle +addon.local.gradle.kts +addon.late.local.gradle +addon.late.local.gradle.kts diff --git a/build.gradle b/build.gradle index 39309904..35dd43ef 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1685785062 +//version: 1689101527 /* DO NOT CHANGE THIS FILE! Also, you may replace this file at any time if there is an update available. @@ -69,7 +69,7 @@ plugins { id 'com.diffplug.spotless' version '6.13.0' apply false // 6.13.0 is the last jvm8 supporting version id 'com.modrinth.minotaur' version '2.+' apply false id 'com.matthewprenger.cursegradle' version '1.4.0' apply false - id 'com.gtnewhorizons.retrofuturagradle' version '1.3.14' + id 'com.gtnewhorizons.retrofuturagradle' version '1.3.19' } print("You might want to check out './gradlew :faq' if your build fails.\n") @@ -115,6 +115,8 @@ propertyDefaultIfUnset("usesMixinDebug", project.usesMixins) propertyDefaultIfUnset("forceEnableMixins", false) propertyDefaultIfUnset("channel", "stable") propertyDefaultIfUnset("mappingsVersion", "12") +propertyDefaultIfUnset("usesMavenPublishing", true) +propertyDefaultIfUnset("mavenPublishUrl", "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases") propertyDefaultIfUnset("modrinthProjectId", "") propertyDefaultIfUnset("modrinthRelations", "") propertyDefaultIfUnset("curseForgeProjectId", "") @@ -357,7 +359,24 @@ catch (Exception ignored) { String identifiedVersion String versionOverride = System.getenv("VERSION") ?: null try { - identifiedVersion = versionOverride == null ? gitVersion() : versionOverride + // Produce a version based on the tag, or for branches something like 0.2.2-configurable-maven-and-extras.38+43090270b6-dirty + if (versionOverride == null) { + def gitDetails = versionDetails() + def isDirty = gitVersion().endsWith(".dirty") // No public API for this, isCleanTag has a different meaning + String branchName = gitDetails.branchName + branchName = branchName.replaceAll("[^a-zA-Z0-9-]+", "-") // sanitize branch names for semver + identifiedVersion = gitDetails.lastTag + if (gitDetails.commitDistance > 0) { + identifiedVersion += "-${branchName}.${gitDetails.commitDistance}+${gitDetails.gitHash}" + if (isDirty) { + identifiedVersion += "-dirty" + } + } else if (isDirty) { + identifiedVersion += "-${branchName}+${gitDetails.gitHash}-dirty" + } + } else { + identifiedVersion = versionOverride + } } catch (Exception ignored) { out.style(Style.Failure).text( @@ -465,10 +484,19 @@ sourceSets { } } -if (file('addon.gradle').exists()) { +if (file('addon.gradle.kts').exists()) { + apply from: 'addon.gradle.kts' +} else if (file('addon.gradle').exists()) { apply from: 'addon.gradle' } +// File for local tweaks not commited to Git +if (file('addon.local.gradle.kts').exists()) { + apply from: 'addon.local.gradle.kts' +} else if (file('addon.local.gradle').exists()) { + apply from: 'addon.local.gradle' +} + // Allow unsafe repos but warn repositories.configureEach { repo -> if (repo instanceof org.gradle.api.artifacts.repositories.UrlArtifactRepository) { @@ -479,7 +507,14 @@ repositories.configureEach { repo -> } } -apply from: 'repositories.gradle' +if (file('repositories.gradle.kts').exists()) { + apply from: 'repositories.gradle.kts' +} else if (file('repositories.gradle').exists()) { + apply from: 'repositories.gradle' +} else { + logger.error("Neither repositories.gradle.kts nor repositories.gradle was found, make sure you extracted the full ExampleMod template.") + throw new RuntimeException("Missing repositories.gradle[.kts]") +} configurations { runtimeClasspath.extendsFrom(runtimeOnlyNonPublishable) @@ -611,7 +646,32 @@ configurations.all { } } -apply from: 'dependencies.gradle' +dependencies { + constraints { + def minGtnhLibVersion = "0.0.13" + implementation("com.github.GTNewHorizons:GTNHLib:${minGtnhLibVersion}") { + because("fixes duplicate mod errors in java 17 configurations using old gtnhlib") + } + runtimeOnly("com.github.GTNewHorizons:GTNHLib:${minGtnhLibVersion}") { + because("fixes duplicate mod errors in java 17 configurations using old gtnhlib") + } + devOnlyNonPublishable("com.github.GTNewHorizons:GTNHLib:${minGtnhLibVersion}") { + because("fixes duplicate mod errors in java 17 configurations using old gtnhlib") + } + runtimeOnlyNonPublishable("com.github.GTNewHorizons:GTNHLib:${minGtnhLibVersion}") { + because("fixes duplicate mod errors in java 17 configurations using old gtnhlib") + } + } +} + +if (file('dependencies.gradle.kts').exists()) { + apply from: 'dependencies.gradle.kts' +} else if (file('dependencies.gradle').exists()) { + apply from: 'dependencies.gradle' +} else { + logger.error("Neither dependencies.gradle.kts nor dependencies.gradle was found, make sure you extracted the full ExampleMod template.") + throw new RuntimeException("Missing dependencies.gradle[.kts]") +} def mixingConfigRefMap = 'mixins.' + modId + '.refmap.json' def mixinTmpDir = buildDir.path + File.separator + 'tmp' + File.separator + 'mixins' @@ -724,13 +784,13 @@ ext.java17PatchDependenciesCfg = configurations.create("java17PatchDependencies" } dependencies { - def lwjgl3ifyVersion = '1.3.5' + def lwjgl3ifyVersion = '1.4.0' def asmVersion = '9.4' if (modId != 'lwjgl3ify') { java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}") } if (modId != 'hodgepodge') { - java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.13') + java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.19') } java17PatchDependencies('net.minecraft:launchwrapper:1.15') {transitive = false} @@ -979,6 +1039,9 @@ idea { } } runConfigurations { + "0. Build and Test"(Gradle) { + taskNames = ["build"] + } "1. Run Client"(Gradle) { taskNames = ["runClient"] } @@ -1098,6 +1161,11 @@ tasks.named("processIdeaSettings").configure { dependsOn("injectTags") } +tasks.named("ideVirtualMainClasses").configure { + // Make IntelliJ "Build project" build the mod jars + dependsOn("jar", "reobfJar", "spotlessCheck") +} + // workaround variable hiding in pom processing def projectConfigs = project.configurations @@ -1118,12 +1186,14 @@ publishing { } repositories { - maven { - url = "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases" - allowInsecureProtocol = true - credentials { - username = System.getenv("MAVEN_USER") ?: "NONE" - password = System.getenv("MAVEN_PASSWORD") ?: "NONE" + if (usesMavenPublishing.toBoolean()) { + maven { + url = mavenPublishUrl + allowInsecureProtocol = mavenPublishUrl.startsWith("http://") // Mostly for the GTNH maven + credentials { + username = System.getenv("MAVEN_USER") ?: "NONE" + password = System.getenv("MAVEN_PASSWORD") ?: "NONE" + } } } } @@ -1344,8 +1414,14 @@ boolean isNewBuildScriptVersionAvailable() { String currentBuildScript = getFile("build.gradle").getText() String currentBuildScriptHash = getVersionHash(currentBuildScript) - String availableBuildScript = availableBuildScriptUrl().newInputStream(parameters).getText() - String availableBuildScriptHash = getVersionHash(availableBuildScript) + String availableBuildScriptHash + try { + String availableBuildScript = availableBuildScriptUrl().newInputStream(parameters).getText() + availableBuildScriptHash = getVersionHash(availableBuildScript) + } catch (IOException e) { + logger.warn("Could not check for buildscript update availability: {}", e.message) + return false + } boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash return !isUpToDate @@ -1510,3 +1586,17 @@ def getSecondaryArtifacts() { if (apiPackage) secondaryArtifacts += [apiJar] return secondaryArtifacts } + +// For easier scripting of things that require variables defined earlier in the buildscript +if (file('addon.late.gradle.kts').exists()) { + apply from: 'addon.late.gradle.kts' +} else if (file('addon.late.gradle').exists()) { + apply from: 'addon.late.gradle' +} + +// File for local tweaks not commited to Git +if (file('addon.late.local.gradle.kts').exists()) { + apply from: 'addon.late.local.gradle.kts' +} else if (file('addon.late.local.gradle').exists()) { + apply from: 'addon.late.local.gradle' +} diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index 0b12499e..d1e30fe6 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -176,12 +176,12 @@ public abstract class GuiRecipe 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; - } + // 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; } } From 46f636247c55066ed5c3b5824f80b27c78891fc2 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sat, 15 Jul 2023 08:36:36 +0100 Subject: [PATCH 02/10] Fix bad item lighting in recipe tooltips --- src/main/java/codechicken/nei/ItemsGrid.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/codechicken/nei/ItemsGrid.java b/src/main/java/codechicken/nei/ItemsGrid.java index 7ed8c055..12cdeb6d 100644 --- a/src/main/java/codechicken/nei/ItemsGrid.java +++ b/src/main/java/codechicken/nei/ItemsGrid.java @@ -16,12 +16,14 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.shader.Framebuffer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; import codechicken.lib.vec.Rectangle4i; import codechicken.nei.ItemPanel.ItemPanelSlot; @@ -352,6 +354,9 @@ public class ItemsGrid { } recipeTooltipGui.drawGuiContainerBackgroundLayer(0.0f, -100, -100); if (recipeTooltipGui.slotcontainer != null) { + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); @SuppressWarnings("unchecked") List slots = (List) recipeTooltipGui.slotcontainer.inventorySlots; for (Slot slot : slots) { @@ -359,6 +364,7 @@ public class ItemsGrid { GuiContainerManager.drawItem(slot.xDisplayPosition, slot.yDisplayPosition, slot.getStack()); } } + GL11.glPopAttrib(); } recipeTooltipGui.drawGuiContainerForegroundLayer(-100, -100); for (GuiButton btn : recipeTooltipGui.getOverlayButtons()) { From 8547a885125a55134fbc7d93207ddb8f35833b8b Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sat, 15 Jul 2023 09:26:57 +0100 Subject: [PATCH 03/10] Update buildscript --- build.gradle | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 35dd43ef..bd6289cf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1689101527 +//version: 1689409577 /* DO NOT CHANGE THIS FILE! Also, you may replace this file at any time if there is an update available. @@ -363,9 +363,12 @@ try { if (versionOverride == null) { def gitDetails = versionDetails() def isDirty = gitVersion().endsWith(".dirty") // No public API for this, isCleanTag has a different meaning - String branchName = gitDetails.branchName + String branchName = gitDetails.branchName ?: (System.getenv('GIT_BRANCH') ?: 'git') + if (branchName.startsWith('origin/')) { + branchName = branchName.minus('origin/') + } branchName = branchName.replaceAll("[^a-zA-Z0-9-]+", "-") // sanitize branch names for semver - identifiedVersion = gitDetails.lastTag + identifiedVersion = gitDetails.lastTag ?: '${gitDetails.gitHash}' if (gitDetails.commitDistance > 0) { identifiedVersion += "-${branchName}.${gitDetails.commitDistance}+${gitDetails.gitHash}" if (isDirty) { From a8e09ece187dbca4776f7f98f303c1c17ba30811 Mon Sep 17 00:00:00 2001 From: Wilhelm Schuster Date: Sun, 16 Jul 2023 11:15:49 +0200 Subject: [PATCH 04/10] Fix NEI ignoring handler switching on click Handlers might call Minecraft#displayGuiScreen and overwrite Minecraft.currentScreen, but the height hack would unconditionally undo this again. --- .../java/codechicken/nei/recipe/GuiRecipe.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index d1e30fe6..aaae0234 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -151,7 +151,7 @@ public abstract class GuiRecipe extends GuiContainer i private HeightHack() { trueHeight = height; trueGuiTop = guiTop; - trueGui = Minecraft.getMinecraft().currentScreen; + trueGui = NEIClientUtils.mc().currentScreen; isHeightHackApplied = NEIClientConfig.heightHackHandlerRegex.stream() .map(pattern -> pattern.matcher(handler.getHandlerId())).anyMatch(Matcher::matches); @@ -181,7 +181,7 @@ public abstract class GuiRecipe extends GuiContainer i // 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; + NEIClientUtils.mc().currentScreen = GuiRecipe.this; } } @@ -189,7 +189,13 @@ public abstract class GuiRecipe extends GuiContainer i public void close() { guiTop = trueGuiTop; height = trueHeight; - Minecraft.getMinecraft().currentScreen = trueGui; + + // Only restore currentScreen if it hasn't been altered by a recipe handler (for example through + // Minecraft#displayGuiScreen). + if (limitToOneRecipe && NEIClientUtils.mc().currentScreen == GuiRecipe.this) { + NEIClientUtils.mc().currentScreen = trueGui; + } + isHeightHackApplied = false; } } @@ -207,7 +213,7 @@ public abstract class GuiRecipe extends GuiContainer i super.initGui(); } else { this.guiLeft = (this.width - this.xSize) / 2; - this.mc = Minecraft.getMinecraft(); + this.mc = NEIClientUtils.mc(); this.fontRendererObj = mc.fontRenderer; ScaledResolution scaledresolution = new ScaledResolution( this.mc, From 788a8de717ef5bcb76c7b1cc04dfb0e705030e33 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 16 Jul 2023 13:50:40 +0200 Subject: [PATCH 05/10] spotlessApply (#404) Co-authored-by: GitHub GTNH Actions <> --- src/main/java/codechicken/nei/recipe/GuiRecipe.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index aaae0234..060f9ed3 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -13,7 +13,6 @@ import java.util.regex.Matcher; import java.util.stream.Collectors; import java.util.stream.IntStream; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; From d3bd68dab59d7db4cb8cae7cf11cefbd2ac4912d Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sun, 16 Jul 2023 09:00:35 +0100 Subject: [PATCH 06/10] Attempt to fix CME when opening recipes immediately after load (#403) --- src/main/java/codechicken/nei/ItemsGrid.java | 4 ++++ .../java/codechicken/nei/api/ShortcutInputHandler.java | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/codechicken/nei/ItemsGrid.java b/src/main/java/codechicken/nei/ItemsGrid.java index 12cdeb6d..99e1090a 100644 --- a/src/main/java/codechicken/nei/ItemsGrid.java +++ b/src/main/java/codechicken/nei/ItemsGrid.java @@ -279,6 +279,10 @@ public class ItemsGrid { } private void drawRecipeTooltip(int mousex, int mousey, List itemTooltip) { + if (!NEIClientConfig.isLoaded()) { + return; + } + final Minecraft mc = Minecraft.getMinecraft(); ItemPanelSlot focused = getSlotMouseOver(mousex, mousey); if (focused == null) { diff --git a/src/main/java/codechicken/nei/api/ShortcutInputHandler.java b/src/main/java/codechicken/nei/api/ShortcutInputHandler.java index 1758b933..2cf5d8aa 100644 --- a/src/main/java/codechicken/nei/api/ShortcutInputHandler.java +++ b/src/main/java/codechicken/nei/api/ShortcutInputHandler.java @@ -20,6 +20,10 @@ public abstract class ShortcutInputHandler { public static boolean handleKeyEvent(ItemStack stackover) { + if (!NEIClientConfig.isLoaded()) { + return false; + } + if (NEIClientConfig.isKeyHashDown("gui.overlay_hide")) { return hideOverlayRecipe(); } @@ -67,6 +71,10 @@ 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(); From 76545e7f07079d523e777f5049080e2367956279 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sun, 16 Jul 2023 13:10:24 +0100 Subject: [PATCH 07/10] Rename the internal private class HeightHack->CompatibilityHacks to better reflect the new usage. --- .../codechicken/nei/recipe/GuiRecipe.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index 060f9ed3..b85ea7dd 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -107,7 +107,7 @@ public abstract class GuiRecipe extends GuiContainer i /** * This will only be true iff height hacking has been configured for the current recipe handler AND we are currently - * within the scope of an active {@link HeightHack} instance. + * within the scope of an active {@link CompatibilityHacks} instance. */ private boolean isHeightHackApplied = false; @@ -138,16 +138,22 @@ public abstract class GuiRecipe extends GuiContainer i * property's value so that these old mods' calculations return the correct value for the new height. * *

+ * New and old mods often assume that the handler is only drawn when {@link GuiRecipe} is the currently active + * screen in {@link Minecraft}. This is no longer true since the addition of recipe tooltips which need to render + * the recipe in other containers on mouse hover, this class temporarily switches the active screen to {@code this} + * while rendering them to avoid ClassCastExceptions and other similar crashes. + * + *

* This class is an {@link AutoCloseable} so that it can be used with try-with-resources, which will ensure that - * {@link #height} is returned to the correct value afterwards. + * {@link #height} and {@link Minecraft#currentScreen} is returned to the correct value afterwards. */ - private class HeightHack implements AutoCloseable { + private class CompatibilityHacks implements AutoCloseable { private final int trueHeight; private final int trueGuiTop; private final GuiScreen trueGui; - private HeightHack() { + private CompatibilityHacks() { trueHeight = height; trueGuiTop = guiTop; trueGui = NEIClientUtils.mc().currentScreen; @@ -394,7 +400,7 @@ public abstract class GuiRecipe extends GuiContainer i } if (GuiContainerManager.getManager(this).lastKeyTyped(i, c)) return; - try (HeightHack heightHack = new HeightHack()) { + try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) { for (int recipe : getRecipeIndices()) if (handler.keyTyped(this, c, i, recipe)) return; } @@ -416,7 +422,7 @@ public abstract class GuiRecipe extends GuiContainer i @Override protected void mouseClicked(int x, int y, int button) { - try (HeightHack heightHack = new HeightHack()) { + try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) { for (int recipe : getRecipeIndices()) if (handler.mouseClicked(this, button, recipe)) return; } @@ -493,7 +499,7 @@ public abstract class GuiRecipe extends GuiContainer i @Override public List handleTooltip(GuiContainer gui, int mousex, int mousey, List currenttip) { - try (HeightHack heightHack = new HeightHack()) { + try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) { for (int i : getRecipeIndices()) currenttip = handler.handleTooltip(this, currenttip, i); } recipeTabs.handleTooltip(mousex, mousey, currenttip); @@ -503,7 +509,7 @@ public abstract class GuiRecipe extends GuiContainer i @Override public List handleItemTooltip(GuiContainer gui, ItemStack stack, int mousex, int mousey, List currenttip) { - try (HeightHack heightHack = new HeightHack()) { + try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) { for (int i : getRecipeIndices()) currenttip = handler.handleItemTooltip(this, stack, currenttip, i); } @@ -661,7 +667,7 @@ public abstract class GuiRecipe extends GuiContainer i GL11.glPushMatrix(); GL11.glTranslatef(5, 32 - ySkip + yShift, 0); - try (HeightHack heightHack = new HeightHack()) { + try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) { for (int i = page * recipesPerPage; i < handler.numRecipes() && i < (page + 1) * recipesPerPage; i++) { handler.drawForeground(i); if (drawItemPresence && (isMouseOverOverlayButton(i - page * recipesPerPage) || limitToOneRecipe) @@ -716,7 +722,7 @@ public abstract class GuiRecipe extends GuiContainer i GL11.glPushMatrix(); GL11.glTranslatef(guiLeft + 5, guiTop - ySkip + 32 + yShift, 0); - try (HeightHack heightHack = new HeightHack()) { + try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) { for (int i = page * recipesPerPage; i < handler.numRecipes() && i < (page + 1) * recipesPerPage; i++) { handler.drawBackground(i); GL11.glTranslatef(0, handlerInfo.getHeight(), 0); From b94aabe03db88ebdaa59b9da067ca3cae6a02504 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sun, 16 Jul 2023 13:40:24 +0100 Subject: [PATCH 08/10] Move trueGui assignment down. --- src/main/java/codechicken/nei/recipe/GuiRecipe.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index b85ea7dd..a90c4d00 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -139,13 +139,14 @@ public abstract class GuiRecipe extends GuiContainer i * *

* New and old mods often assume that the handler is only drawn when {@link GuiRecipe} is the currently active - * screen in {@link Minecraft}. This is no longer true since the addition of recipe tooltips which need to render - * the recipe in other containers on mouse hover, this class temporarily switches the active screen to {@code this} - * while rendering them to avoid ClassCastExceptions and other similar crashes. + * screen in {@link net.minecraft.client.Minecraft}. This is no longer true since the addition of recipe tooltips + * which need to render the recipe in other containers on mouse hover, this class temporarily switches the active + * screen to {@code this} while rendering them to avoid ClassCastExceptions and other similar crashes. * *

* This class is an {@link AutoCloseable} so that it can be used with try-with-resources, which will ensure that - * {@link #height} and {@link Minecraft#currentScreen} is returned to the correct value afterwards. + * {@link #height} and {@link net.minecraft.client.Minecraft#currentScreen} is returned to the correct value + * afterwards. */ private class CompatibilityHacks implements AutoCloseable { @@ -156,7 +157,6 @@ public abstract class GuiRecipe extends GuiContainer i private CompatibilityHacks() { trueHeight = height; trueGuiTop = guiTop; - trueGui = NEIClientUtils.mc().currentScreen; isHeightHackApplied = NEIClientConfig.heightHackHandlerRegex.stream() .map(pattern -> pattern.matcher(handler.getHandlerId())).anyMatch(Matcher::matches); @@ -185,6 +185,7 @@ public abstract class GuiRecipe extends GuiContainer i // 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. + trueGui = NEIClientUtils.mc().currentScreen; if (limitToOneRecipe) { NEIClientUtils.mc().currentScreen = GuiRecipe.this; } From e383c398840d5def4764c5ea9e748e3a3aeae25b Mon Sep 17 00:00:00 2001 From: Wilhelm Schuster Date: Sun, 16 Jul 2023 22:19:14 +0200 Subject: [PATCH 09/10] Fix overlay button y offsets --- src/main/java/codechicken/nei/recipe/GuiRecipe.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipe.java b/src/main/java/codechicken/nei/recipe/GuiRecipe.java index a90c4d00..71cf6d73 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipe.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipe.java @@ -265,13 +265,14 @@ public abstract class GuiRecipe extends GuiContainer i final int recipesPerPage = getRecipesPerPage(); overlayButtons = new GuiButton[recipesPerPage]; final int xOffset = limitToOneRecipe ? ((xSize / 2) - 2) : (width / 2); + final int yOffset = limitToOneRecipe ? 0 : guiTop - 18; 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 + getRecipePosition(i).y + handlerInfo.getHeight(), buttonWidth, buttonHeight, "?"); From 092f572beb8a5118d57b1100ab225b9695fc1c80 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Mon, 17 Jul 2023 19:02:29 +0100 Subject: [PATCH 10/10] Fix wrong recipe tooltip background rendering --- src/main/java/codechicken/nei/ItemsGrid.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/codechicken/nei/ItemsGrid.java b/src/main/java/codechicken/nei/ItemsGrid.java index 99e1090a..9459b59d 100644 --- a/src/main/java/codechicken/nei/ItemsGrid.java +++ b/src/main/java/codechicken/nei/ItemsGrid.java @@ -356,7 +356,10 @@ public class ItemsGrid { } else { gui = null; } + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + RenderHelper.disableStandardItemLighting(); recipeTooltipGui.drawGuiContainerBackgroundLayer(0.0f, -100, -100); + GL11.glPopAttrib(); if (recipeTooltipGui.slotcontainer != null) { GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); RenderHelper.enableGUIStandardItemLighting();