Ping module

Ping: Minecraft 26.3 cheat module, full source for every implementation (1 client: Nicotine).

1 implementationHUD

Clients with this module

Full module source: 1 implementation

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

NicotineHUDsrc/client/java/nicotine/mod/mods/hud/Ping.javaJava · 69 lines · 2.1 KB
SettingsSource
Ping.javaJava · Minecraft 26.3 · 69 lines · 2.1 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.hud;
2
3
import net.minecraft.ChatFormatting;
4
import net.minecraft.network.protocol.ping.ClientboundPongResponsePacket;
5
import net.minecraft.network.protocol.ping.ServerboundPingRequestPacket;
6
import nicotine.events.ClientLevelTickEvent;
7
import nicotine.events.PacketInEvent;
8
import nicotine.mod.HUDMod;
9
import nicotine.mod.ModCategory;
10
import nicotine.mod.mods.general.HUD;
11
import nicotine.mod.option.DropDownOption;
12
import nicotine.util.EventBus;
13
import nicotine.util.Player;
14
15
import java.util.List;
16
17
import static nicotine.util.Common.mc;
18
19
public class Ping extends HUDMod {
20
    private int tick = 0;
21
    private int pingVal = 0;
22
23
    private final DropDownOption source = new DropDownOption(
24
            "Source",
25
            new String[]{"Tab", "QueryPingPacket"}
26
    );
27
28
    public Ping() {
29
        super(ModCategory.HUD, "Ping");
30
        this.anchor = HUDMod.Anchor.TopLeft;
31
        this.addOptions(source);
32
    }
33
34
    @Override
35
    protected void init() {
36
        EventBus.register(ClientLevelTickEvent.class, event -> {
37
            if (!this.enabled || mc.hasSingleplayerServer())
38
                return true;
39
40
            if (source.value.equals("Tab"))
41
                pingVal = Player.getPing(mc.player);
42
            else {
43
                if (tick == 120) {
44
                    mc.getConnection().send(new ServerboundPingRequestPacket(System.nanoTime()));
45
                    tick = 0;
46
                }
47
48
                tick++;
49
            }
50
51
            String pingText = String.format("ping %s%s %dms", ChatFormatting.WHITE, HUD.separator.value, pingVal);
52
            this.texts = List.of(pingText);
53
54
            return true;
55
        });
56
57
        EventBus.register(PacketInEvent.class, event -> {
58
            if (!this.enabled || source.value.equals("Tab") || mc.hasSingleplayerServer())
59
                return true;
60
61
            if (event.packet instanceof ClientboundPongResponsePacket ClientboundPongResponsePacket && mc.player != null) {
62
                pingVal = (int)((System.nanoTime() - ClientboundPongResponsePacket.time()) / 1E6);
63
            }
64
65
            return true;
66
        });
67
    }
68
}
69