diff --git a/src/main/java/net/silentclient/client/Client.java b/src/main/java/net/silentclient/client/Client.java index 992c299..b9677b2 100644 --- a/src/main/java/net/silentclient/client/Client.java +++ b/src/main/java/net/silentclient/client/Client.java @@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.resources.data.IMetadataSerializer; import net.minecraft.util.ResourceLocation; import net.silentclient.client.config.ConfigManager; @@ -91,6 +92,7 @@ public class Client { private GlobalSettings globalSettings; private File globalSettingsFile; private AccountManager accountManager; + public ServerData lastServerData; public static void memoryDebug(String paramString) { LogManager.getLogger().info("-- Start Memory Debug -- " + paramString); @@ -500,8 +502,9 @@ public class Client { playersCount = 0; nextPing = 10; this.updateUserInformation(); - Client.logger.info("Update Connection Server: " + event.getIp()); - silentSocket.getSocket().emit("update_information", event.getIp()); + Client.logger.info("Update Connection Server: " + event.getServerData().serverIP); + silentSocket.getSocket().emit("update_information", event.getServerData().serverIP); + lastServerData = event.getServerData(); } @EventTarget diff --git a/src/main/java/net/silentclient/client/event/impl/ConnectToServerEvent.java b/src/main/java/net/silentclient/client/event/impl/ConnectToServerEvent.java index 3e0020d..011e951 100644 --- a/src/main/java/net/silentclient/client/event/impl/ConnectToServerEvent.java +++ b/src/main/java/net/silentclient/client/event/impl/ConnectToServerEvent.java @@ -1,16 +1,17 @@ package net.silentclient.client.event.impl; +import net.minecraft.client.multiplayer.ServerData; import net.silentclient.client.event.Event; public class ConnectToServerEvent extends Event { - private final String ip; + private final ServerData serverData; - public ConnectToServerEvent(String ip) { - this.ip = ip; + public ConnectToServerEvent(ServerData serverData) { + this.serverData = serverData; } - public String getIp() { - return ip; + public ServerData getServerData() { + return serverData; } } diff --git a/src/main/java/net/silentclient/client/gui/minecraft/GuiConnecting.java b/src/main/java/net/silentclient/client/gui/minecraft/GuiConnecting.java index 2e983a4..c58526c 100644 --- a/src/main/java/net/silentclient/client/gui/minecraft/GuiConnecting.java +++ b/src/main/java/net/silentclient/client/gui/minecraft/GuiConnecting.java @@ -87,7 +87,7 @@ public class GuiConnecting extends SilentScreen GuiConnecting.this.networkManager.setNetHandler(new NetHandlerLoginClient(GuiConnecting.this.networkManager, GuiConnecting.this.mc, GuiConnecting.this.previousGuiScreen)); GuiConnecting.this.networkManager.sendPacket(new C00Handshake(47, ip, port, EnumConnectionState.LOGIN)); GuiConnecting.this.networkManager.sendPacket(new C00PacketLoginStart(GuiConnecting.this.mc.getSession().getProfile())); - new ConnectToServerEvent(serverData.serverIP).call(); + new ConnectToServerEvent(serverData).call(); } catch (UnknownHostException unknownhostexception) { @@ -153,7 +153,7 @@ public class GuiConnecting extends SilentScreen GuiConnecting.this.networkManager.setNetHandler(new NetHandlerLoginClient(GuiConnecting.this.networkManager, GuiConnecting.this.mc, GuiConnecting.this.previousGuiScreen)); GuiConnecting.this.networkManager.sendPacket(new C00Handshake(47, ip, port, EnumConnectionState.LOGIN)); GuiConnecting.this.networkManager.sendPacket(new C00PacketLoginStart(GuiConnecting.this.mc.getSession().getProfile())); - new ConnectToServerEvent(ip).call(); + new ConnectToServerEvent(new ServerData("Minecraft Server", ip, false)).call(); } catch (UnknownHostException unknownhostexception) { diff --git a/src/main/java/net/silentclient/client/mixin/mixins/GuiDisconnectedMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/GuiDisconnectedMixin.java index 491f38b..62a2f80 100644 --- a/src/main/java/net/silentclient/client/mixin/mixins/GuiDisconnectedMixin.java +++ b/src/main/java/net/silentclient/client/mixin/mixins/GuiDisconnectedMixin.java @@ -1,16 +1,27 @@ package net.silentclient.client.mixin.mixins; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiDisconnected; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.resources.I18n; import net.minecraft.util.IChatComponent; +import net.silentclient.client.Client; import net.silentclient.client.event.impl.ServerLeaveEvent; +import net.silentclient.client.gui.minecraft.GuiConnecting; +import net.silentclient.client.gui.multiplayer.SilentMultiplayerGui; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.List; + @Mixin(GuiDisconnected.class) -public class GuiDisconnectedMixin { +public class GuiDisconnectedMixin extends GuiScreen { + @Shadow private int field_175353_i; + @Inject(method = "", at = @At("RETURN")) private void init(GuiScreen screen, String reasonLocalizationKey, @@ -18,4 +29,22 @@ public class GuiDisconnectedMixin { CallbackInfo ci) { new ServerLeaveEvent().call(); } + + @Redirect(method = "initGui", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z")) + public boolean addButtons(List instance, E e) { + if(Client.getInstance().lastServerData != null) { + instance.add(new GuiButton(1, this.width / 2 - 100, this.height / 2 + field_175353_i / 2 + this.fontRendererObj.FONT_HEIGHT, "Retry")); + } + instance.add(new GuiButton(0, this.width / 2 - 100, this.height / 2 + field_175353_i / 2 + this.fontRendererObj.FONT_HEIGHT + (Client.getInstance().lastServerData != null ? 23 : 0), I18n.format("gui.toMenu", new Object[0]))); + + return false; + } + + @Inject(method = "actionPerformed", at = @At("HEAD"), cancellable = true) + public void reconnect(GuiButton button, CallbackInfo ci) { + if(button.id == 1 && Client.getInstance().lastServerData != null) { + this.mc.displayGuiScreen(new GuiConnecting(new SilentMultiplayerGui(Client.getInstance().getMainMenu()), this.mc, Client.getInstance().lastServerData)); + ci.cancel(); + } + } } diff --git a/src/main/java/net/silentclient/client/mixin/optifine/OptiFineFontRendererHandler.java b/src/main/java/net/silentclient/client/mixin/optifine/OptiFineFontRendererHandler.java deleted file mode 100644 index 76150d7..0000000 --- a/src/main/java/net/silentclient/client/mixin/optifine/OptiFineFontRendererHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.silentclient.client.mixin.optifine; - -import net.silentclient.client.Client; -import net.silentclient.client.mixin.SilentClientTweaker; -import net.silentclient.client.mixin.accessors.optifine.ConfigAccessor; -import net.silentclient.client.mixin.accessors.optifine.CustomColorsAccessor; - -public class OptiFineFontRendererHandler { - private static boolean caughtError = false; - public static int getTextColor(int index, int originalColor) { - if (caughtError) return originalColor; - try { - if (!SilentClientTweaker.hasOptifine) { - return originalColor; - } - if (ConfigAccessor.invokeIsCustomColors()) { - return CustomColorsAccessor.invokeGetTextColor(index, originalColor); - } - return originalColor; - } catch (Throwable t) { - caughtError = true; - Client.logger.error("Unable to get OptiFine's Custom Color", t); - return originalColor; - } - } -} \ No newline at end of file