Skip to content

Commit 18a4e6f

Browse files
committed
Add "Server List" button in the Minecraft pause GUI
This patch adds a new "Server List" button replacing the disabled "Open To Lan" button in the multiplayer pause menu :)
1 parent 414581b commit 18a4e6f

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/main/java/com/lambda/mixin/MixinMinecraft.java

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.minecraft.client.gui.GuiScreen;
1616
import net.minecraft.client.gui.inventory.GuiContainer;
1717
import net.minecraft.client.multiplayer.PlayerControllerMP;
18+
import net.minecraft.client.multiplayer.ServerData;
1819
import net.minecraft.client.multiplayer.WorldClient;
1920
import net.minecraft.client.settings.GameSettings;
2021
import net.minecraft.init.Items;
@@ -39,6 +40,7 @@ public abstract class MixinMinecraft {
3940
@Shadow public GuiScreen currentScreen;
4041
@Shadow public GameSettings gameSettings;
4142
@Shadow public PlayerControllerMP playerController;
43+
@Shadow private ServerData currentServerData;
4244
@Shadow private int fpsCounter;
4345
private boolean handActive = false;
4446
private boolean isHittingBlock = false;
@@ -173,4 +175,15 @@ public void setIngameFocus(CallbackInfo info) {
173175
}
174176
}
175177

178+
@Inject(method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", at = @At("HEAD"))
179+
public void loadWorld(WorldClient worldClientIn, String loadingMessage, CallbackInfo info) {
180+
// NOTE: We do this instead of hooking the GuiConnecting constructor because you can't hook into the HEAD of a
181+
// constructor, which is what would be required as we need to have access to the previous world in order
182+
// to disconnect from it :)
183+
// If connecting to a server while being in a server
184+
if (this.world != null && this.currentServerData != null) {
185+
this.world.sendQuittingDisconnectingPacket();
186+
}
187+
}
188+
176189
}

src/main/java/com/lambda/mixin/gui/MixinGuiIngameMenu.java

+21-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import com.lambda.client.gui.mc.LambdaGuiAntiDisconnect;
44
import com.lambda.client.module.modules.misc.AntiDisconnect;
55
import com.lambda.client.util.Wrapper;
6-
import net.minecraft.client.gui.GuiButton;
7-
import net.minecraft.client.gui.GuiIngameMenu;
8-
import net.minecraft.client.gui.GuiScreen;
6+
import net.minecraft.client.gui.*;
97
import org.spongepowered.asm.mixin.Mixin;
108
import org.spongepowered.asm.mixin.injection.At;
119
import org.spongepowered.asm.mixin.injection.Inject;
@@ -15,11 +13,26 @@
1513
public class MixinGuiIngameMenu extends GuiScreen {
1614
@Inject(method = "actionPerformed", at = @At("HEAD"), cancellable = true)
1715
public void actionPerformed(GuiButton button, CallbackInfo callbackInfo) {
18-
if (button.id == 1) {
19-
if (AntiDisconnect.INSTANCE.isEnabled()) {
20-
Wrapper.getMinecraft().displayGuiScreen(new LambdaGuiAntiDisconnect());
21-
callbackInfo.cancel();
22-
}
16+
switch (button.id) {
17+
case 1:
18+
if (AntiDisconnect.INSTANCE.isEnabled()) {
19+
Wrapper.getMinecraft().displayGuiScreen(new LambdaGuiAntiDisconnect());
20+
callbackInfo.cancel();
21+
}
22+
break;
23+
case Integer.MIN_VALUE:
24+
Wrapper.getMinecraft().displayGuiScreen(new GuiMultiplayer(this));
25+
break;
26+
default:
27+
break;
28+
}
29+
}
30+
31+
@Inject(method = "initGui", at = @At("RETURN"))
32+
public void initGui(CallbackInfo ci) {
33+
if (!mc.isSingleplayer()) {
34+
GuiButton openToLanButton = buttonList.remove(4);
35+
buttonList.add(new GuiButton(Integer.MIN_VALUE, openToLanButton.x, openToLanButton.y, openToLanButton.width, openToLanButton.height, "Server List"));
2336
}
2437
}
2538
}

0 commit comments

Comments
 (0)