mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-16 09:15:10 +01:00
Enable commands in all environments
- Many command-related fixes and improvements - Added test environment for easier development
This commit is contained in:
@@ -107,15 +107,10 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static void initClient(String modid, Field field, EntryInfo info) {
|
||||
info.dataType = field.getType();
|
||||
info.dataType = getUnderlyingType(field);
|
||||
Entry e = field.getAnnotation(Entry.class);
|
||||
info.width = e != null ? e.width() : 0;
|
||||
info.field = field; info.modid = modid;
|
||||
if (info.dataType == List.class) {
|
||||
Class<?> listType = (Class<?>) ((ParameterizedType) info.field.getGenericType()).getActualTypeArguments()[0];
|
||||
try { info.dataType = (Class<?>) listType.getField("TYPE").get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) { info.dataType = listType; }
|
||||
}
|
||||
|
||||
if (e != null) {
|
||||
if (!e.name().isEmpty()) info.name = Text.translatable(e.name());
|
||||
@@ -138,6 +133,13 @@ public abstract class MidnightConfig {
|
||||
}}
|
||||
entries.add(info);
|
||||
}
|
||||
public static Class<?> getUnderlyingType(Field field) {
|
||||
if (field.getType() == List.class) {
|
||||
Class<?> listType = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
||||
try { return (Class<?>) listType.getField("TYPE").get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) { return listType; }
|
||||
} else return field.getType();
|
||||
}
|
||||
public static Tooltip getTooltip(EntryInfo info) {
|
||||
String key = info.modid + ".midnightconfig."+info.field.getName()+".tooltip";
|
||||
return Tooltip.of(info.error != null ? info.error : I18n.hasTranslation(key) ? Text.translatable(key) : Text.empty());
|
||||
|
||||
Reference in New Issue
Block a user