From dbb2019bf3724c6edd092323be4f7758a58b8b74 Mon Sep 17 00:00:00 2001 From: JustAlittleWolf Date: Wed, 25 Oct 2023 10:59:50 +0200 Subject: [PATCH] Fix refresh issue - Fix the refresh issue by replacing @Inject with @Replace. This immediately trims the value of .getText() - Remove unused entrypoints and mixins --- .../mixin/client/MixinAddServerScreen.java | 22 ++++++----------- .../client/MixinDirectConnectScreen.java | 24 +++++++------------ .../resources/twd-sasf.client.mixins.json | 3 +-- src/main/resources/fabric.mod.json | 3 --- src/main/resources/twd-sasf.mixins.json | 4 +--- 5 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/client/java/xyz/thewhitedog9487/mixin/client/MixinAddServerScreen.java b/src/client/java/xyz/thewhitedog9487/mixin/client/MixinAddServerScreen.java index d9b1c67..89d5a25 100644 --- a/src/client/java/xyz/thewhitedog9487/mixin/client/MixinAddServerScreen.java +++ b/src/client/java/xyz/thewhitedog9487/mixin/client/MixinAddServerScreen.java @@ -1,22 +1,14 @@ package xyz.thewhitedog9487.mixin.client; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; +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.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(net.minecraft.client.gui.screen.AddServerScreen.class) -public class MixinAddServerScreen extends Screen { - protected MixinAddServerScreen(Text title) { - super(title);} - - @Inject(method = "addAndClose()V", at = @At("RETURN")) - private void addAndClose(CallbackInfo ci){ - var Server = ((AddServerScreenAccessor) this).Mixin_GetServer(); - var Address = ((AddServerScreenAccessor) this).Mixin_GetAddressField().getText(); - // this.server.address = this.addressField.getText(); - Server.address = Address.trim();} - +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) { + return instance.getText().trim(); + } } diff --git a/src/client/java/xyz/thewhitedog9487/mixin/client/MixinDirectConnectScreen.java b/src/client/java/xyz/thewhitedog9487/mixin/client/MixinDirectConnectScreen.java index 0292391..973a90f 100644 --- a/src/client/java/xyz/thewhitedog9487/mixin/client/MixinDirectConnectScreen.java +++ b/src/client/java/xyz/thewhitedog9487/mixin/client/MixinDirectConnectScreen.java @@ -1,22 +1,16 @@ package xyz.thewhitedog9487.mixin.client; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; +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.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(net.minecraft.client.gui.screen.DirectConnectScreen.class) -public class MixinDirectConnectScreen extends Screen { - protected MixinDirectConnectScreen(Text title) { - super(title);} - - @Inject(method = "saveAndClose()V", at = @At("RETURN")) - private void addAndClose(CallbackInfo ci){ - var ServerEntry = ((DirectConnectScreenAccessor) this).Mixin_GetServerEntry(); - var Address = ((DirectConnectScreenAccessor) this).Mixin_GetAddressField().getText(); - // this.serverEntry.address = this.addressField.getText(); - ServerEntry.address = Address.trim();} - +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) { + String trimmedText = instance.getText().trim(); + ((DirectConnectScreenAccessor) this).Mixin_GetAddressField().setText(trimmedText); + return trimmedText; + } } diff --git a/src/client/resources/twd-sasf.client.mixins.json b/src/client/resources/twd-sasf.client.mixins.json index f0e6437..538a0d2 100644 --- a/src/client/resources/twd-sasf.client.mixins.json +++ b/src/client/resources/twd-sasf.client.mixins.json @@ -3,8 +3,7 @@ "package": "xyz.thewhitedog9487.mixin.client", "compatibilityLevel": "JAVA_17", "client": [ - "AddServerScreenAccessor", - "ExampleClientMixin", + "DirectConnectScreenAccessor", "MixinAddServerScreen", "MixinDirectConnectScreen" ], diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b90d2f3..a03f447 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -16,9 +16,6 @@ "icon": "assets/twd-sasf/icon.png", "environment": "client", "entrypoints": { - "main": [ - "xyz.thewhitedog9487.ServerAddressSpaceFix" - ], "client": [ "xyz.thewhitedog9487.ServerAddressSpaceFixClient" ] diff --git a/src/main/resources/twd-sasf.mixins.json b/src/main/resources/twd-sasf.mixins.json index cdfb1a7..5c46f72 100644 --- a/src/main/resources/twd-sasf.mixins.json +++ b/src/main/resources/twd-sasf.mixins.json @@ -2,9 +2,7 @@ "required": true, "package": "xyz.thewhitedog9487.mixin", "compatibilityLevel": "JAVA_17", - "mixins": [ - "ExampleMixin" - ], + "mixins": [], "injectors": { "defaultRequire": 1 }