Enable commands in all environments

- Many command-related fixes and improvements
- Added test environment for easier development
This commit is contained in:
Martin Prokoph
2024-08-29 13:38:38 +02:00
parent 545a845add
commit db32a41e2b
14 changed files with 215 additions and 50 deletions

View File

@@ -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());