1+ package io .github .markassk .fishonmcextras .mixin ;
2+
3+ import net .minecraft .client .MinecraftClient ;
4+ import net .minecraft .client .gui .screen .ReconfiguringScreen ;
5+ import net .minecraft .client .gui .screen .Screen ;
6+ import net .minecraft .client .gui .screen .multiplayer .ConnectScreen ;
7+ import net .minecraft .client .gui .widget .ButtonWidget ;
8+ import net .minecraft .client .network .ServerAddress ;
9+ import net .minecraft .client .network .ServerInfo ;
10+ import net .minecraft .text .Text ;
11+ import org .spongepowered .asm .mixin .Mixin ;
12+ import org .spongepowered .asm .mixin .Unique ;
13+ import org .spongepowered .asm .mixin .injection .At ;
14+ import org .spongepowered .asm .mixin .injection .Inject ;
15+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
16+
17+ @ Mixin (ReconfiguringScreen .class )
18+ public abstract class ReconfiguringMixin extends Screen {
19+
20+ @ Unique private boolean buttonAdded = false ;
21+
22+ protected ReconfiguringMixin (Text title ) {
23+ super (title );
24+ }
25+
26+ @ Inject (method = "init" , at = @ At ("TAIL" ))
27+ private void addForceReconnectButton (CallbackInfo ci ) {
28+ if (buttonAdded ) return ;
29+
30+ MinecraftClient client = MinecraftClient .getInstance ();
31+ ServerInfo last = client .getCurrentServerEntry ();
32+ if (last == null ) return ;
33+
34+ ButtonWidget reconnectButton = ButtonWidget .builder (Text .of ("Force Reconnect" ), btn -> {
35+ // Kill current stuck connection
36+ if (client .getNetworkHandler () != null ) {
37+ client .getNetworkHandler ().getConnection ().disconnect (Text .of ("Force reconnect" ));
38+ }
39+
40+ // Reconnect instantly
41+ ServerAddress addr =
42+ ServerAddress .parse (last .address );
43+
44+ ConnectScreen .connect (
45+ this , client , addr , last , false , null
46+ );
47+ }).dimensions (this .width / 2 - 100 , this .height - 40 , 200 , 20 ).build ();
48+
49+ this .addDrawableChild (reconnectButton );
50+ buttonAdded = true ;
51+ }
52+ }
0 commit comments