-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
优化语言设置方法,修复更新检测出现问题时提示两次的问题,再次修复
SuggestModScreen
背景问题
- Loading branch information
Showing
10 changed files
with
99 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ classes/ | |
.metadata | ||
.vscode | ||
.settings | ||
*.launch | ||
*.launch | ||
/.architectury-transformer/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
common/src/main/java/top/vmctcn/vmtranslationupdate/VMTranslationUpdate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
package top.vmctcn.vmtranslationupdate; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import top.vmctcn.vmtranslationupdate.util.GameOptionsUtil; | ||
import top.vmctcn.vmtranslationupdate.util.ModConfigUtil; | ||
import top.vmctcn.vmtranslationupdate.util.ScreenUtil; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class VMTranslationUpdate { | ||
public static final String MOD_ID = "vmtranslationupdate"; | ||
static MinecraftClient client = MinecraftClient.getInstance(); | ||
public static final Logger LOGGER = LoggerFactory.getLogger("VMTranslationUpdateMod"); | ||
public static final Path OPTIONS_FILE = Paths.get(MinecraftClient.getInstance().runDirectory.toString(), "options.txt"); | ||
|
||
public static void init() { | ||
ScreenUtil.checkModsLoaded(); | ||
|
||
if (ModConfigUtil.getConfig().autoSwitchLanguage && ModConfigUtil.getConfig().switchLanguage != null) { | ||
client.options.language = ModConfigUtil.getConfig().switchLanguage; | ||
try { | ||
GameOptionsUtil.createInitFile(OPTIONS_FILE.toFile()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
common/src/main/java/top/vmctcn/vmtranslationupdate/util/GameOptionsUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package top.vmctcn.vmtranslationupdate.util; | ||
|
||
import com.google.common.collect.Lists; | ||
import org.apache.commons.io.FileUtils; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
public class GameOptionsUtil { | ||
private static final String DEFAULT_LANG = "lang:" + ModConfigUtil.getConfig().switchLanguage; | ||
private static final String INIT_OPTIONS = DEFAULT_LANG; | ||
|
||
public static void createInitFile(File optionsFile) throws IOException { | ||
if (!optionsFile.exists()) { | ||
FileUtils.write(optionsFile, INIT_OPTIONS, StandardCharsets.UTF_8); | ||
} else { | ||
changeFile(optionsFile); | ||
} | ||
} | ||
|
||
private static void changeFile(File optionsFile) throws IOException { | ||
List<String> options = FileUtils.readLines(optionsFile, StandardCharsets.UTF_8); | ||
List<String> output = Lists.newArrayList(); | ||
boolean hasLang = false; | ||
|
||
for (String line : options) { | ||
if (line.startsWith("lang:")) { | ||
line = DEFAULT_LANG; | ||
hasLang = true; | ||
} | ||
|
||
output.add(line); | ||
} | ||
|
||
if (!hasLang) { | ||
output.add(DEFAULT_LANG); | ||
} | ||
|
||
FileUtils.writeLines(optionsFile, StandardCharsets.UTF_8.name(), output, "\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
.../src/main/java/top/vmctcn/vmtranslationupdate/fabric/VMTranslationUpdateClientFabric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters