SoundESP module

SoundESP: Minecraft 26.3 cheat module, full source for every implementation (2 clients: MelaHack (ThunderHack fork), Combatant).

2 implementationsRENDERVISUALS

Full module source: 2 implementations

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

MelaHack (ThunderHack fork)RENDERsrc/main/java/thunder/hack/features/modules/render/SoundESP.javaJava · 88 lines · 3.4 KB

Highlights sounds.

SettingsScaleColor
SoundESP.javaJava · Minecraft 26.2 · 88 lines · 3.4 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.render;
2
3
import com.google.common.collect.Lists;
4
import org.joml.Vector4d;
5
import thunder.hack.features.modules.Module;
6
import thunder.hack.gui.font.FontRenderers;
7
import thunder.hack.setting.Setting;
8
import thunder.hack.setting.impl.ColorSetting;
9
import thunder.hack.utility.render.Render2DEngine;
10
import thunder.hack.utility.render.Render3DEngine;
11
12
import java.util.ArrayList;
13
import java.util.List;
14
import net.minecraft.client.gui.GuiGraphicsExtractor;
15
import net.minecraft.world.phys.Vec3;
16
17
public class SoundESP extends Module {
18
    public SoundESP() {
19
        super("SoundESP", Category.RENDER);
20
    }
21
22
    private final Setting<Float> scale = new Setting<>("Scale", 1f, 0.1f, 10f);
23
    private final Setting<ColorSetting> fillColorA = new Setting<>("Color", new ColorSetting(0x80000000));
24
25
    private List<Sound> sounds = new ArrayList<>();
26
27
    public void add(double x, double y, double z, String name) {
28
        sounds.add(new Sound(x, y, z, name.replace("minecraft.block.", "").replace("minecraft.entity", "").replace(".", " ")));
29
    }
30
31
    public void onRender2D(GuiGraphicsExtractor context) {
32
        for (Sound s : Lists.newArrayList(sounds)) {
33
            Vec3 vector = new Vec3(s.x, s.y, s.z);
34
            Vector4d position = null;
35
            vector = Render3DEngine.worldSpaceToScreenSpace(vector);
36
            if (vector.z > 0 && vector.z < 1) {
37
                position = new Vector4d(vector.x, vector.y, vector.z, 0);
38
                position.x = Math.min(vector.x, position.x);
39
                position.y = Math.min(vector.y, position.y);
40
                position.z = Math.max(vector.x, position.z);
41
            }
42
43
            if (position != null) {
44
                double posX = position.x;
45
                double posY = position.y;
46
                double endPosX = position.z;
47
48
                float diff = (float) (endPosX - posX) / 2;
49
                float textWidth = (FontRenderers.sf_bold.getStringWidth(s.name) * 1);
50
                float tagX = (float) ((posX + diff - textWidth / 2) * 1);
51
52
                float alpha = (float) (1f - Math.pow(1f - ((float) s.ticks / 60f), 3f));
53
54
                context.pose().pushMatrix();
55
                context.pose().translate((float) (tagX - 2 + (textWidth + 4) / 2f), (float) ((float) (posY - 13f) + 6.5f));
56
                context.pose().scale(scale.getValue(), scale.getValue());
57
                context.pose().translate((float) (-(tagX - 2 + (textWidth + 4) / 2f)), (float) (-(float) ((posY - 13f) + 6.5f)));
58
                Render2DEngine.drawRect(context.pose(), tagX - 2, (float) (posY - 13f), textWidth + 4, 11, fillColorA.getValue().withAlpha((int) (fillColorA.getValue().getAlpha() * alpha)).getColorObject());
59
                FontRenderers.sf_bold.drawString(context.pose(), s.name, tagX, (float) posY - 10, Render2DEngine.applyOpacity(-1, alpha));
60
                context.pose().popMatrix();
61
            }
62
        }
63
    }
64
65
    @Override
66
    public void onUpdate() {
67
        sounds.removeIf(Sound::shouldRemove);
68
    }
69
70
    private class Sound {
71
        double x, y, z;
72
        String name;
73
        int ticks;
74
75
        public Sound(double x, double y, double z, String name) {
76
            this.x = x;
77
            this.y = y;
78
            this.z = z;
79
            this.name = name;
80
            this.ticks = 60;
81
        }
82
83
        public boolean shouldRemove() {
84
            return ticks-- <= 0;
85
        }
86
    }
87
}
88
CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/SoundESP.javaJava · 216 lines · 7.8 KB
SettingssoundEspNameModesoundEspMaxDistancesoundEspLifetimeMssoundEspColor
SoundESP.javaJava · Minecraft 26.2 · 216 lines · 7.8 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.visuals;
9
10
import net.minecraft.client.Minecraft;
11
import net.minecraft.client.gui.GuiGraphicsExtractor;
12
import net.minecraft.client.resources.language.I18n;
13
import net.minecraft.resources.Identifier;
14
import net.minecraft.world.phys.Vec3;
15
import combatant.client.config.values.ModeValue;
16
import combatant.client.config.values.NumberValue;
17
import combatant.client.config.values.RGBAColorValue;
18
import combatant.client.features.module.HudPhase;
19
import combatant.client.features.module.Module;
20
import combatant.client.features.module.ModuleCategory;
21
import combatant.client.features.module.ModuleInfo;
22
import combatant.client.render.engine.color.RenderColor;
23
import combatant.client.render.engine.renderer.Renderer2D;
24
import combatant.client.render.engine.text.RuntimeTextLayout;
25
import combatant.client.render.engine.text.TextRenderer;
26
import combatant.client.render.helpers.MatteHudStyle;
27
import combatant.client.render.helpers.ScreenProjection;
28
29
import java.util.ArrayList;
30
import java.util.List;
31
32
//todo Description
33
@ModuleInfo(id = "soundesp", displayName = "SoundESP", category = ModuleCategory.VISUALS)
34
public class SoundESP extends Module {
35
    private static final String SETTING_NAME_MODE = "name_mode";
36
    private static final String SETTING_MAX_DISTANCE = "max_distance";
37
    private static final String SETTING_LIFETIME_MS = "lifetime_ms";
38
    private static final String SETTING_COLOR = "color";
39
    private static final double PAD_X = 3.25;
40
    private static final double PAD_Y = 1.15;
41
    private static final double LABEL_Y_OFFSET = 4.25;
42
    private static final double TEXT_SCALE = 0.74;
43
    private static final long FADE_IN_MS = 160L;
44
    private static final long FADE_OUT_MS = 360L;
45
    private final Minecraft mc = Minecraft.getInstance();
46
    private final ModeValue nameMode = modeSetting(
47
            "soundEspNameMode",
48
            SETTING_NAME_MODE,
49
            "Technical",
50
            "Technical",
51
            "Localized"
52
    );
53
    private final NumberValue<Integer> maxDistance =
54
            num("soundEspMaxDistance", SETTING_MAX_DISTANCE, 64, 4, 256);
55
    private final NumberValue<Integer> lifetimeMs =
56
            num("soundEspLifetimeMs", SETTING_LIFETIME_MS, 2000, 200, 10000);
57
    private final RGBAColorValue color =
58
            color("soundEspColor", SETTING_COLOR, "#FFFFFFFF");
59
60
    private final List<SoundPing> sounds = new ArrayList<>();
61
    private final Object soundLock = new Object();
62
63
    private static float computeAlpha(long ageMs, int lifetimeMs) {
64
        float in = FADE_IN_MS <= 0L ? 1.0f : clamp01(ageMs / (float) FADE_IN_MS);
65
        float out = FADE_OUT_MS <= 0L ? 1.0f : clamp01((lifetimeMs - ageMs) / (float) FADE_OUT_MS);
66
        return easeOutCubic(Math.min(in, out));
67
    }
68
69
    private static float easeOutCubic(float t) {
70
        float p = clamp01(t);
71
        float inv = 1.0f - p;
72
        return 1.0f - inv * inv * inv;
73
    }
74
75
    private static float clamp01(float value) {
76
        if (value < 0.0f) return 0.0f;
77
        if (value > 1.0f) return 1.0f;
78
        return value;
79
    }
80
81
    @Override
82
    public HudPhase getHudPhase() {
83
        return HudPhase.FIRST;
84
    }
85
86
    public void handleSound(Identifier id, Vec3 pos) {
87
        if (!isEnabled() || mc.level == null || mc.player == null) return;
88
        if (id == null || pos == null) return;
89
        synchronized (soundLock) {
90
            sounds.add(new SoundPing(id, pos, System.currentTimeMillis()));
91
        }
92
    }
93
94
    @Override
95
    public void onDisable() {
96
        synchronized (soundLock) {
97
            sounds.clear();
98
        }
99
    }
100
101
    @Override
102
    public void onRenderHudEngine(Renderer2D renderer, TextRenderer textRenderer, GuiGraphicsExtractor ctx, float tickDelta) {
103
        if (!isEnabled() || mc.level == null || mc.player == null) return;
104
105
        long now = System.currentTimeMillis();
106
        int lifetime = Math.max(1, lifetimeMs.get());
107
        List<SoundPing> snapshot = new ArrayList<>();
108
        Vec3 camPos = mc.gameRenderer.mainCamera().position();
109
        double maxDistSq = (double) maxDistance.get() * maxDistance.get();
110
111
        synchronized (soundLock) {
112
            for (int i = sounds.size() - 1; i >= 0; i--) {
113
                SoundPing ping = sounds.get(i);
114
                long age = now - ping.timestampMs();
115
                if (age > lifetime) {
116
                    sounds.remove(i);
117
                    continue;
118
                }
119
                if (camPos.distanceToSqr(ping.pos()) > maxDistSq) {
120
                    continue;
121
                }
122
                snapshot.add(ping);
123
            }
124
        }
125
        if (snapshot.isEmpty()) return;
126
127
        boolean measureStarted = false;
128
        if (!textRenderer.isBuilding()) {
129
            textRenderer.begin(TEXT_SCALE, true, false);
130
            measureStarted = true;
131
        }
132
133
        List<SoundLabel> labels = new ArrayList<>(snapshot.size());
134
        for (SoundPing ping : snapshot) {
135
            Vec3 screen = worldToScreen(ping.pos(), tickDelta);
136
            if (screen == null) continue;
137
138
            String text = RuntimeTextLayout.singleLine(resolveName(ping.getId()));
139
            if (text.isBlank()) continue;
140
141
            long age = now - ping.timestampMs();
142
            float alpha = computeAlpha(age, lifetime);
143
            if (alpha <= 0.001f) continue;
144
145
            double textWidth = Math.max(0.0, textRenderer.getWidth(text, false));
146
            double textHeight = Math.max(0.0, textRenderer.getHeight(false));
147
            double width = textWidth + PAD_X * 2.0;
148
            double height = textHeight + PAD_Y * 2.0;
149
            double x = Math.floor(screen.x - width * 0.5 + 0.5);
150
            double y = Math.floor(screen.y - height - LABEL_Y_OFFSET + 0.5);
151
            double textX = x + PAD_X;
152
            double textY = y + (height - textHeight) * 0.5;
153
            labels.add(new SoundLabel(text, x, y, width, height, textX, textY, alpha));
154
        }
155
156
        if (measureStarted) {
157
            textRenderer.end();
158
        }
159
        if (labels.isEmpty()) return;
160
161
        int baseTextColor = color.getArgb();
162
        for (SoundLabel label : labels) {
163
            MatteHudStyle.drawEspMattePlate(
164
                    renderer,
165
                    label.x(),
166
                    label.y(),
167
                    label.width(),
168
                    label.height(),
169
                    3.6f,
170
                    label.alpha()
171
            );
172
        }
173
174
        boolean renderStarted = false;
175
        if (!textRenderer.isBuilding()) {
176
            textRenderer.begin(TEXT_SCALE);
177
            renderStarted = true;
178
        }
179
        for (SoundLabel label : labels) {
180
            textRenderer.render(label.text(), label.textX(), label.textY(), new RenderColor(MatteHudStyle.scaleAlpha(baseTextColor, label.alpha())), false);
181
        }
182
        if (renderStarted) {
183
            textRenderer.end();
184
        }
185
    }
186
187
    @Override
188
    public void onRender2D(GuiGraphicsExtractor ctx, float tickDelta) {
189
        // Vanilla DrawContext path is intentionally not used.
190
    }
191
192
    private String resolveName(Identifier id) {
193
        if (id == null) return "";
194
        if ("Localized".equals(nameMode.get())) {
195
            String key = "subtitles." + id.getPath();
196
            String translated = I18n.get(key);
197
            if (!translated.equals(key)) return translated;
198
        }
199
        return id.toString();
200
    }
201
202
    private Vec3 worldToScreen(Vec3 worldPos, float tickDelta) {
203
        return ScreenProjection.worldToScreen(worldPos, tickDelta);
204
    }
205
206
    private record SoundPing(Identifier id, Vec3 pos, long timestampMs) {
207
        public Identifier getId() {
208
            return id;
209
        }
210
    }
211
212
    private record SoundLabel(String text, double x, double y, double width, double height,
213
                              double textX, double textY, float alpha) {
214
    }
215
}
216