diff --git a/src/main/java/net/silentclient/client/gui/GuiMultiplayerInGame.java b/src/main/java/net/silentclient/client/gui/GuiMultiplayerInGame.java index 81e0478..ffcb6c3 100644 --- a/src/main/java/net/silentclient/client/gui/GuiMultiplayerInGame.java +++ b/src/main/java/net/silentclient/client/gui/GuiMultiplayerInGame.java @@ -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); } } diff --git a/src/main/java/net/silentclient/client/mixin/accessors/GuiMultiplayerAccessor.java b/src/main/java/net/silentclient/client/mixin/accessors/GuiMultiplayerAccessor.java deleted file mode 100644 index 5d1577c..0000000 --- a/src/main/java/net/silentclient/client/mixin/accessors/GuiMultiplayerAccessor.java +++ /dev/null @@ -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(); -} diff --git a/src/main/java/net/silentclient/client/mixin/ducks/GuiMultiplayerExt.java b/src/main/java/net/silentclient/client/mixin/ducks/GuiMultiplayerExt.java new file mode 100644 index 0000000..21ed9a1 --- /dev/null +++ b/src/main/java/net/silentclient/client/mixin/ducks/GuiMultiplayerExt.java @@ -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(); +} diff --git a/src/main/java/net/silentclient/client/mixin/mixins/GuiMultiplayerMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/GuiMultiplayerMixin.java index 996bae8..9ea9d62 100644 --- a/src/main/java/net/silentclient/client/mixin/mixins/GuiMultiplayerMixin.java +++ b/src/main/java/net/silentclient/client/mixin/mixins/GuiMultiplayerMixin.java @@ -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; } }