Skip to content

Commit

Permalink
Handle multiple config classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 committed Jan 29, 2024
1 parent b6c7f20 commit 21aeb44
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -216,6 +218,22 @@ public static List<IConfigElement> getConfigElements(Class<?> configClass) throw
})).collect(Collectors.toList());
}

@SuppressWarnings({ "rawtypes" })
public static List<IConfigElement> getConfigElementsMulti(Class<?>... configClasses) throws ConfigException {
switch (configClasses.length) {
case 0:
return Collections.emptyList();
case 1:
return getConfigElements(configClasses[0]);
default:
val result = new ArrayList<IConfigElement>();
for (val configClass : configClasses) {
result.addAll(getConfigElements(configClass));
}
return result;
}
}

private static File minecraftHome() {
return Launch.minecraftHome != null ? Launch.minecraftHome : new File(".");
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/gtnewhorizon/gtnhlib/config/SimpleGuiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ public SimpleGuiConfig(GuiScreen parent, Class<?> configClass, String modID, Str
false,
modName + " Configuration");
}

public SimpleGuiConfig(GuiScreen parent, String modID, String modName, Class<?>... configClasses)
throws ConfigException {
super(
parent,
ConfigurationManager.getConfigElementsMulti(configClasses),
modID,
false,
false,
modName + " Configuration");
}
}

0 comments on commit 21aeb44

Please sign in to comment.