clean: some code cleanup

This commit is contained in:
Martin Prokoph
2025-05-13 12:05:07 +02:00
parent 6bbaf1ab5d
commit 7ddfadd4ec
2 changed files with 33 additions and 34 deletions

View File

@@ -187,11 +187,9 @@ public abstract class MidnightConfig {
}
private static Text getEnumTranslatableText(Object value, String modid, EntryInfo info) {
if (value instanceof TranslatableOption translatableOption) {
return translatableOption.getText();
}
if (value instanceof TranslatableOption translatableOption) return translatableOption.getText();
String translationKey = modid + ".midnightconfig.enum." + info.dataType.getSimpleName() + "." + info.toTemporaryValue();
String translationKey = "%s.midnightconfig.enum.%s.%s".formatted(modid, info.dataType.getSimpleName(), info.toTemporaryValue());
return I18n.hasTranslation(translationKey) ? Text.translatable(translationKey) : Text.literal(info.toTemporaryValue());
}
@@ -257,7 +255,7 @@ public abstract class MidnightConfig {
@Environment(EnvType.CLIENT)
public static class MidnightConfigScreen extends Screen {
protected MidnightConfigScreen(Screen parent, String modid) {
super(Text.translatable(modid + ".midnightconfig." + "title"));
super(Text.translatable(modid + ".midnightconfig.title"));
this.parent = parent; this.modid = modid;
this.translationPrefix = modid + ".midnightconfig.";
loadValuesFromJson(modid);

View File

@@ -40,35 +40,6 @@ public class MidnightConfigExample extends MidnightConfig {
QUILT, FABRIC, FORGE, NEOFORGE, VANILLA
}
@Entry(category = TEXT) public static GraphicsSteps graphicsSteps = GraphicsSteps.FABULOUS; // Example for an enum option with TranslatableOption
public enum GraphicsSteps implements TranslatableOption {
FAST(0, "options.graphics.fast"),
FANCY(1, "options.graphics.fancy"),
FABULOUS(2, "options.graphics.fabulous");
private final int id;
private final String translationKey;
GraphicsSteps(int id, String translationKey) {
this.id = id;
this.translationKey = translationKey;
}
@Override
public Text getText() {
MutableText mutableText = Text.translatable(this.getTranslationKey());
return this == GraphicsSteps.FABULOUS ? mutableText.formatted(Formatting.ITALIC).formatted(Formatting.AQUA) : mutableText;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getTranslationKey() {
return this.translationKey;
}
}
@Comment(category = TEXT, name = "§nMidnightLib Wiki", centered = true, url = "https://www.midnightdust.eu/wiki/midnightlib/") public static Comment wiki; // Example for a comment with a url
@@ -155,6 +126,36 @@ public class MidnightConfigExample extends MidnightConfig {
public static int imposter = 16777215; // - Entries without an @Entry or @Comment annotation are ignored
public enum GraphicsSteps implements TranslatableOption {
FAST(0, "options.graphics.fast"),
FANCY(1, "options.graphics.fancy"),
FABULOUS(2, "options.graphics.fabulous");
private final int id;
private final String translationKey;
GraphicsSteps(int id, String translationKey) {
this.id = id;
this.translationKey = translationKey;
}
@Override
public Text getText() {
MutableText mutableText = Text.translatable(this.getTranslationKey());
return this == GraphicsSteps.FABULOUS ? mutableText.formatted(Formatting.ITALIC).formatted(Formatting.AQUA) : mutableText;
}
@Override
public int getId() {
return this.id;
}
@Override
public String getTranslationKey() {
return this.translationKey;
}
}
@Condition(requiredModId = "thismoddoesnotexist")
@Comment(category = EXTRAS) public static Comment iAmJustADummy; // We only have this to initialize an empty tab for the keybinds below