时间:2024 10 30
主要内容:
加大剂量,
1. 以前不会对服务器列表中已经保存的服务器地址进行处理,现在只要模组处于启用状态会直接对所有地址进行消除空格替换,确保不留死角。
说人话:未安装或未启用本模组时添加的服务器地址如果有空格,在启用本模组之后会在打开“多人游戏”窗口时被处理掉。
This commit is contained in:
TheWhiteDog9487 2024-10-30 17:33:24 +08:00
parent 7e6b5bea64
commit cb7a0f57e3
6 changed files with 36 additions and 20 deletions

View File

@ -1,12 +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.multiplayer.DirectConnectScreen.class)
public interface DirectConnectScreenAccessor {
@Accessor("addressField")
TextFieldWidget Mixin_GetAddressField();
}

View File

@ -1,14 +1,15 @@
package xyz.thewhitedog9487.mixin.client;
import net.minecraft.client.gui.screen.multiplayer.AddServerScreen;
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.multiplayer.AddServerScreen.class)
@Mixin(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(" ", "");}}
if( Settings.ModEnabled == false ) { return instance.getText(); }
else return instance.getText().replace(" ", "");}}

View File

@ -1,16 +1,23 @@
package xyz.thewhitedog9487.mixin.client;
import net.minecraft.client.gui.screen.multiplayer.DirectConnectScreen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import xyz.thewhitedog9487.Settings;
@Mixin(net.minecraft.client.gui.screen.multiplayer.DirectConnectScreen.class)
@Mixin(DirectConnectScreen.class)
interface DirectConnectScreenAccessor {
@Accessor("addressField")
TextFieldWidget Mixin_GetAddressField();}
@Mixin(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(); }
if( Settings.ModEnabled == false ) { return instance.getText(); }
String trimmedText = instance.getText().replace(" ", "");
((DirectConnectScreenAccessor) this).Mixin_GetAddressField().setText(trimmedText);
return trimmedText;}}

View File

@ -0,0 +1,19 @@
package xyz.thewhitedog9487.mixin.client;
import net.minecraft.client.network.ServerInfo;
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 java.nio.file.Paths;
@Mixin(ServerInfo.class)
public class MixinServerInfo {
@Redirect(method = "<init>", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/network/ServerInfo;address:Ljava/lang/String;"))
private void RemoveSpace_Write(ServerInfo original, String value) {
if( Settings.ModEnabled == false ) {
original.address = value;
return; }
else { original.address = value.replace(" ", ""); } }}

View File

@ -1,11 +1,12 @@
{
"required": true,
"package": "xyz.thewhitedog9487.mixin.client",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"client": [
"DirectConnectScreenAccessor",
"MixinAddServerScreen",
"MixinDirectConnectScreen"
"MixinDirectConnectScreen",
"MixinServerInfo"
],
"injectors": {
"defaultRequire": 1

View File

@ -1,7 +1,7 @@
{
"required": true,
"package": "xyz.thewhitedog9487.mixin",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"mixins": [],
"injectors": {
"defaultRequire": 1