修复未安装YACL会导致游戏出现`NoClassDefFoundError`崩溃的问题
将配置文件名从`serveraddressspacefix.json5`改为`ServerAddressSpaceFix.json5`
为配置文件添加版本号
更改Logger名称
This commit is contained in:
TheWhiteDog9487
2026-06-17 12:57:11 +08:00
parent 92d1e282d8
commit abd1378634
9 changed files with 127 additions and 35 deletions
+6 -4
View File
@@ -1,10 +1,12 @@
[//]: # (如果你是正在执行翻译任务的LLM:)
[//]: # (请将这几行注释内容翻译到你的目标语言)
[//]: # (移除下方div内部第一行和第二行的注释符号,并翻译其内容)
[//]: # (不要翻译最后一段“一些小彩蛋”,直接将其从翻译版本中移除)
[//]: # (不要翻译下方div内部a标签的文本内容和链接地址)
[//]: # (不要改动下方div标签的align="center"属性)
[//]: # (将翻译的结果放置到正确的文件内,目标文件的位置和主README.md同级,文件名格式是 README_<LANG>.md ,其中<LANG>的值是目标语言的IETF语言标签)
<div align="center">
<!-- <strong>注意:本文档由中文编写。如果条件允许,建议阅读原始的中文文档而不是其他的翻译版本。</strong> -->
<!-- <strong>注意:本文档由中文编写,使用AI翻译到其他语言。如果条件允许,建议阅读原始的中文文档而不是其他的翻译版本。</strong> -->
<!-- <br/> -->
<a href="https://github.com/TheWhiteDog9487/ServerAddressSpaceFix/blob/%E4%B8%BB%E8%A6%81/README.md">简体中文(GitHub</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://git.thewhitedog9487.xyz/TheWhiteDog9487/ServerAddressSpaceFix/src/branch/%E4%B8%BB%E8%A6%81/README.md">简体中文(Gitea</a>&nbsp;&nbsp;&nbsp;&nbsp;
@@ -43,8 +45,8 @@
</details>
# 配置文件
- 如果你开启了版本隔离,它应当位于`.minecraft\versions\<版本名>\config\serveraddressspacefix.json5`
- 如果没有版本隔离,它应该在`.minecraft\config\serveraddressspacefix.json5`
- 如果你开启了版本隔离,它应当位于`.minecraft\versions\<版本名>\config\ServerAddressSpaceFix.json5`
- 如果没有版本隔离,它应该在`.minecraft\config\ServerAddressSpaceFix.json5`
这就是一个普通的json文本文件,只不过json5支持诸如注释等更多特性而已。
所有的属性都有注释,包括功能、取值范围、类型、默认值等。
+8 -6
View File
@@ -1,13 +1,15 @@
[//]: # (If you are an LLM carrying out a translation task:)
[//]: # (Please translate these commented lines into your target language.)
[//]: # (Please translate the commented lines below into your target language.)
[//]: # (Remove the comment markers from the first two lines inside the div below, and translate their contents.)
[//]: # (Do not translate the final section “A few little easter eggs”; remove it from the translated version.)
[//]: # (Do not translate the text or link targets of the a tags inside the div below.)
[//]: # (Do not change the align="center" attribute on the div below.)
[//]: # (Place the translated result in the correct file, alongside README.md, named README_<LANG>.md, where <LANG> is the IETF language tag of the target language.)
<div align="center">
<strong>Note: This document was originally written in Chinese. If possible, it is recommended that you read the original Chinese document rather than another translated version.</strong>
<br/>
<a href="https://github.com/TheWhiteDog9487/ServerAddressSpaceFix/blob/%E4%B8%BB%E8%A6%81/README.md">Simplified Chinese (GitHub)</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://git.thewhitedog9487.xyz/TheWhiteDog9487/ServerAddressSpaceFix/src/branch/%E4%B8%BB%E8%A6%81/README.md">Simplified Chinese (Gitea)</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://github.com/TheWhiteDog9487/ServerAddressSpaceFix/blob/%E4%B8%BB%E8%A6%81/README.md">简体中文 (GitHub)</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://git.thewhitedog9487.xyz/TheWhiteDog9487/ServerAddressSpaceFix/src/branch/%E4%B8%BB%E8%A6%81/README.md">简体中文 (Gitea)</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://github.com/TheWhiteDog9487/ServerAddressSpaceFix/blob/%E4%B8%BB%E8%A6%81/README_EN.md">English (GitHub)</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://git.thewhitedog9487.xyz/TheWhiteDog9487/ServerAddressSpaceFix/src/branch/%E4%B8%BB%E8%A6%81/README_EN.md">English (Gitea)</a>
</div>
@@ -43,8 +45,8 @@ This prevents the “Unknown host” bug mentioned above.
</details>
# Configuration
- If you have version isolation enabled, it should be located at `.minecraft\versions\<version name>\config\serveraddressspacefix.json5`
- If you do not have version isolation enabled, it should be at `.minecraft\config\serveraddressspacefix.json5`
- If you have version isolation enabled, it should be located at `.minecraft\versions\<version name>\config\ServerAddressSpaceFix.json5`
- If you do not have version isolation enabled, it should be at `.minecraft\config\ServerAddressSpaceFix.json5`
This is just a regular JSON text file, except that JSON5 supports extra features such as comments.
All properties are annotated, including their purpose, range of values, type, default value, and so on.
+23
View File
@@ -1,3 +1,5 @@
import java.nio.file.Paths
plugins {
id("net.fabricmc.fabric-loom")
`maven-publish`
@@ -22,6 +24,27 @@ repositories {
name = "Nucleoid"
url = uri("https://maven.nucleoid.xyz/") } }
afterEvaluate {
val MixinJarPath = configurations.loaderLibraries.get().resolvedConfiguration
.resolvedArtifacts
.find { it.moduleVersion.id.group == "net.fabricmc" && it.moduleVersion.id.name == "sponge-mixin" }!!
.file
val IsSupportDceVM = Paths.get(System.getProperty("java.home"))
.resolve("bin")
.resolve("java")
.toFile()
.let {
val ReturnCode = ProcessBuilder(it.absolutePath, "-XX:+AllowEnhancedClassRedefinition", "-version")
.start()
.waitFor()
return@let ReturnCode == 0 }
loom.runs.named("client") {
jvmArguments.add("-javaagent:${MixinJarPath.absolutePath}")
if (IsSupportDceVM == true) jvmArguments.add("-XX:+AllowEnhancedClassRedefinition") }
loom.runs.named("server") {
jvmArguments.add("-javaagent:${MixinJarPath.absolutePath}")
if (IsSupportDceVM == true) jvmArguments.add("-XX:+AllowEnhancedClassRedefinition") } }
loom {
splitEnvironmentSourceSets()
+4 -7
View File
@@ -6,10 +6,10 @@ org.gradle.parallel=true
# check these on https://fabricmc.net/develop
minecraft_version=26.1
loader_version=0.18.4
loom_version=1.16-SNAPSHOT
loom_version=1.17-SNAPSHOT
# Mod Properties
mod_version=0.2.3
mod_version=0.2.4
maven_group=xyz.thewhitedog9487
archives_base_name=ServerAddressSpaceFix
@@ -20,11 +20,8 @@ compatible_with=26.x
# https://modrinth.com/mod/modmenu/versions
# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
modmenu_version=18.0.0-alpha.7
modmenu_version=18.0.0-beta.1
# https://modrinth.com/mod/yacl/versions
# https://maven.isxander.dev/#/releases/dev/isxander/yet-another-config-lib
yacl_version=3.9.0+26.1-fabric
# https://mvnrepository.com/artifact/org.projectlombok/lombok
lombok_version=1.18.46
yacl_version=3.9.0+26.1-fabric
@@ -4,15 +4,24 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import xyz.thewhitedog9487.Settings;
import static xyz.thewhitedog9487.ServerAddressSpaceFixClient.ModLogger;
import static xyz.thewhitedog9487.Settings.SettingsInstance;
import static xyz.thewhitedog9487.Settings.*;
public class ClientLifecycleEventsRegister {
public static void Register(){
ClientLifecycleEvents.CLIENT_STARTED.register(ClientInstance -> {
ModLogger.info("正在从" + Settings.ConfigFilePath + "加载设置...");
Settings.SettingsHandler.load();
SettingsInstance = Settings.SettingsHandler.instance();
Settings.RegisterConfigFileReloadWatcher(); } );
if (Settings.SettingsHandler == null){
ModLogger.warn("当前没有安装YACL,因此无法调整和保持Mod配置");
SettingsInstance = new Settings(); }
else {
ModLogger.info("正在从" + Settings.ConfigFilePath + "加载设置...");
Settings.SettingsHandler.load();
SettingsInstance = Settings.SettingsHandler.instance();
if (SettingsInstance.ConfigurationVersionCode != CurrentConfigurationVersionCode){
// 必要时手动处理升降级,现在不必要,就这么办了
SettingsInstance.ConfigurationVersionCode = CurrentConfigurationVersionCode;
SettingsHandler.save(); }
Settings.RegisterConfigFileReloadWatcher(); } } );
ClientLifecycleEvents.CLIENT_STOPPING.register(ClientInstance -> {
if (Settings.SettingsHandler == null) return;
ModLogger.info("正在保存设置到" + Settings.ConfigFilePath + "...");
Settings.SettingsHandler.save(); } ); } }
@@ -0,0 +1,33 @@
package xyz.thewhitedog9487;
import net.fabricmc.loader.api.FabricLoader;
import java.io.IOException;
import java.nio.file.Files;
import static xyz.thewhitedog9487.ServerAddressSpaceFixClient.*;
/**
* 预计27.1正式版发布后删除
*/
@Deprecated
public class RemoveInFuture {
@Deprecated
public static void MigrateConfiguration() {
var OldPath = FabricLoader.getInstance()
.getConfigDir()
.resolve(ModID + ".json5")
.toAbsolutePath();
if (OldPath.toFile().exists()){
try {
ModLogger.info("发现旧的配置文件,正在进行迁移");
Files.copy(OldPath, Settings.ConfigFilePath);
boolean IsSuccessDeleted = OldPath.toFile().delete();
if (IsSuccessDeleted) {
ModLogger.info("迁移完成,已删除旧的配置文件");
} else {
ModLogger.warn("迁移完成,但未能删除旧的配置文件,请手动删除 " + OldPath.toAbsolutePath()); }
} catch (IOException e) {
ModLogger.error("迁移配置文件失败");
ModLogger.error(e.getLocalizedMessage());
e.printStackTrace(); } } } }
@@ -7,11 +7,13 @@ import xyz.thewhitedog9487.Event.ClientLifecycleEventsRegister;
public class ServerAddressSpaceFixClient implements ClientModInitializer {
public static final String ModID = "serveraddressspacefix";
public static final Logger ModLogger = LoggerFactory.getLogger(ModID);
public static final String FriendlyModID = "ServerAddressSpaceFix";
public static final Logger ModLogger = LoggerFactory.getLogger(FriendlyModID);
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
RemoveInFuture.MigrateConfiguration();
ClientLifecycleEventsRegister.Register();
}
}
@@ -18,22 +18,28 @@ import java.nio.file.WatchService;
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
import static xyz.thewhitedog9487.ServerAddressSpaceFixClient.ModID;
import static xyz.thewhitedog9487.ServerAddressSpaceFixClient.ModLogger;
import static xyz.thewhitedog9487.ServerAddressSpaceFixClient.*;
public class Settings {
public static Path ConfigFilePath = FabricLoader.getInstance()
.getConfigDir()
.resolve(ModID + ".json5")
.resolve(FriendlyModID + ".json5")
.toAbsolutePath();
public static ConfigClassHandler<Settings> SettingsHandler = ConfigClassHandler.createBuilder(Settings.class)
.id(Identifier.fromNamespaceAndPath(ModID, "settings_confighandler"))
.serializer(SettingsConfigClassHandler -> GsonConfigSerializerBuilder.create(SettingsConfigClassHandler)
.setPath(ConfigFilePath)
.appendGsonBuilder(GsonBuilder::setPrettyPrinting)
.setJson5(true)
.build() )
.build();
public static ConfigClassHandler<Settings> SettingsHandler = null;
public static long CurrentConfigurationVersionCode = 0;
static {
try {
SettingsHandler = ConfigClassHandler.createBuilder(Settings.class)
.id(Identifier.fromNamespaceAndPath(ModID, "settings_confighandler"))
.serializer(SettingsConfigClassHandler -> GsonConfigSerializerBuilder.create(SettingsConfigClassHandler)
.setPath(ConfigFilePath)
.appendGsonBuilder(GsonBuilder::setPrettyPrinting)
.setJson5(true)
.build() )
.build();
} catch (NoClassDefFoundError _) {} }
public static volatile Settings SettingsInstance;
// region 配置文件变更监听器
@@ -59,13 +65,24 @@ public class Settings {
SettingsInstance = SettingsHandler.instance();
ModLogger.info("检测到配置文件变更,已重新加载设置。");}
if (!WatchKey.reset()) {
break;}}
break; } }
} catch (InterruptedException InterruptedException) {
Thread.currentThread().interrupt();
} catch (IOException e) {
throw new RuntimeException(e); } } ) ); }
// endregion
@SerialEntry(comment =
"""
配置文件版本号
用于在配置文件结构发生变化且需要手动干预时进行兼容性处理
非必要情况下你不应该手动修改这个数据,否则可能导致本Mod的配置文件出现损坏或其他问题
类型:整数
取值范围:0 ~ Long.MAX_VALUE
当前值:0
""")
public long ConfigurationVersionCode = CurrentConfigurationVersionCode;
@SerialEntry(comment =
"""
是否启用本模组的功能
+7
View File
@@ -1,3 +1,10 @@
# 0.2.4
时间:2026 06 17
1. 修复未安装YACL会导致游戏出现`NoClassDefFoundError`崩溃的问题
2. 将配置文件名从`serveraddressspacefix.json5`改为`ServerAddressSpaceFix.json5`
3. 为配置文件添加版本号
4. 更改Logger名称
# 0.2.3
时间:2026 06 04
1. 使用YACL Config API自动将功能开关状态保存到文件内