From f844961cf8b991598f6e520f7191740e518504ca Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Sat, 20 Apr 2024 23:20:28 +0200 Subject: [PATCH] fix: Do not crash if there are no buttons in the in-game menu (fixes #14) --- .../se/icus/mag/modsettings/gui/MenuScreensChanger.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/se/icus/mag/modsettings/gui/MenuScreensChanger.java b/src/main/java/se/icus/mag/modsettings/gui/MenuScreensChanger.java index 1133b98..a88de7c 100644 --- a/src/main/java/se/icus/mag/modsettings/gui/MenuScreensChanger.java +++ b/src/main/java/se/icus/mag/modsettings/gui/MenuScreensChanger.java @@ -55,6 +55,13 @@ private static void injectModSettingsButton(Screen screen, List } else { if (savedButton == null) { // There is no "Options..." button. Just grab an arbitrary button + if (buttons.isEmpty()) { + // There are no existing buttons? Just try to add our button + ClickableWidget msbutton = new ModSettingsButton(screen.width / 2 - fullButtonWidth / 2, + 108 - verticalOffset, fullButtonWidth, BUTTON_HEIGHT, screen); + buttons.add(msbutton); + return; + } savedButton = buttons.get(0); } // Shift all buttons starting at "Options..." down