Retry Button in Gui Disconnected

This commit is contained in:
kirillsaint 2023-09-30 14:56:02 +06:00
parent 8318d25350
commit 7f0273016d
5 changed files with 43 additions and 36 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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)
{

View File

@ -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 = "<init>", 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 <E> 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();
}
}
}

View File

@ -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;
}
}
}