Bstn1802 / AutoReconnect

Minecraft fabric mod which automatically reconnects the client to the last known server after disconnection
https://www.curseforge.com/minecraft/mc-mods/autoreconnect
GNU Lesser General Public License v3.0
28 stars 36 forks source link

1.19.4 finish code for connect #52

Closed Meense closed 1 year ago

Meense commented 1 year ago
MinecraftClient client = MinecraftClient.getInstance();
Screen screen = client.currentScreen;
InetSocketAddress inetSocketAddress;

try {
Optional<InetSocketAddress> optional = AllowedAddressResolver.DEFAULT.resolve(address).map(Address::getInetSocketAddress);

inetSocketAddress = optional.get();
ClientConnection connection = ClientConnection.connect(inetSocketAddress, client.options.shouldUseNativeTransport());
connection.setPacketListener(new ClientLoginNetworkHandler(connection, client, info, screen, false, null, CurrentClass::setStatus));
connection.send(new HandshakeC2SPacket(inetSocketAddress.getHostName(), inetSocketAddress.getPort(), NetworkState.LOGIN));
connection.send(new LoginHelloC2SPacket(client.getSession().getUsername(), Optional.ofNullable(client.getSession().getUuidOrNull())));
} catch (Exception var6) {
}

private static void setStatus(Text status) {
      LOGGER.info("Reconnected to server: " + status.getString());
}

private static ServerInfo info =  new ServerInfo("name", "ip", false);
private static ServerAddress address = ServerAddress.parse("ip");
Meense commented 1 year ago

i hope this helps

Bstn1802 commented 1 year ago

I'm not sure where this should come in or what it is trying to fix, please elaborate if it's still relevant. Closing this, as I'm focusing on the 1.20 release right now. If a version for 1.19.3/4 is still needed, please reopen issue #48 or reopen this if you want to explain what issue you were trying to fix here.