From de52198867a0bf01ab6f05a451f8d76fdfedec30 Mon Sep 17 00:00:00 2001 From: decce6 Date: Sat, 2 May 2026 20:59:05 +0800 Subject: [PATCH] Fix missing pop on the pose stack --- .../com/natamus/guiclock/events/GUIEvent.java | 223 +++++++++--------- 1 file changed, 113 insertions(+), 110 deletions(-) diff --git a/Common/src/main/java/com/natamus/guiclock/events/GUIEvent.java b/Common/src/main/java/com/natamus/guiclock/events/GUIEvent.java index 7015851..869384a 100644 --- a/Common/src/main/java/com/natamus/guiclock/events/GUIEvent.java +++ b/Common/src/main/java/com/natamus/guiclock/events/GUIEvent.java @@ -46,138 +46,141 @@ public static void renderOverlay(GuiGraphics guiGraphics, float tickDelta) { PoseStack poseStack = guiGraphics.pose(); poseStack.pushPose(); - - Font fontRenderer = mc.font; - Window scaled = mc.getWindow(); - int width = scaled.getGuiScaledWidth(); - - int heightoffset = ConfigHandler.clockHeightOffset; - if (heightoffset < 5) { - heightoffset = 5; - } - - if (ConfigHandler.lowerClockWhenPlayerHasEffects) { - Collection activeeffects = mc.player.getActiveEffects(); - if (activeeffects.size() > 0) { - boolean haspositive = false; - boolean hasnegative = false; - for (MobEffectInstance effect : activeeffects) { - if (effect.isVisible()) { - if (effect.getEffect().getCategory().equals(MobEffectCategory.BENEFICIAL)) { - haspositive = true; - } - else { - hasnegative = true; - } - if (haspositive && hasnegative) { - break; + try { + Font fontRenderer = mc.font; + Window scaled = mc.getWindow(); + int width = scaled.getGuiScaledWidth(); + + int heightoffset = ConfigHandler.clockHeightOffset; + if (heightoffset < 5) { + heightoffset = 5; + } + + if (ConfigHandler.lowerClockWhenPlayerHasEffects) { + Collection activeeffects = mc.player.getActiveEffects(); + if (activeeffects.size() > 0) { + boolean haspositive = false; + boolean hasnegative = false; + for (MobEffectInstance effect : activeeffects) { + if (effect.isVisible()) { + if (effect.getEffect().getCategory().equals(MobEffectCategory.BENEFICIAL)) { + haspositive = true; + } + else { + hasnegative = true; + } + + if (haspositive && hasnegative) { + break; + } } } - } - if (hasnegative && haspositive) { - heightoffset += 50; - } - else if (haspositive && !hasnegative) { - heightoffset += 25; - } - } - } - - int xcoord; - int daycoord; - if (ConfigHandler.showOnlyMinecraftClockIcon) { - if (gametimeb) { - if (!found) { - return; + if (hasnegative && haspositive) { + heightoffset += 50; + } + else if (haspositive && !hasnegative) { + heightoffset += 25; + } } } - - if (ConfigHandler.clockPositionIsLeft) { - xcoord = 20; - } - else if (ConfigHandler.clockPositionIsCenter) { - xcoord = (width/2) - 8; - } - else { - xcoord = width - 20; - } - - xcoord += ConfigHandler.clockWidthOffset; - guiGraphics.renderItem(new ItemStack(Items.CLOCK), xcoord, heightoffset); - } - else { - String time; - String realtime = StringFunctions.getPCLocalTime(ConfigHandler._24hourformat, ConfigHandler.showRealTimeSeconds); - if (ConfigHandler.showBothTimes) { - if (gametimeb && realtimeb) { + int xcoord; + int daycoord; + if (ConfigHandler.showOnlyMinecraftClockIcon) { + if (gametimeb) { if (!found) { return; } - time = getGameTime() + " | " + realtime; } - else if (!found && gametimeb) { - time = realtime; + + if (ConfigHandler.clockPositionIsLeft) { + xcoord = 20; } - else if (!found && realtimeb) { - time = getGameTime(); + else if (ConfigHandler.clockPositionIsCenter) { + xcoord = (width/2) - 8; } else { - time = getGameTime() + " | " + realtime; + xcoord = width - 20; } + + xcoord += ConfigHandler.clockWidthOffset; + + guiGraphics.renderItem(new ItemStack(Items.CLOCK), xcoord, heightoffset); } - else if (ConfigHandler.showRealTime) { - if (realtimeb) { - if (!found) { - return; + else { + String time; + String realtime = StringFunctions.getPCLocalTime(ConfigHandler._24hourformat, ConfigHandler.showRealTimeSeconds); + if (ConfigHandler.showBothTimes) { + if (gametimeb && realtimeb) { + if (!found) { + return; + } + time = getGameTime() + " | " + realtime; + } + else if (!found && gametimeb) { + time = realtime; + } + else if (!found && realtimeb) { + time = getGameTime(); + } + else { + time = getGameTime() + " | " + realtime; } } - time = realtime; - } - else { - if (gametimeb) { - if (!found) { - return; + else if (ConfigHandler.showRealTime) { + if (realtimeb) { + if (!found) { + return; + } } + time = realtime; + } + else { + if (gametimeb) { + if (!found) { + return; + } + } + time = getGameTime(); + } + + if (time.equals("")) { + return; + } + + int stringWidth = fontRenderer.width(time); + int daystringWidth = fontRenderer.width(daystring); + + Color colour = new Color(ConfigHandler.RGB_R, ConfigHandler.RGB_G, ConfigHandler.RGB_B, 255); + + if (ConfigHandler.clockPositionIsLeft) { + xcoord = 5; + daycoord = 5; + } + else if (ConfigHandler.clockPositionIsCenter) { + xcoord = (width/2) - (stringWidth/2); + daycoord = (width/2) - (daystringWidth/2); + } + else { + xcoord = width - stringWidth - 5; + daycoord = width - daystringWidth - 5; + } + + xcoord += ConfigHandler.clockWidthOffset; + daycoord += ConfigHandler.clockWidthOffset; + + int rgb = colour.getRGB(); + drawText(fontRenderer, guiGraphics, time, xcoord, heightoffset, rgb, ConfigHandler.drawTextShadow); + if (!daystring.equals("")) { + drawText(fontRenderer, guiGraphics, daystring, daycoord, heightoffset+10, rgb, ConfigHandler.drawTextShadow); } - time = getGameTime(); - } - - if (time.equals("")) { - return; - } - - int stringWidth = fontRenderer.width(time); - int daystringWidth = fontRenderer.width(daystring); - - Color colour = new Color(ConfigHandler.RGB_R, ConfigHandler.RGB_G, ConfigHandler.RGB_B, 255); - - if (ConfigHandler.clockPositionIsLeft) { - xcoord = 5; - daycoord = 5; - } - else if (ConfigHandler.clockPositionIsCenter) { - xcoord = (width/2) - (stringWidth/2); - daycoord = (width/2) - (daystringWidth/2); - } - else { - xcoord = width - stringWidth - 5; - daycoord = width - daystringWidth - 5; - } - - xcoord += ConfigHandler.clockWidthOffset; - daycoord += ConfigHandler.clockWidthOffset; - - int rgb = colour.getRGB(); - drawText(fontRenderer, guiGraphics, time, xcoord, heightoffset, rgb, ConfigHandler.drawTextShadow); - if (!daystring.equals("")) { - drawText(fontRenderer, guiGraphics, daystring, daycoord, heightoffset+10, rgb, ConfigHandler.drawTextShadow); } } - - poseStack.popPose(); + finally { + poseStack.popPose(); + } } private static void drawText(Font font, GuiGraphics guiGraphics, String content, int x, int y, int rgb, boolean drawShadow) {