From 413fb34fd876b7a1ff99589a6c0c7a1eb16527b3 Mon Sep 17 00:00:00 2001 From: Jerozgen Date: Tue, 14 May 2024 21:39:28 +0300 Subject: [PATCH] Fix English (US) is missing after updating to 1.6 --- gradle.properties | 2 +- .../languagereload/config/Config.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a89f75f..730789f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ loader_version=0.15.11 fabric_version=0.98.0+1.20.6 # Mod Properties -mod_version=1.6+1.20.6 +mod_version=1.6.1+1.20.6 maven_group=jerozgen archives_base_name=language-reload diff --git a/src/main/java/jerozgen/languagereload/config/Config.java b/src/main/java/jerozgen/languagereload/config/Config.java index 21bfe4e..accb86f 100644 --- a/src/main/java/jerozgen/languagereload/config/Config.java +++ b/src/main/java/jerozgen/languagereload/config/Config.java @@ -6,6 +6,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.util.Language; import java.nio.file.Files; import java.nio.file.Path; @@ -19,6 +20,8 @@ public class Config { private static Config INSTANCE; + public int version = 0; + public boolean multilingualItemSearch = true; public LinkedList fallbacks = new LinkedList<>(); public LinkedList previousFallbacks = new LinkedList<>(); @@ -38,6 +41,8 @@ public static void load() { LanguageReload.LOGGER.error("Couldn't load config file: ", e); } + migrateToVersion1(); + if (INSTANCE.language.equals(LanguageReload.NO_LANGUAGE) && !INSTANCE.fallbacks.isEmpty()) { INSTANCE.language = INSTANCE.fallbacks.pollFirst(); } @@ -59,4 +64,21 @@ public static Config getInstance() { if (INSTANCE == null) load(); return INSTANCE; } + + private static void migrateToVersion1() { + if (INSTANCE.version >= 1) return; + INSTANCE.version = 1; + + if (!INSTANCE.language.isEmpty() + && !INSTANCE.language.equals(Language.DEFAULT_LANGUAGE) + && !INSTANCE.fallbacks.contains(Language.DEFAULT_LANGUAGE)) + INSTANCE.fallbacks.add(Language.DEFAULT_LANGUAGE); + + if (!INSTANCE.previousLanguage.isEmpty() + && !INSTANCE.previousLanguage.equals(Language.DEFAULT_LANGUAGE) + && !INSTANCE.previousFallbacks.contains(Language.DEFAULT_LANGUAGE)) + INSTANCE.previousFallbacks.add(Language.DEFAULT_LANGUAGE); + + save(); + } }