From 92d1e282d8105438140cc9d6e5fb3bc65403397f Mon Sep 17 00:00:00 2001 From: TheWhiteDog9487 Date: Thu, 4 Jun 2026 11:42:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8YACL=20Config=20API=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=B0=86=E5=8A=9F=E8=83=BD=E5=BC=80=E5=85=B3=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=BF=9D=E5=AD=98=E5=88=B0=E6=96=87=E4=BB=B6=E5=86=85?= =?UTF-8?q?=20=E4=BD=BF=E7=94=A8=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=99=A8=E4=BD=BF=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=A2=AB=E5=A4=96=E9=83=A8=E6=9B=B4=E6=94=B9=E6=97=B6?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=87=AA=E5=8A=A8=E9=87=8D=E8=BD=BD=E5=88=B0?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E5=86=85=20=E8=A7=A3=E5=86=B3=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E8=BF=9E=E6=8E=A5=E7=AA=97=E5=8F=A3=E5=86=85=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=A1=86=E9=87=8C=E7=9A=84=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?IP=E6=B2=A1=E6=9C=89=E8=A2=AB=E7=A7=BB=E9=99=A4=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E5=A4=84=E7=90=86=E7=9A=84=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E5=9C=A8=E7=A7=BB=E9=99=A4=E7=A9=BA=E6=A0=BC=E4=B9=8B=E5=90=8E?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=8B=B1=E6=96=87README=20=E9=87=8D=E6=96=B0=E7=BB=99main?= =?UTF-8?q?=E5=85=A5=E5=8F=A3=E7=B1=BB=E6=B7=BB=E5=8A=A0`@Deprecated`?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=EF=BC=8C=E8=BF=99=E4=B8=9C=E8=A5=BF=E7=A1=AE?= =?UTF-8?q?=E5=AE=9E=E7=94=A8=E4=B8=8D=E5=88=B0=EF=BC=8C=E5=90=8E=E9=9D=A2?= =?UTF-8?q?=E7=9C=8B=E8=A6=81=E4=B8=8D=E8=A6=81=E7=9B=B4=E6=8E=A5=E5=88=A0?= =?UTF-8?q?=E4=BA=86=20=E4=B8=BAAI=20Agent=E6=B7=BB=E5=8A=A0AGENTS.md?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BB=A5=E6=8C=87=E7=A4=BA=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 6 ++ README.md | 25 ++++++- README_EN.md | 60 +++++++++++++++ build.gradle.kts | 5 +- gradle.properties | 9 ++- .../Event/ClientLifecycleEventsRegister.java | 18 +++++ .../java/xyz/thewhitedog9487/ModMenu.java | 10 ++- .../ServerAddressSpaceFixClient.java | 8 +- .../java/xyz/thewhitedog9487/Settings.java | 74 ++++++++++++++++++- .../client/DirectJoinServerScreenMixin.java | 41 ++++++++++ .../client/JoinMultiplayerScreenMixin.java | 30 -------- .../mixin/client/ManageServerScreenMixin.java | 19 +++-- .../mixin/client/ServerDataMixin.java | 18 ++++- .../serveraddressspacefix.client.mixins.json | 7 +- .../ServerAddressSpaceFix.java | 12 +-- src/main/resources/fabric.mod.json | 5 +- 更新日志 ChangeLog.md | 7 ++ 17 files changed, 289 insertions(+), 65 deletions(-) create mode 100644 AGENTS.md create mode 100644 README_EN.md create mode 100644 src/client/java/xyz/thewhitedog9487/Event/ClientLifecycleEventsRegister.java create mode 100644 src/client/java/xyz/thewhitedog9487/mixin/client/DirectJoinServerScreenMixin.java delete mode 100644 src/client/java/xyz/thewhitedog9487/mixin/client/JoinMultiplayerScreenMixin.java diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..d02e9f8 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,6 @@ +- 如果需要Minecraft经过反混淆的源码,直接在`.gradle/loom-cache/minecraftMaven/net/minecraft`目录下查找。 +- 源码使用完成之后记得删除解压jar产生的临时文件 + +- 使用帕斯卡命名法 + +- 如果你是正在翻译README的LLM,请遵守README内使用注释编写的指令 \ No newline at end of file diff --git a/README.md b/README.md index 3044640..ba5c52b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,24 @@ +[//]: # (如果你是正在执行翻译任务的LLM:) +[//]: # (请将这几行注释内容翻译到你的目标语言) +[//]: # (移除下方div内部第一行和第二行的注释符号,并翻译其内容) +[//]: # (不要翻译最后一段“一些小彩蛋”,直接将其从翻译版本中移除) + +
+ + + 简体中文(GitHub)     + 简体中文(Gitea)     + English(GitHub)     + English(Gitea) +
+ # 介绍 本模组意在修复一个2021年11月26号被报告但一直未修复的Bug [漏洞追踪器链接](https://bugs.mojang.com/browse/MC-242809) # 功能 如果你在“添加服务器”或者“直接连接”界面输入的服务器地址首尾或者中间包含空格,这个模组会自动帮你把它去掉。 -以防止上面提到的“未知的主机”Bug的出现。 +以防止上面提到的“未知的主机”Bug的出现。
为什么会有这个模组 @@ -28,6 +42,15 @@
+# 配置文件 +- 如果你开启了版本隔离,它应当位于`.minecraft\versions\<版本名>\config\serveraddressspacefix.json5` +- 如果没有版本隔离,它应该在`.minecraft\config\serveraddressspacefix.json5` + +这就是一个普通的json文本文件,只不过json5支持诸如注释等更多特性而已。 +所有的属性都有注释,包括功能、取值范围、类型、默认值等。 +使用普通的文本编辑器打开即可进行修改。 +你可以直接在游戏运行时编辑配置文件,保存之后会自动应用到游戏内。 + # 已知问题 所有已知问题均被修复,如果有新的欢迎通知我。 如果有谁愿意帮我把Bug修了,欢迎提交PR╰(*°▽°*)╯ diff --git a/README_EN.md b/README_EN.md new file mode 100644 index 0000000..504cef5 --- /dev/null +++ b/README_EN.md @@ -0,0 +1,60 @@ +[//]: # (If you are an LLM carrying out a translation task:) +[//]: # (Please translate these commented lines 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.) + +
+ 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. +
+ Simplified Chinese (GitHub)     + Simplified Chinese (Gitea)     + English (GitHub)     + English (Gitea) +
+ +# Introduction +This mod aims to fix a bug that was reported on 26 November 2021 but has still not been fixed. +[Bug tracker link](https://bugs.mojang.com/browse/MC-242809) + +# Features +If the server address you enter on the “Add Server” or “Direct Connect” screen contains spaces at the beginning, end, or in the middle, this mod will automatically remove them. +This prevents the “Unknown host” bug mentioned above. + +
+ Why this mod exists +
+		A few months ago, I wanted to play on a server. I copied the address from the server’s official website, pasted it into “Server Address”, and saved it — only to get “Unknown host”.
+		No panic; this clearly meant DNS had not resolved the corresponding address, so I pinged it first.
+		Ping could resolve the domain’s address, and then I suspected the Great Firewall might be doing something odd again, so I tested it with the tool on Chinaz, and every result matched mine.
+		That was rather odd.
+		After fiddling with it for a while, I found the problem.
+		There was a space at the end of the server address I had copied.
+		That was really infuriating. After messing around for a bit longer and confirming that the issue could be reproduced reliably, I submitted a bug to the tracker.
+		And what do you think happened? 
+		The issue I filed on the bug tracker
+		The comment below
+		An even earlier bug report
+		My English is absolutely terrible, so I did not keep going; the problem description was written using translation tools.
+		But deep down, I still thought this was rather absurd.
+		Since your address is a String, how hard can it be to call trim afterwards?
+		And as a player, when you tell me, “This was all your own carelessness; it does not even count as a bug,” I cannot accept that.
+		So, this mod came to be.
+	
+
+ +# Configuration +- If you have version isolation enabled, it should be located at `.minecraft\versions\\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. +You can open it in a plain text editor and modify it. +You can edit the config file while the game is running; once saved, the changes will be applied in-game automatically. + +# Known issues +All known issues have been fixed; if you find any new ones, please let me know. +If anyone is willing to help me fix the bug, please submit a PR ╰(*°▽°*)╯ + +# Licence +I use the more radical WTFPL rather than MIT. + diff --git a/build.gradle.kts b/build.gradle.kts index b921328..01a26fd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -37,7 +37,6 @@ loom { dependencies { // To change the versions see the gradle.properties file minecraft("com.mojang:minecraft:${providers.gradleProperty("minecraft_version").get()}") - implementation("net.fabricmc:fabric-loader:${providers.gradleProperty("loader_version").get()}") // Fabric API. This is technically optional, but you probably want it anyway. @@ -77,11 +76,11 @@ tasks.jar { from("LICENSE") { rename { "${it}_$projectName" } } - archiveFileName = "ServerAddressSpaceFix-${project.version} mc${providers.gradleProperty("compatible_with").get()}.jar" + archiveFileName = "${providers.gradleProperty("archives_base_name").get()}-${project.version} mc${providers.gradleProperty("compatible_with").get()}.jar" } tasks.named("sourcesJar") { - archiveFileName = "ServerAddressSpaceFix-${project.version} mc${providers.gradleProperty("compatible_with").get()}-sources.jar"} + archiveFileName = "${providers.gradleProperty("archives_base_name").get()}-${project.version} mc${providers.gradleProperty("compatible_with").get()}-sources.jar"} // configure the maven publication diff --git a/gradle.properties b/gradle.properties index e3a5bf3..ce0432d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ loader_version=0.18.4 loom_version=1.16-SNAPSHOT # Mod Properties -mod_version=0.2.2 +mod_version=0.2.3 maven_group=xyz.thewhitedog9487 archives_base_name=ServerAddressSpaceFix @@ -17,9 +17,14 @@ archives_base_name=ServerAddressSpaceFix fabric_api_version=0.144.0+26.1 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 + # 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 \ No newline at end of file +yacl_version=3.9.0+26.1-fabric + +# https://mvnrepository.com/artifact/org.projectlombok/lombok +lombok_version=1.18.46 \ No newline at end of file diff --git a/src/client/java/xyz/thewhitedog9487/Event/ClientLifecycleEventsRegister.java b/src/client/java/xyz/thewhitedog9487/Event/ClientLifecycleEventsRegister.java new file mode 100644 index 0000000..1cec35b --- /dev/null +++ b/src/client/java/xyz/thewhitedog9487/Event/ClientLifecycleEventsRegister.java @@ -0,0 +1,18 @@ +package xyz.thewhitedog9487.Event; + +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; + +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(); } ); + ClientLifecycleEvents.CLIENT_STOPPING.register(ClientInstance -> { + ModLogger.info("正在保存设置到" + Settings.ConfigFilePath + "..."); + Settings.SettingsHandler.save(); } ); } } \ No newline at end of file diff --git a/src/client/java/xyz/thewhitedog9487/ModMenu.java b/src/client/java/xyz/thewhitedog9487/ModMenu.java index b999681..3562737 100644 --- a/src/client/java/xyz/thewhitedog9487/ModMenu.java +++ b/src/client/java/xyz/thewhitedog9487/ModMenu.java @@ -9,6 +9,8 @@ import dev.isxander.yacl3.api.YetAnotherConfigLib; import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder; import net.minecraft.network.chat.Component; +import static xyz.thewhitedog9487.Settings.SettingsInstance; + public class ModMenu implements ModMenuApi { @Override public ConfigScreenFactory getModConfigScreenFactory() { @@ -18,10 +20,12 @@ public class ModMenu implements ModMenuApi { .name(Component.translatable("config.serveraddressspacefix.category.general")) .option(Option.createBuilder() .name(Component.translatable("option.serveraddressspacefix.ModEnabled")) - .binding(true, () -> Settings.ModEnabled, newVal -> Settings.ModEnabled = newVal) + .binding(true, () -> SettingsInstance.ModEnabled, newVal -> { + SettingsInstance.ModEnabled = newVal; + Settings.SettingsHandler.save(); } ) .description(OptionDescription.of(Component.translatable("option.serveraddressspacefix.ModEnabled.description"))) .controller(TickBoxControllerBuilder::create) .build()) .build()) - .build().generateScreen(parent);} -} \ No newline at end of file + .build() + .generateScreen(parent); } } \ No newline at end of file diff --git a/src/client/java/xyz/thewhitedog9487/ServerAddressSpaceFixClient.java b/src/client/java/xyz/thewhitedog9487/ServerAddressSpaceFixClient.java index c2a472f..70ef8e7 100644 --- a/src/client/java/xyz/thewhitedog9487/ServerAddressSpaceFixClient.java +++ b/src/client/java/xyz/thewhitedog9487/ServerAddressSpaceFixClient.java @@ -3,15 +3,15 @@ package xyz.thewhitedog9487; import net.fabricmc.api.ClientModInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import static xyz.thewhitedog9487.ServerAddressSpaceFix.ModID; +import xyz.thewhitedog9487.Event.ClientLifecycleEventsRegister; public class ServerAddressSpaceFixClient implements ClientModInitializer { - public static final Logger LOGGER = LoggerFactory.getLogger(ModID); + public static final String ModID = "serveraddressspacefix"; + public static final Logger ModLogger = LoggerFactory.getLogger(ModID); @Override public void onInitializeClient() { // This entrypoint is suitable for setting up client-specific logic, such as rendering. -// LOGGER.info("ServerAddressSpaceFix Loading!"); + ClientLifecycleEventsRegister.Register(); } } \ No newline at end of file diff --git a/src/client/java/xyz/thewhitedog9487/Settings.java b/src/client/java/xyz/thewhitedog9487/Settings.java index 7cb41af..d253612 100644 --- a/src/client/java/xyz/thewhitedog9487/Settings.java +++ b/src/client/java/xyz/thewhitedog9487/Settings.java @@ -1,5 +1,77 @@ package xyz.thewhitedog9487; +import com.google.gson.GsonBuilder; +import dev.isxander.yacl3.config.v2.api.ConfigClassHandler; +import dev.isxander.yacl3.config.v2.api.SerialEntry; +import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.resources.Identifier; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; +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; + public class Settings { - public static boolean ModEnabled = true; + public static Path ConfigFilePath = FabricLoader.getInstance() + .getConfigDir() + .resolve(ModID + ".json5") + .toAbsolutePath(); + public static ConfigClassHandler 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 volatile Settings SettingsInstance; + +// region 配置文件变更监听器 + public static void RegisterConfigFileReloadWatcher(){ + // 由GPT 5.4 Mini生成 + Thread.startVirtualThread(new Thread(() -> { + Path ConfigDirectory = ConfigFilePath.getParent(); + try (WatchService WatchService = FileSystems.getDefault().newWatchService()) { + ConfigDirectory.register(WatchService, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE); + while (!Thread.currentThread().isInterrupted()) { + WatchKey WatchKey = WatchService.take(); + boolean ShouldReload = false; + + for (WatchEvent WatchEvent : WatchKey.pollEvents()) { + WatchEvent.Kind EventKind = WatchEvent.kind(); + if (EventKind == StandardWatchEventKinds.OVERFLOW) { + continue; } + Path ChangedPath = (Path) WatchEvent.context(); + if (ChangedPath != null && ChangedPath.equals(ConfigFilePath.getFileName())) { + ShouldReload = true; } } + if (ShouldReload) { + SettingsHandler.load(); + SettingsInstance = SettingsHandler.instance(); + ModLogger.info("检测到配置文件变更,已重新加载设置。");} + if (!WatchKey.reset()) { + break;}} + } catch (InterruptedException InterruptedException) { + Thread.currentThread().interrupt(); + } catch (IOException e) { + throw new RuntimeException(e); } } ) ); } +// endregion + + @SerialEntry(comment = + """ + 是否启用本模组的功能 + 类型:布尔值 + 取值范围:true false + 默认值:true + """) + public boolean ModEnabled = true; } diff --git a/src/client/java/xyz/thewhitedog9487/mixin/client/DirectJoinServerScreenMixin.java b/src/client/java/xyz/thewhitedog9487/mixin/client/DirectJoinServerScreenMixin.java new file mode 100644 index 0000000..27178b9 --- /dev/null +++ b/src/client/java/xyz/thewhitedog9487/mixin/client/DirectJoinServerScreenMixin.java @@ -0,0 +1,41 @@ +package xyz.thewhitedog9487.mixin.client; + +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.DirectJoinServerScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static xyz.thewhitedog9487.ServerAddressSpaceFixClient.ModLogger; +import static xyz.thewhitedog9487.Settings.SettingsInstance; + +@Mixin(DirectJoinServerScreen.class) +public class DirectJoinServerScreenMixin { + @Shadow private EditBox ipEdit; + + @Inject(method = "init", at = @At("TAIL")) + private void onInit(CallbackInfo ci) { + RemoveSpaceCharacter(); } + + @Inject(method = "onSelect", at = @At("HEAD")) + private void onSelect(CallbackInfo ci) { + RemoveSpaceCharacter(); } + + @Inject(method = "removed", at = @At("HEAD")) + private void onRemoved(CallbackInfo ci) { + RemoveSpaceCharacter(); } + + @Unique + private void RemoveSpaceCharacter() { + var RawValue = ipEdit.getValue(); + if (SettingsInstance.ModEnabled == false || + RawValue.contains(" ") == false) { return; } + var NewValue = RawValue.replace(" ", ""); + this.ipEdit.setValue(NewValue); + ModLogger.info("已完成移除空格替换!" + "\n" + + "原始值:" + RawValue + "\n" + + "新值:" + NewValue); } } + diff --git a/src/client/java/xyz/thewhitedog9487/mixin/client/JoinMultiplayerScreenMixin.java b/src/client/java/xyz/thewhitedog9487/mixin/client/JoinMultiplayerScreenMixin.java deleted file mode 100644 index 894d5c1..0000000 --- a/src/client/java/xyz/thewhitedog9487/mixin/client/JoinMultiplayerScreenMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package xyz.thewhitedog9487.mixin.client; - -import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen; -import net.minecraft.client.multiplayer.ServerData; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import xyz.thewhitedog9487.Settings; - -@Mixin(JoinMultiplayerScreen.class) -public class JoinMultiplayerScreenMixin { - @Shadow public ServerData editingServer; - - @Inject( - method = "directJoinCallback", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/multiplayer/ServerList;get(Ljava/lang/String;)Lnet/minecraft/client/multiplayer/ServerData;", - shift = At.Shift.BEFORE ) ) - private void onDirectJoinCallback(boolean result, CallbackInfo ci) { - if ( Settings.ModEnabled == false ) { return; } - else { - this.editingServer = new ServerData( - this.editingServer.name, - this.editingServer.ip.replace(" ", ""), - this.editingServer.type() ); } } } \ No newline at end of file diff --git a/src/client/java/xyz/thewhitedog9487/mixin/client/ManageServerScreenMixin.java b/src/client/java/xyz/thewhitedog9487/mixin/client/ManageServerScreenMixin.java index a6843b2..db8d7f7 100644 --- a/src/client/java/xyz/thewhitedog9487/mixin/client/ManageServerScreenMixin.java +++ b/src/client/java/xyz/thewhitedog9487/mixin/client/ManageServerScreenMixin.java @@ -5,7 +5,9 @@ import net.minecraft.client.gui.screens.ManageServerScreen; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import xyz.thewhitedog9487.Settings; + +import static xyz.thewhitedog9487.ServerAddressSpaceFixClient.ModLogger; +import static xyz.thewhitedog9487.Settings.SettingsInstance; @Mixin(ManageServerScreen.class) public class ManageServerScreenMixin { @@ -16,9 +18,14 @@ public class ManageServerScreenMixin { value = "INVOKE", target = "Lnet/minecraft/client/gui/components/EditBox;getValue()Ljava/lang/String;", ordinal = 1 ) ) - private String redirectIpEditGetValue(EditBox instance) { - if ( Settings.ModEnabled == false ) { - return instance.getValue(); } + private String RedirectIpEditGetValue(EditBox instance) { + var RawValue = instance.getValue(); + if ( SettingsInstance.ModEnabled == false || + RawValue.contains(" ") == false) { + return RawValue; } else { - return instance.getValue() - .replace(" ", ""); } } } \ No newline at end of file + var NewValue = RawValue.replace(" ", ""); + ModLogger.info("已完成移除空格替换!" + "\n" + + "原始值:" + RawValue + "\n" + + "新值:" + NewValue); + return NewValue; } } } \ No newline at end of file diff --git a/src/client/java/xyz/thewhitedog9487/mixin/client/ServerDataMixin.java b/src/client/java/xyz/thewhitedog9487/mixin/client/ServerDataMixin.java index 4103b33..dbb92f0 100644 --- a/src/client/java/xyz/thewhitedog9487/mixin/client/ServerDataMixin.java +++ b/src/client/java/xyz/thewhitedog9487/mixin/client/ServerDataMixin.java @@ -1,18 +1,30 @@ package xyz.thewhitedog9487.mixin.client; import net.minecraft.client.multiplayer.ServerData; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import xyz.thewhitedog9487.Settings; + +import static xyz.thewhitedog9487.ServerAddressSpaceFixClient.ModLogger; +import static xyz.thewhitedog9487.Settings.SettingsInstance; @Mixin(ServerData.class) public class ServerDataMixin { + /** + * 用于处理服务器列表内已经存在的服务器项的IP存在空格的问题 + */ @Redirect(method = "", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/multiplayer/ServerData;ip:Ljava/lang/String;")) private void RemoveSpace_Write(ServerData original, String value) { - if( Settings.ModEnabled == false ) { + @Nullable String RawValue = value; + if (SettingsInstance.ModEnabled == false || + RawValue.contains(" ") == false) { original.ip = value; return; } else { - original.ip = value.replace(" ", ""); } } } \ No newline at end of file + var NewValue = RawValue.replace(" ", ""); + original.ip = NewValue; + ModLogger.info("已完成移除空格替换!" + "\n" + + "原始值:" + RawValue + "\n" + + "新值:" + NewValue); } } } \ No newline at end of file diff --git a/src/client/resources/serveraddressspacefix.client.mixins.json b/src/client/resources/serveraddressspacefix.client.mixins.json index dca8ee8..056824c 100644 --- a/src/client/resources/serveraddressspacefix.client.mixins.json +++ b/src/client/resources/serveraddressspacefix.client.mixins.json @@ -3,14 +3,13 @@ "package": "xyz.thewhitedog9487.mixin.client", "compatibilityLevel": "JAVA_25", "client": [ - "ServerDataMixin", - "JoinMultiplayerScreenMixin", - "ManageServerScreenMixin" + "DirectJoinServerScreenMixin", + "ManageServerScreenMixin", + "ServerDataMixin" ], "injectors": { "defaultRequire": 1 }, "mixins": [ - ] } \ No newline at end of file diff --git a/src/main/java/xyz/thewhitedog9487/ServerAddressSpaceFix.java b/src/main/java/xyz/thewhitedog9487/ServerAddressSpaceFix.java index 772eee2..1d72dab 100644 --- a/src/main/java/xyz/thewhitedog9487/ServerAddressSpaceFix.java +++ b/src/main/java/xyz/thewhitedog9487/ServerAddressSpaceFix.java @@ -2,15 +2,16 @@ package xyz.thewhitedog9487; import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +/** + * 所有的代码都在client源集内 + * @deprecated 目前没有任何用途 + * @see ServerAddressSpaceFixClient + */ +@Deprecated public class ServerAddressSpaceFix implements ModInitializer { // This logger is used to write text to the console and the log file. // It is considered best practice to use your mod id as the logger's name. // That way, it's clear which mod wrote info, warnings, and errors. - public static final String ModID = "serveraddressspacefix"; - public static final Logger LOGGER = LoggerFactory.getLogger(ModID); @Override public void onInitialize() { @@ -18,6 +19,5 @@ public class ServerAddressSpaceFix implements ModInitializer { // However, some things (like resources) may still be uninitialized. // Proceed with mild caution. - LOGGER.info("Hello Fabric world!"); } } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b3e5b6b..015cc7e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,6 +28,7 @@ ], "depends": { "fabricloader": ">=0.18.4", + "fabric-api": ">=0.144.0", "minecraft": "26.*", "java": ">=25" }, @@ -39,8 +40,8 @@ "modmenu": { "links": { "serveraddressspacefix.bilibili": "https://space.bilibili.com/401746666", - "serveraddressspacefix.blog": "www.thewhitedog9487.xyz"}, - "update_checker": true}}, + "serveraddressspacefix.blog": "https://www.thewhitedog9487.xyz"}, + "update_checker": true } }, "contributors": [ "JustAlittleWolf" ], diff --git a/更新日志 ChangeLog.md b/更新日志 ChangeLog.md index ef0d277..4594e99 100644 --- a/更新日志 ChangeLog.md +++ b/更新日志 ChangeLog.md @@ -1,3 +1,10 @@ +# 0.2.3 +时间:2026 06 04 +1. 使用YACL Config API自动将功能开关状态保存到文件内 +2. 解决直接连接窗口内输入框里的服务器IP没有被移除空格处理的问题 +3. 在移除空格之后打印日志 +4. 更改ModID + # 0.2.2 时间:2026 03 26 1. 新到Minecraft 26.1