ConfigEntry.Gui.CollapsibleObject does not include fields in super classes
rikka0w0 opened this issue ยท 0 comments
As the title suggests. It is inconvenient when handling a large set of similar options and requires a lot of duplication and hard coding.
I found a solution. In DefaultGuiProviders.java:
private static List<AbstractConfigListEntry> getChildren(String i18n, Class<?> fieldType, Object iConfig, Object iDefaults, GuiRegistryAccess guiProvider) {
- return Arrays.stream(fieldType.getDeclaredFields())
+ return traverseFields(fieldType, true).stream()
where traverseFields
is a new helper function:
private static List<Field> traverseFields(Class<?> fieldType, boolean includeSuper) {
List<Field> result = new LinkedList<>();
Class<?> cls = fieldType;
while (cls != null && !cls.equals(Object.class)) {
result.addAll(Arrays.asList(cls.getDeclaredFields()));
if (!includeSuper) {
break;
}
cls = cls.getSuperclass();
}
return result;
}
We could introduce another option in the CollapsibleObject annotation to specify whether we include the fields in its super class or not.