@@ -102,26 +102,6 @@ public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmou
102102
103103 @ Override
104104 protected void init () {
105- for (Mod mod : ModMenu .MODS .values ()) {
106- String id = mod .getId ();
107- if (!modHasConfigScreen .containsKey (id )) {
108- try {
109- Screen configScreen = ModMenu .getConfigScreen (id , this );
110- modHasConfigScreen .put (id , configScreen != null );
111- } catch (java .lang .NoClassDefFoundError e ) {
112- LOGGER .warn (
113- "The '" + id + "' mod config screen is not available because " + e .getLocalizedMessage () +
114- " is missing." );
115- modScreenErrors .put (id , e );
116- modHasConfigScreen .put (id , false );
117- } catch (Throwable e ) {
118- LOGGER .error ("Error from mod '" + id + "'" , e );
119- modScreenErrors .put (id , e );
120- modHasConfigScreen .put (id , false );
121- }
122- }
123- }
124-
125105 int paneY = ModMenuConfig .CONFIG_MODE .getValue () ? 48 : 48 + 19 ;
126106 this .paneWidth = this .width / 2 - 8 ;
127107 this .rightPaneX = this .width - this .paneWidth ;
@@ -203,9 +183,8 @@ protected void init() {
203183 if (!ModMenuConfig .HIDE_CONFIG_BUTTONS .getValue ()) {
204184 this .configureButton = LegacyTexturedButtonWidget .legacyTexturedBuilder (ScreenTexts .EMPTY , button -> {
205185 final String id = Objects .requireNonNull (selected ).getMod ().getId ();
206- if (modHasConfigScreen .get (id )) {
207- Screen configScreen = ModMenu .getConfigScreen (id , this );
208- client .setScreen (configScreen );
186+ if (getModHasConfigScreen (id )) {
187+ this .safelyOpenConfigScreen (id );
209188 } else {
210189 button .active = false ;
211190 }
@@ -540,9 +519,9 @@ public void updateSelectedEntry(ModListEntry entry) {
540519
541520 if (this .configureButton != null ) {
542521
543- this .configureButton .active = modHasConfigScreen . get (modId );
522+ this .configureButton .active = getModHasConfigScreen (modId );
544523 this .configureButton .visible =
545- selected != null && modHasConfigScreen . get (modId ) || modScreenErrors .containsKey (modId );
524+ selected != null && getModHasConfigScreen (modId ) || modScreenErrors .containsKey (modId );
546525
547526 if (modScreenErrors .containsKey (modId )) {
548527 Throwable e = modScreenErrors .get (modId );
@@ -652,7 +631,29 @@ private static boolean isValidMod(Path mod) {
652631 }
653632 }
654633
655- public Map <String , Boolean > getModHasConfigScreen () {
656- return this .modHasConfigScreen ;
634+ public boolean getModHasConfigScreen (String modId ) {
635+ if (this .modScreenErrors .containsKey (modId )) {
636+ return false ;
637+ } else {
638+ return this .modHasConfigScreen .computeIfAbsent (modId , ModMenu ::hasConfigScreen );
639+ }
640+ }
641+
642+ public void safelyOpenConfigScreen (String modId ) {
643+ try {
644+ Screen screen = ModMenu .getConfigScreen (modId , this );
645+
646+ if (screen != null ) {
647+ this .client .setScreen (screen );
648+ }
649+ } catch (java .lang .NoClassDefFoundError e ) {
650+ LOGGER .warn (
651+ "The '" + modId + "' mod config screen is not available because " + e .getLocalizedMessage () +
652+ " is missing." );
653+ modScreenErrors .put (modId , e );
654+ } catch (Throwable e ) {
655+ LOGGER .error ("Error from mod '" + modId + "'" , e );
656+ modScreenErrors .put (modId , e );
657+ }
657658 }
658659}
0 commit comments