时间: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:
TheWhiteDog9487 2024-01-15 14:58:30 +08:00
parent ee6a656041
commit 789ad58006
14 changed files with 83 additions and 35 deletions

View File

@ -16,6 +16,11 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically. // Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html // See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories. // for more information about repositories.
maven {
name 'Xander Maven'
url 'https://maven.isxander.dev/releases'}
maven { url "https://maven.terraformersmc.com/releases/" }
} }
loom { loom {
@ -43,6 +48,9 @@ dependencies {
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
modImplementation "dev.isxander.yacl:yet-another-config-lib-fabric:3.3.1+1.20.4"
// https://maven.isxander.dev/#/releases/dev/isxander/yacl/yet-another-config-lib-fabric
modImplementation "com.terraformersmc:modmenu:9.0.0"
} }
processResources { processResources {

View File

@ -4,17 +4,17 @@ org.gradle.parallel=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
minecraft_version=1.20.2 minecraft_version=1.20.4
yarn_mappings=1.20.2+build.4 yarn_mappings=1.20.4+build.3
loader_version=0.14.23 loader_version=0.15.3
# Mod Properties # Mod Properties
mod_version=0.1.3 mod_version=0.1.4
maven_group=xyz.thewhitedog9487 maven_group=xyz.thewhitedog9487
archives_base_name=ServerAddressSpaceFix archives_base_name=ServerAddressSpaceFix
# Dependencies # Dependencies
fabric_version=0.90.0+1.20.2 fabric_version=0.93.1+1.20.4
loom_libraries_base=https://bmclapi2.bangbang93.com/maven/ loom_libraries_base=https://bmclapi2.bangbang93.com/maven/
loom_resources_base=https://bmclapi2.bangbang93.com/assets/ loom_resources_base=https://bmclapi2.bangbang93.com/assets/

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; package xyz.thewhitedog9487;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ServerAddressSpaceFixClient implements ClientModInitializer { public class ServerAddressSpaceFixClient implements ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("twd-sasf");
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering. // 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.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor; 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 { public interface DirectConnectScreenAccessor {
@Accessor("serverEntry")
ServerInfo Mixin_GetServerEntry();
@Accessor("addressField") @Accessor("addressField")
TextFieldWidget Mixin_GetAddressField(); 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.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; 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 { public class MixinAddServerScreen {
@Redirect(method = "addAndClose", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;getText()Ljava/lang/String;", ordinal = 1)) @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) { private String trimGetText(TextFieldWidget instance) {
if( !Settings.ModEnabled ) { return instance.getText(); }
return instance.getText().replace(" ", "");}} 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.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; 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 { public class MixinDirectConnectScreen {
@Redirect(method = "saveAndClose", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;getText()Ljava/lang/String;")) @Redirect(method = "saveAndClose", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;getText()Ljava/lang/String;"))
private String trimGetText(TextFieldWidget instance) { private String trimGetText(TextFieldWidget instance) {
if( !Settings.ModEnabled ) { return instance.getText(); }
String trimmedText = instance.getText().replace(" ", ""); String trimmedText = instance.getText().replace(" ", "");
((DirectConnectScreenAccessor) this).Mixin_GetAddressField().setText(trimmedText); ((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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@Deprecated
public class ServerAddressSpaceFix implements ModInitializer { public class ServerAddressSpaceFix implements ModInitializer {
// This logger is used to write text to the console and the log file. // 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. // 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.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.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.nameTranslation.twd-sasf": "服务器地址首尾空格修复",
"modmenu.descriptionTranslation.twd-sasf": "修复添加服务器或直接连接时服务器地址首尾包含空格导致的“未知的主机”Bug", "modmenu.descriptionTranslation.twd-sasf": "修复添加服务器或直接连接时服务器地址首尾包含空格导致的“未知的主机”Bug\n提示如果需要使用配置菜单请安装YetAnotherConfigLib模组",
"twd-sasf.bilibili": "哔哩哔哩主页", "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", "icon": "assets/twd-sasf/icon.png",
"environment": "client", "environment": "client",
"entrypoints": { "entrypoints": {
"client": [ "client": [ "xyz.thewhitedog9487.ServerAddressSpaceFixClient" ],
"xyz.thewhitedog9487.ServerAddressSpaceFixClient" "modmenu": [ "xyz.thewhitedog9487.ModMenu" ]
]
}, },
"mixins": [ "mixins": [
"twd-sasf.mixins.json", "twd-sasf.mixins.json",
@ -28,7 +27,7 @@
} }
], ],
"depends": { "depends": {
"fabricloader": ">=0.14.23", "fabricloader": ">=0.15.3",
"minecraft": ["1.20","1.20.*"], "minecraft": ["1.20","1.20.*"],
"java": ">=17" "java": ">=17"
}, },

View File

@ -1,3 +1,14 @@
# 0.1.4
时间2024 01 15
主要内容:
1. 更新开发环境到1.20.4
2. 更新Fabric Loader和Fabric API的版本
3. 使用YetAnotherConfigLib和ModMenu为模组创建一个配置屏幕
4. 配置选项中增加是否启用模组功能的开关
5. 移除自使用Redirect注解之后不再被需要的接口和方法
6. 在客户端侧的初始化方法中,让日志记录器打印一段日志,方便调试和除错
7. 更新Mixin注入的类的路径这东西居然更新了
# 0.1.3 # 0.1.3
时间2023 10 28 时间2023 10 28
主要内容这玩意好像不具备特定版本兼容性啊那我直接改兼容性列表以大版本作为兼容性边界得了1.20全版本通用一个分支和同一个输出。 主要内容这玩意好像不具备特定版本兼容性啊那我直接改兼容性列表以大版本作为兼容性边界得了1.20全版本通用一个分支和同一个输出。