AutoReconnect module

AutoReconnect: Minecraft 26.3 cheat module, full source for every implementation (2 clients: OfflineClient, Nicotine).

2 implementationsMISCMisc

Clients with this module

Full module source: 2 implementations

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

OfflineClientMISCsrc/main/java/com/jellypudding/offlineclient/modules/misc/AutoReconnect.javaJava · 102 lines · 3.1 KB

Rejoins the server after you get disconnected.

SettingsDelayButtons
AutoReconnect.javaJava · Minecraft 26.2 · 102 lines · 3.1 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.misc;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.ClientTickEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.setting.BoolSetting;
8
import com.jellypudding.offlineclient.setting.NumberSetting;
9
import net.minecraft.client.gui.screens.ConnectScreen;
10
import net.minecraft.client.gui.screens.DisconnectedScreen;
11
import net.minecraft.client.multiplayer.ServerData;
12
import net.minecraft.client.multiplayer.resolver.ServerAddress;
13
14
public final class AutoReconnect extends Module {
15
16
    private final NumberSetting delay = new NumberSetting("Delay",
17
        "Seconds to wait before reconnecting.", 5, 0, 60, 0.1, "s").min(0).max(600);
18
    private final BoolSetting buttons = new BoolSetting("Buttons",
19
        "Adds a reconnect button and a switch to the disconnected screen.", true);
20
21
    // The last server joined. Kept even whilst the module is off. Switched on
22
    // after a disconnect it still knows where to go.
23
    private static ServerData lastServer;
24
25
    private int countdown = -1;
26
27
    public AutoReconnect() {
28
        super("AutoReconnect", "Rejoins the server after you get disconnected.", Category.MISC);
29
        addSettings(delay, buttons);
30
        searchTags("rejoin", "reconnect");
31
    }
32
33
    // Called from the connect screen whatever the module is doing.
34
    public static void remember(ServerData server) {
35
        if (server != null) {
36
            lastServer = server;
37
        }
38
    }
39
40
    public boolean showsButtons() {
41
        return buttons.isOn();
42
    }
43
44
    // Seconds left rounded to one place. Below zero whilst nothing is counting.
45
    public double secondsLeft() {
46
        return countdown < 0 ? -1 : Math.round(countdown / 2f) / 10.0;
47
    }
48
49
    public static boolean canReconnect() {
50
        return lastServer != null;
51
    }
52
53
    public void reconnectNow() {
54
        countdown = -1;
55
        connect();
56
    }
57
58
    // The button on the screen flips the module and starts the wait again.
59
    public void toggleFromScreen() {
60
        countdown = -1;
61
        toggle();
62
    }
63
64
    @Subscribe
65
    private void onClientTick(ClientTickEvent event) {
66
        if (mc.level != null && mc.getCurrentServer() != null) {
67
            remember(mc.getCurrentServer());
68
            countdown = -1;
69
            return;
70
        }
71
72
        if (!(mc.gui.screen() instanceof DisconnectedScreen) || lastServer == null) {
73
            countdown = -1;
74
            return;
75
        }
76
77
        if (countdown == -1) {
78
            countdown = (int) Math.round(delay.getValue() * 20);
79
        }
80
        countdown--;
81
        if (countdown > 0) {
82
            return;
83
        }
84
85
        countdown = -1;
86
        connect();
87
    }
88
89
    private void connect() {
90
        if (lastServer == null || mc.gui.screen() == null) {
91
            return;
92
        }
93
        ConnectScreen.startConnecting(mc.gui.screen(), mc,
94
            ServerAddress.parseString(lastServer.ip), lastServer, false, null);
95
    }
96
97
    @Override
98
    protected void onDisable() {
99
        countdown = -1;
100
    }
101
}
102
NicotineMiscsrc/client/java/nicotine/mod/mods/misc/AutoReconnect.javaJava · 38 lines · 878 B
SettingsDelay
AutoReconnect.javaJava · Minecraft 26.3 · 38 lines · 878 B · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.misc;
2
3
import nicotine.events.DisconnectEvent;
4
import nicotine.mod.Mod;
5
import nicotine.mod.ModCategory;
6
import nicotine.mod.option.SliderOption;
7
import nicotine.screens.clickgui.AutoReconnectScreen;
8
import nicotine.util.EventBus;
9
10
import static nicotine.util.Common.mc;
11
12
public class AutoReconnect extends Mod {
13
14
    private final  SliderOption delay = new SliderOption(
15
            "Delay",
16
            20,
17
            1,
18
            60
19
    );
20
21
    public AutoReconnect() {
22
        super(ModCategory.Misc, "AutoReconnect");
23
        this.addOptions(delay);
24
    }
25
26
    @Override
27
    protected void init() {
28
        EventBus.register(DisconnectEvent.class, event -> {
29
            if (!this.enabled)
30
                return true;
31
32
            mc.gui.setScreen(new AutoReconnectScreen((int)delay.value * 20));
33
            return true;
34
        });
35
36
    }
37
}
38