This commit is contained in:
kirillsaint 2023-07-27 14:20:33 +06:00
parent 655c37daa8
commit fba96fa175
4 changed files with 21 additions and 46 deletions

View File

@ -6,12 +6,9 @@ import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiScreenServerList;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.resources.I18n;
import net.silentclient.client.Client;
import net.silentclient.client.mixin.accessors.GuiMultiplayerAccessor;
import net.silentclient.client.utils.ClientUtils;
import net.silentclient.client.mixin.ducks.GuiMultiplayerExt;
import java.io.IOException;
import java.lang.reflect.Field;
public class GuiMultiplayerInGame extends GuiMultiplayer {
@ -26,17 +23,9 @@ public class GuiMultiplayerInGame extends GuiMultiplayer {
}
if(button.id == 4) {
((GuiMultiplayerAccessor) this).silent$setDirectConnect(true);
try {
Class<?> clazz = this.getClass();
Object cc = clazz.newInstance();
Field f1 = cc.getClass().getSuperclass().getDeclaredField(ClientUtils.isDevelopment() ? "selectedServer" : "z");
f1.setAccessible(true);
f1.set(cc, new ServerData(I18n.format("selectServer.defaultName"), "", false));
this.mc.displayGuiScreen(new GuiScreenServerList(this, (ServerData) f1.get(cc)));
} catch (Exception err) {
Client.logger.catching(err);
}
((GuiMultiplayerExt) this).silent$setDirectConnect(true);
((GuiMultiplayerExt) this).silent$setSelectedServer(new ServerData(I18n.format("selectServer.defaultName"), "", false));
this.mc.displayGuiScreen(new GuiScreenServerList(this, new ServerData(I18n.format("selectServer.defaultName"), "", false)));
}
super.actionPerformed(button);
@ -53,15 +42,7 @@ public class GuiMultiplayerInGame extends GuiMultiplayer {
this.mc.theWorld.sendQuittingDisconnectingPacket();
this.mc.loadWorld(null);
this.mc.displayGuiScreen(null);
try {
Class<?> clazz = this.getClass();
Object cc = clazz.newInstance();
Field f1 = cc.getClass().getSuperclass().getDeclaredField(ClientUtils.isDevelopment() ? "parentScreen" : "g");
f1.setAccessible(true);
f1.set(cc, null);
} catch (Exception err) {
Client.logger.catching(err);
}
((GuiMultiplayerExt) this).silent$setParentScreen(null);
}
}

View File

@ -1,12 +0,0 @@
package net.silentclient.client.mixin.accessors;
import net.minecraft.client.multiplayer.ServerData;
import net.silentclient.client.mixin.wrappers.GuiScreenWrapper;
import net.silentclient.client.mixin.wrappers.ServerDataWrapper;
public interface GuiMultiplayerAccessor {
void silent$setParentScreen(GuiScreenWrapper a);
void silent$setDirectConnect(boolean a);
void silent$setSelectedServer(ServerDataWrapper a);
ServerDataWrapper silent$getSelectedServer();
}

View File

@ -0,0 +1,8 @@
package net.silentclient.client.mixin.ducks;
public interface GuiMultiplayerExt {
void silent$setParentScreen(Object a);
void silent$setDirectConnect(boolean a);
void silent$setSelectedServer(Object a);
Object silent$getSelectedServer();
}

View File

@ -4,15 +4,13 @@ import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.ServerData;
import net.silentclient.client.gui.minecraft.GuiConnecting;
import net.silentclient.client.mixin.accessors.GuiMultiplayerAccessor;
import net.silentclient.client.mixin.wrappers.GuiScreenWrapper;
import net.silentclient.client.mixin.wrappers.ServerDataWrapper;
import net.silentclient.client.mixin.ducks.GuiMultiplayerExt;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(GuiMultiplayer.class)
public abstract class GuiMultiplayerMixin extends GuiScreen implements GuiMultiplayerAccessor {
public abstract class GuiMultiplayerMixin extends GuiScreen implements GuiMultiplayerExt {
@Shadow private GuiScreen parentScreen;
@Shadow private boolean directConnect;
@ -28,12 +26,12 @@ public abstract class GuiMultiplayerMixin extends GuiScreen implements GuiMultip
}
@Override
public void silent$setParentScreen(GuiScreenWrapper a) {
public void silent$setParentScreen(Object a) {
if(a == null) {
this.parentScreen = null;
return;
}
this.parentScreen = a.getScreen();
this.parentScreen = (GuiScreen) a;
}
@Override
@ -42,16 +40,16 @@ public abstract class GuiMultiplayerMixin extends GuiScreen implements GuiMultip
}
@Override
public ServerDataWrapper silent$getSelectedServer() {
return new ServerDataWrapper(selectedServer);
public Object silent$getSelectedServer() {
return selectedServer;
}
@Override
public void silent$setSelectedServer(ServerDataWrapper a) {
public void silent$setSelectedServer(Object a) {
if(a == null) {
this.selectedServer = null;
return;
}
this.selectedServer = a.getServerData();
this.selectedServer = (ServerData) a;
}
}