Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into 1.19.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	src/main/java/jerozgen/languagereload/config/Config.java
  • Loading branch information
Jerozgen committed May 14, 2024
2 parents babd927 + 413fb34 commit f6bad7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loader_version=0.15.11
fabric_version=0.77.0+1.19.2

# Mod Properties
mod_version=1.6+1.19.2
mod_version=1.6.1+1.19.2
maven_group=jerozgen
archives_base_name=language-reload

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/jerozgen/languagereload/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +20,8 @@ public class Config {

private static Config INSTANCE;

public int version = 0;

public boolean multilingualItemSearch = true;
public LinkedList<String> fallbacks = new LinkedList<>();
public LinkedList<String> previousFallbacks = new LinkedList<>();
Expand All @@ -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_CODE) && !INSTANCE.fallbacks.isEmpty()) {
INSTANCE.language = INSTANCE.fallbacks.pollFirst();
}
Expand All @@ -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();
}
}

0 comments on commit f6bad7f

Please sign in to comment.