From 493f183054a431a324df8ca4e2e11e7a781c9edc Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Fri, 7 Jan 2022 15:31:39 -0700 Subject: [PATCH] v1.4.3 * Fix for https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/9304 --- gradle.properties | 2 +- .../neicustomdiagram/api/draw/GuiManager.java | 44 ++++++++++++++++--- .../neicustomdiagram/main/NeiIntegration.java | 4 ++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index c29f0ac..a14f5f4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -neiCustomDiagramVersion=1.4.2 +neiCustomDiagramVersion=1.4.3 minecraftVersion=1.7.10 forgeVersion=10.13.4.1614 diff --git a/src/main/java/com/github/dcysteine/neicustomdiagram/api/draw/GuiManager.java b/src/main/java/com/github/dcysteine/neicustomdiagram/api/draw/GuiManager.java index e495717..817a02e 100644 --- a/src/main/java/com/github/dcysteine/neicustomdiagram/api/draw/GuiManager.java +++ b/src/main/java/com/github/dcysteine/neicustomdiagram/api/draw/GuiManager.java @@ -9,6 +9,8 @@ import net.minecraft.client.gui.ScaledResolution; import org.lwjgl.opengl.GL11; +import java.util.Optional; + /** Handles things like getting the mouse position, and scrolling. */ public final class GuiManager { // Margins for glScissor, in pixels. These margins will be excluded from the scissor region. @@ -201,7 +203,13 @@ public Point getAbsoluteMousePosition() { } public Point getRelativeMousePosition(int recipe) { - GuiRecipe gui = getGui(); + Optional guiOptional = getGui(); + if (!guiOptional.isPresent()) { + // The GUI got closed already, or something. + return Point.create(0, 0); + } + GuiRecipe gui = guiOptional.get(); + java.awt.Point mouse = GuiDraw.getMousePosition(); java.awt.Point offset = gui.getRecipePosition(recipe); @@ -261,14 +269,26 @@ public void scrollToMouse(Dimension diagramDimension) { *

Note that this is incorrect for {@code glScissor}! */ public Point getViewportPosition() { - GuiRecipe gui = getGui(); + Optional guiOptional = getGui(); + if (!guiOptional.isPresent()) { + // The GUI got closed already, or something. + return Point.create(0, 0); + } + GuiRecipe gui = guiOptional.get(); + return Point.create( Reflection.GUI_LEFT.get(gui) + SIDE_MARGIN, Reflection.GUI_TOP.get(gui) + TOP_MARGIN); } public Dimension getViewportDimension() { - GuiRecipe gui = getGui(); + Optional guiOptional = getGui(); + if (!guiOptional.isPresent()) { + // The GUI got closed already, or something. + return Dimension.create(0, 0); + } + GuiRecipe gui = guiOptional.get(); + return Dimension.create( Reflection.X_SIZE.get(gui) - 2 * SIDE_MARGIN, Reflection.Y_SIZE.get(gui) - (TOP_MARGIN + BOTTOM_MARGIN)); @@ -280,7 +300,13 @@ private int computeScrollableHeight(Dimension diagramDimension) { } private void setScissor() { - GuiRecipe gui = getGui(); + Optional guiOptional = getGui(); + if (!guiOptional.isPresent()) { + // The GUI got closed already, or something. + return; + } + GuiRecipe gui = guiOptional.get(); + int left = Reflection.GUI_LEFT.get(gui) + SIDE_MARGIN; int bottom = gui.height - (Reflection.GUI_TOP.get(gui) + Reflection.Y_SIZE.get(gui)) @@ -300,7 +326,13 @@ private void setScissor() { viewportDim.width() * scaleFactor, viewportDim.height() * scaleFactor); } - private GuiRecipe getGui() { - return (GuiRecipe) GuiContainerManager.getManager().window; + /** Returns empty {@link Optional} in cases such as the GUI being instantly closed. */ + private Optional getGui() { + GuiContainerManager manager = GuiContainerManager.getManager(); + if (manager == null || !(manager.window instanceof GuiRecipe)) { + return Optional.empty(); + } + + return Optional.of((GuiRecipe) manager.window); } } diff --git a/src/main/java/com/github/dcysteine/neicustomdiagram/main/NeiIntegration.java b/src/main/java/com/github/dcysteine/neicustomdiagram/main/NeiIntegration.java index db8ec34..cda4d51 100644 --- a/src/main/java/com/github/dcysteine/neicustomdiagram/main/NeiIntegration.java +++ b/src/main/java/com/github/dcysteine/neicustomdiagram/main/NeiIntegration.java @@ -46,6 +46,10 @@ public void load(GuiContainer guiContainer) {} @Override public ItemStack getStackUnderMouse(GuiContainer guiContainer, int mousex, int mousey) { + if (!(guiContainer instanceof GuiRecipe)) { + return null; + } + Optional diagramGroupOptional = getDiagramGroup(guiContainer); if (!diagramGroupOptional.isPresent()) { return null;