mirror of
https://github.com/TheWhiteDog9487/ServerAddressSpaceFix.git
synced 2025-09-15 23:16:57 +00:00
Initial commit
This commit is contained in:
@@ -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.
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
@@ -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();
|
||||
}
|
@@ -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
|
||||
}
|
||||
}
|
@@ -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();}
|
||||
|
||||
}
|
@@ -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();}
|
||||
|
||||
}
|
14
src/client/resources/twd-sasf.client.mixins.json
Normal file
14
src/client/resources/twd-sasf.client.mixins.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "xyz.thewhitedog9487.mixin.client",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
"AddServerScreenAccessor",
|
||||
"ExampleClientMixin",
|
||||
"MixinAddServerScreen",
|
||||
"MixinDirectConnectScreen"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
22
src/main/java/xyz/thewhitedog9487/ServerAddressSpaceFix.java
Normal file
22
src/main/java/xyz/thewhitedog9487/ServerAddressSpaceFix.java
Normal 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!");
|
||||
}
|
||||
}
|
15
src/main/java/xyz/thewhitedog9487/mixin/ExampleMixin.java
Normal file
15
src/main/java/xyz/thewhitedog9487/mixin/ExampleMixin.java
Normal 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
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/twd-sasf/icon.png
Normal file
BIN
src/main/resources/assets/twd-sasf/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 453 B |
6
src/main/resources/assets/twd-sasf/lang/en_us.json
Normal file
6
src/main/resources/assets/twd-sasf/lang/en_us.json
Normal 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"
|
||||
}
|
6
src/main/resources/assets/twd-sasf/lang/zh_cn.json
Normal file
6
src/main/resources/assets/twd-sasf/lang/zh_cn.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"modmenu.nameTranslation.twd-sasf": "服务器地址首尾空格修复",
|
||||
"modmenu.descriptionTranslation.twd-sasf": "修复添加服务器或直接连接时,服务器地址首尾包含空格导致的“未知的主机”Bug",
|
||||
"twd-sasf.bilibili": "哔哩哔哩主页",
|
||||
"twd-sasf.blog": "TheWhiteDog9487的博客"
|
||||
}
|
47
src/main/resources/fabric.mod.json
Normal file
47
src/main/resources/fabric.mod.json
Normal 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}}
|
||||
}
|
11
src/main/resources/twd-sasf.mixins.json
Normal file
11
src/main/resources/twd-sasf.mixins.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "xyz.thewhitedog9487.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user