Initial commit

This commit is contained in:
2023-10-18 15:48:48 +08:00
commit 888e2d60cc
25 changed files with 766 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
package xyz.thewhitedog9487;
import net.fabricmc.api.ClientModInitializer;
public class ServerAddressSpaceFixClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
}
}

View File

@@ -0,0 +1,15 @@
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

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

View File

@@ -0,0 +1,15 @@
package xyz.thewhitedog9487.mixin.client;
import net.minecraft.client.MinecraftClient;
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;
@Mixin(MinecraftClient.class)
public class ExampleClientMixin {
@Inject(at = @At("HEAD"), method = "run")
private void run(CallbackInfo info) {
// This code is injected into the start of MinecraftClient.run()V
}
}

View File

@@ -0,0 +1,22 @@
package xyz.thewhitedog9487.mixin.client;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
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;
@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();}
}

View File

@@ -0,0 +1,22 @@
package xyz.thewhitedog9487.mixin.client;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
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;
@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();}
}

View File

@@ -0,0 +1,14 @@
{
"required": true,
"package": "xyz.thewhitedog9487.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"AddServerScreenAccessor",
"ExampleClientMixin",
"MixinAddServerScreen",
"MixinDirectConnectScreen"
],
"injectors": {
"defaultRequire": 1
}
}

View File

@@ -0,0 +1,22 @@
package xyz.thewhitedog9487;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 Logger LOGGER = LoggerFactory.getLogger("twd-sasf");
@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
LOGGER.info("Hello Fabric world!");
}
}

View File

@@ -0,0 +1,15 @@
package xyz.thewhitedog9487.mixin;
import net.minecraft.server.MinecraftServer;
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;
@Mixin(MinecraftServer.class)
public class ExampleMixin {
@Inject(at = @At("HEAD"), method = "loadWorld")
private void init(CallbackInfo info) {
// This code is injected into the start of MinecraftServer.loadWorld()V
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 B

View File

@@ -0,0 +1,6 @@
{
"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",
"twd-sasf.bilibili": "Bilibili",
"twd-sasf.blog": "Blog"
}

View File

@@ -0,0 +1,6 @@
{
"modmenu.nameTranslation.twd-sasf": "服务器地址首尾空格修复",
"modmenu.descriptionTranslation.twd-sasf": "修复添加服务器或直接连接时服务器地址首尾包含空格导致的“未知的主机”Bug",
"twd-sasf.bilibili": "哔哩哔哩主页",
"twd-sasf.blog": "TheWhiteDog9487的博客"
}

View File

@@ -0,0 +1,47 @@
{
"schemaVersion": 1,
"id": "twd-sasf",
"version": "${version}",
"name": "ServerAddressSpaceFix",
"description": "服务器地址首尾空格修复",
"authors": [
"TheWhiteDog9487"
],
"contact": {
"homepage": "https://www.thewhitedog9487.xyz/",
"sources": "https://github.com/TheWhiteDog9487/ServerAddressSpaceFix",
"issues": "https://github.com/TheWhiteDog9487/ServerAddressSpaceFix/issues"
},
"license": "WTFPL",
"icon": "assets/twd-sasf/icon.png",
"environment": "client",
"entrypoints": {
"main": [
"xyz.thewhitedog9487.ServerAddressSpaceFix"
],
"client": [
"xyz.thewhitedog9487.ServerAddressSpaceFixClient"
]
},
"mixins": [
"twd-sasf.mixins.json",
{
"config": "twd-sasf.client.mixins.json",
"environment": "client"
}
],
"depends": {
"fabricloader": ">=0.14.23",
"minecraft": "~1.20.1",
"java": ">=17"
},
"suggests": {
"another-mod": "*"
},
"custom": {
"modmenu": {
"links": {
"twd-sasf.bilibili": "https://space.bilibili.com/401746666",
"twd-sasf.blog": "www.thewhitedog9487.xyz"},
"update_checker": true}}
}

View File

@@ -0,0 +1,11 @@
{
"required": true,
"package": "xyz.thewhitedog9487.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ExampleMixin"
],
"injectors": {
"defaultRequire": 1
}
}