2222
2323package com .falsepattern .lib .internal .config ;
2424
25- import com .falsepattern .lib .internal .FPLog ;
2625import lombok .NoArgsConstructor ;
27- import lombok .val ;
2826
2927import net .minecraft .client .Minecraft ;
30- import net .minecraft .client .gui .GuiScreen ;
3128import net .minecraftforge .client .event .GuiOpenEvent ;
3229import net .minecraftforge .common .MinecraftForge ;
33- import cpw .mods .fml .client .FMLClientHandler ;
3430import cpw .mods .fml .client .GuiIngameModOptions ;
3531import cpw .mods .fml .client .GuiModList ;
36- import cpw .mods .fml .common .ModContainer ;
3732import cpw .mods .fml .common .eventhandler .SubscribeEvent ;
3833
39- import java .lang .reflect .Field ;
40- import java .util .ArrayList ;
41- import java .util .Collections ;
42- import java .util .List ;
43-
4434import static lombok .AccessLevel .PRIVATE ;
4535
4636@ NoArgsConstructor (access = PRIVATE )
4737public final class InGameModOptionsFix {
4838 private static boolean isInitialized = false ;
4939
50- private static Field MODS_FIELD ;
51-
5240 public static void init () {
5341 if (isInitialized )
5442 return ;
55-
56- try {
57- MODS_FIELD = GuiModList .class .getDeclaredField ("mods" );
58- MODS_FIELD .setAccessible (true );
59- } catch (NoSuchFieldException e ) {
60- MODS_FIELD = null ;
61- FPLog .LOG .error ("Failed to get field: cpw.mods.fml.client.GuiModList.mods,"
62- + " In-Game Mod Options Fix will not work" , e );
63- return ;
64- }
6543 MinecraftForge .EVENT_BUS .register (new InGameModOptionsFix ());
6644 isInitialized = true ;
6745 }
@@ -74,36 +52,6 @@ public void onGuiOpen(final GuiOpenEvent event) {
7452 return ;
7553
7654 if (event .gui instanceof GuiIngameModOptions )
77- event .gui = new GuiModConfigList (Minecraft .getMinecraft ().currentScreen );
78- }
79-
80- private static class GuiModConfigList extends GuiModList {
81- private GuiModConfigList (GuiScreen screen ) {
82- super (screen );
83- val mods = new ArrayList <ModContainer >();
84- for (val mod : getModsFromPrivateField ()) {
85- val guiFactory = FMLClientHandler .instance ().getGuiFactoryFor (mod );
86- if (guiFactory == null )
87- continue ;
88- if (guiFactory .mainConfigGuiClass () != null )
89- mods .add (mod );
90- }
91- setModsToPrivateField (mods );
92- }
93-
94- private List <ModContainer > getModsFromPrivateField () {
95- try {
96- return (List <ModContainer >) MODS_FIELD .get (this );
97- } catch (Exception e ) {
98- return Collections .emptyList ();
99- }
100- }
101-
102- private void setModsToPrivateField (List <ModContainer > mods ) {
103- try {
104- MODS_FIELD .set (this , mods );
105- } catch (Exception ignored ) {
106- }
107- }
55+ event .gui = new GuiModList (Minecraft .getMinecraft ().currentScreen );
10856 }
10957}
0 commit comments