Skip to content

Commit fbeab41

Browse files
BaitinqAvanatiker
andauthored
Add "Server List" button in the Minecraft ESC GUI (#472)
* 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 :) * Optimize imports Co-authored-by: Constructor <fractalminds@protonmail.com>
1 parent 5d2f7de commit fbeab41

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

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

+21-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.lambda.client.util.Wrapper;
66
import net.minecraft.client.gui.GuiButton;
77
import net.minecraft.client.gui.GuiIngameMenu;
8+
import net.minecraft.client.gui.GuiMultiplayer;
89
import net.minecraft.client.gui.GuiScreen;
910
import org.spongepowered.asm.mixin.Mixin;
1011
import org.spongepowered.asm.mixin.injection.At;
@@ -15,11 +16,26 @@
1516
public class MixinGuiIngameMenu extends GuiScreen {
1617
@Inject(method = "actionPerformed", at = @At("HEAD"), cancellable = true)
1718
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-
}
19+
switch (button.id) {
20+
case 1:
21+
if (AntiDisconnect.INSTANCE.isEnabled()) {
22+
Wrapper.getMinecraft().displayGuiScreen(new LambdaGuiAntiDisconnect());
23+
callbackInfo.cancel();
24+
}
25+
break;
26+
case Integer.MIN_VALUE:
27+
Wrapper.getMinecraft().displayGuiScreen(new GuiMultiplayer(this));
28+
break;
29+
default:
30+
break;
31+
}
32+
}
33+
34+
@Inject(method = "initGui", at = @At("RETURN"))
35+
public void initGui(CallbackInfo ci) {
36+
if (!mc.isSingleplayer()) {
37+
GuiButton openToLanButton = buttonList.remove(4);
38+
buttonList.add(new GuiButton(Integer.MIN_VALUE, openToLanButton.x, openToLanButton.y, openToLanButton.width, openToLanButton.height, "Server List"));
2339
}
2440
}
2541
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.lambda.mixin.gui;
2+
3+
import net.minecraft.client.gui.GuiMultiplayer;
4+
import net.minecraft.client.gui.GuiScreen;
5+
import net.minecraft.client.multiplayer.ServerData;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
10+
11+
@Mixin(GuiMultiplayer.class)
12+
public class MixinGuiMultiplayer extends GuiScreen {
13+
14+
@Inject(method = "connectToServer", at = @At("HEAD"))
15+
public void connectToServer(ServerData serverData, CallbackInfo ci) {
16+
if (mc.getCurrentServerData() != null && mc.world != null) {
17+
mc.world.sendQuittingDisconnectingPacket();
18+
mc.loadWorld(null);
19+
}
20+
}
21+
22+
}

src/main/resources/mixins.lambda.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"gui.MixinGuiIngameMenu",
4848
"gui.MixinGuiInventory",
4949
"gui.MixinGuiMainMenu",
50+
"gui.MixinGuiMultiplayer",
5051
"gui.MixinGuiNewChat",
5152
"gui.MixinGuiPlayerTabOverlay",
5253
"gui.MixinGuiScreen",

0 commit comments

Comments
 (0)