时间:2024 01 15
主要内容:
1. 更新开发环境到1.20.4
2. 更新Fabric Loader和Fabric API的版本
3. 使用YetAnotherConfigLib和ModMenu为模组创建一个配置屏幕
4. 配置选项中增加是否启用模组功能的开关
5. 移除自使用Redirect注解之后不再被需要的接口和方法
6. 在客户端侧的初始化方法中,让日志记录器打印一段日志,方便调试和除错
7. 更新Mixin注入的类的路径(这东西居然更新了)
This commit is contained in:
2024-01-15 14:58:30 +08:00
parent ee6a656041
commit 789ad58006
14 changed files with 83 additions and 35 deletions

View File

@@ -0,0 +1,26 @@
package xyz.thewhitedog9487;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import dev.isxander.yacl3.api.ConfigCategory;
import dev.isxander.yacl3.api.Option;
import dev.isxander.yacl3.api.OptionDescription;
import dev.isxander.yacl3.api.YetAnotherConfigLib;
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
import net.minecraft.text.Text;
public class ModMenu implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> YetAnotherConfigLib.createBuilder()
.title(Text.translatable("title.thewhitedog9487.twd-sasf.config"))
.category(ConfigCategory.createBuilder()
.name(Text.translatable("config.thewhitedog9487.twd-sasf.category.general"))
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("option.thewhitedog9487.twd-sasf.ModEnabled"))
.binding(true, () -> Settings.ModEnabled, newVal -> Settings.ModEnabled = newVal)
.description(OptionDescription.of(Text.translatable("option.thewhitedog9487.twd-sasf.ModEnabled.description")))
.controller(TickBoxControllerBuilder::create)
.build())
.build())
.build().generateScreen(parent);}}

View File

@@ -1,10 +1,14 @@
package xyz.thewhitedog9487;
import net.fabricmc.api.ClientModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ServerAddressSpaceFixClient implements ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("twd-sasf");
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
LOGGER.info("ServerAddressSpaceFix正在初始化!");
}
}

View File

@@ -0,0 +1,5 @@
package xyz.thewhitedog9487;
public class Settings {
public static boolean ModEnabled = true;
}

View File

@@ -1,15 +0,0 @@
package xyz.thewhitedog9487.mixin.client;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(net.minecraft.client.gui.screen.AddServerScreen.class)
public interface AddServerScreenAccessor {
@Accessor("server")
ServerInfo Mixin_GetServer();
@Accessor("addressField")
TextFieldWidget Mixin_GetAddressField();
}

View File

@@ -5,11 +5,8 @@ import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(net.minecraft.client.gui.screen.DirectConnectScreen.class)
@Mixin(net.minecraft.client.gui.screen.multiplayer.DirectConnectScreen.class)
public interface DirectConnectScreenAccessor {
@Accessor("serverEntry")
ServerInfo Mixin_GetServerEntry();
@Accessor("addressField")
TextFieldWidget Mixin_GetAddressField();
}

View File

@@ -4,9 +4,11 @@ import net.minecraft.client.gui.widget.TextFieldWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import xyz.thewhitedog9487.Settings;
@Mixin(net.minecraft.client.gui.screen.AddServerScreen.class)
@Mixin(net.minecraft.client.gui.screen.multiplayer.AddServerScreen.class)
public class MixinAddServerScreen {
@Redirect(method = "addAndClose", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;getText()Ljava/lang/String;", ordinal = 1))
private String trimGetText(TextFieldWidget instance) {
if( !Settings.ModEnabled ) { return instance.getText(); }
return instance.getText().replace(" ", "");}}

View File

@@ -4,11 +4,13 @@ import net.minecraft.client.gui.widget.TextFieldWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import xyz.thewhitedog9487.Settings;
@Mixin(net.minecraft.client.gui.screen.DirectConnectScreen.class)
@Mixin(net.minecraft.client.gui.screen.multiplayer.DirectConnectScreen.class)
public class MixinDirectConnectScreen {
@Redirect(method = "saveAndClose", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;getText()Ljava/lang/String;"))
private String trimGetText(TextFieldWidget instance) {
if( !Settings.ModEnabled ) { return instance.getText(); }
String trimmedText = instance.getText().replace(" ", "");
((DirectConnectScreenAccessor) this).Mixin_GetAddressField().setText(trimmedText);
return trimmedText;}}
return trimmedText;}}

View File

@@ -5,6 +5,7 @@ import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@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.

View File

@@ -1,6 +1,10 @@
{
"modmenu.nameTranslation.twd-sasf": "ServerAddressSpaceFix",
"modmenu.descriptionTranslation.twd-sasf": "Fixed the \"unknown host\" bug caused by the server address containing spaces at the beginning and end of the server address when adding a server or connecting directly",
"modmenu.descriptionTranslation.twd-sasf": "Fixed the \"unknown host\" bug caused by the server address containing spaces at the beginning and end of the server address when adding a server or connecting directly\nTip: If you need to use the configuration menu, install the YetAnotherConfigLib mod",
"twd-sasf.bilibili": "Bilibili",
"twd-sasf.blog": "Blog"
"twd-sasf.blog": "Blog",
"title.thewhitedog9487.twd-sasf.config": "ServerAddressSpaceFix",
"config.thewhitedog9487.twd-sasf.category.general": "General",
"option.thewhitedog9487.twd-sasf.ModEnabled": "Whether To Enable The Mod Feature",
"option.thewhitedog9487.twd-sasf.ModEnabled.description": "There is no need to restart the game, and the modification will take effect immediately after it is saved"
}

View File

@@ -1,6 +1,10 @@
{
"modmenu.nameTranslation.twd-sasf": "服务器地址首尾空格修复",
"modmenu.descriptionTranslation.twd-sasf": "修复添加服务器或直接连接时服务器地址首尾包含空格导致的“未知的主机”Bug",
"modmenu.descriptionTranslation.twd-sasf": "修复添加服务器或直接连接时服务器地址首尾包含空格导致的“未知的主机”Bug\n提示如果需要使用配置菜单请安装YetAnotherConfigLib模组",
"twd-sasf.bilibili": "哔哩哔哩主页",
"twd-sasf.blog": "TheWhiteDog9487的博客"
"twd-sasf.blog": "TheWhiteDog9487的博客",
"title.thewhitedog9487.twd-sasf.config": "服务器地址首尾空格修复",
"config.thewhitedog9487.twd-sasf.category.general": "通用",
"option.thewhitedog9487.twd-sasf.ModEnabled": "是否启用模组功能",
"option.thewhitedog9487.twd-sasf.ModEnabled.description": "无需重启游戏,修改并保存后立刻生效"
}

View File

@@ -16,9 +16,8 @@
"icon": "assets/twd-sasf/icon.png",
"environment": "client",
"entrypoints": {
"client": [
"xyz.thewhitedog9487.ServerAddressSpaceFixClient"
]
"client": [ "xyz.thewhitedog9487.ServerAddressSpaceFixClient" ],
"modmenu": [ "xyz.thewhitedog9487.ModMenu" ]
},
"mixins": [
"twd-sasf.mixins.json",
@@ -28,7 +27,7 @@
}
],
"depends": {
"fabricloader": ">=0.14.23",
"fabricloader": ">=0.15.3",
"minecraft": ["1.20","1.20.*"],
"java": ">=17"
},