Hitbox module

Hitbox: Minecraft 26.3 cheat module, full source for every implementation (2 clients: Combatant, LiquidBounce (Kotlin)).

2 implementationsCOMBAT

Full module source: 2 implementations

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

CombatantCOMBATsrc/main/java/combatant/client/features/module/modules/combat/Hitbox.javaJava · 469 lines · 16.7 KB
SettingshitboxPaddinghitboxSoftDisablehitboxRenderEnabledhitboxRenderDistancehitboxIgnoreGroupshitboxColor
Hitbox.javaJava · Minecraft 26.2 · 469 lines · 16.7 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.combat;
9
10
import com.mojang.blaze3d.systems.RenderSystem;
11
import com.mojang.blaze3d.vertex.PoseStack;
12
import combatant.client.config.values.*;
13
import combatant.client.features.module.*;
14
import combatant.client.features.module.Module;
15
import net.minecraft.client.Minecraft;
16
import net.minecraft.core.registries.BuiltInRegistries;
17
import net.minecraft.world.entity.Entity;
18
import net.minecraft.world.entity.LivingEntity;
19
import net.minecraft.world.entity.player.Player;
20
import net.minecraft.world.phys.AABB;
21
import net.minecraft.world.phys.Vec3;
22
import org.joml.Matrix4f;
23
import org.joml.Quaternionf;
24
import combatant.client.config.values.*;
25
import combatant.client.features.module.*;
26
import combatant.client.features.module.modules.visuals.ESP;
27
import combatant.client.features.relations.CategoryRules;
28
import combatant.client.features.relations.CategoryType;
29
import combatant.client.features.relations.EntityFilters;
30
import combatant.client.mixininterface.IEntity;
31
import combatant.client.render.engine.RenderState;
32
import combatant.client.render.engine.depth.PreTranslucentDepth;
33
import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
34
import combatant.client.render.engine.renderer.MeshRenderer;
35
import combatant.client.render.engine.renderer.Renderer3D;
36
import combatant.client.render.engine.uniform.MeshBuilder;
37
38
import java.util.ArrayList;
39
import java.util.List;
40
import java.util.Map;
41
import java.util.concurrent.ConcurrentHashMap;
42
43
44
//todo Description
45
@ModuleInfo(
46
        id = "hitbox",
47
        displayName = "Hitbox",
48
        category = ModuleCategory.COMBAT
49
)
50
public class Hitbox extends Module {
51
52
    private static final String ACTION_SUPPRESS_HITBOX = "suppress_hitbox";
53
    private static final long HIT_FLASH_DURATION_MS = 2000;
54
    private static final MeshBuilder HITBOX_TRIS = new MeshBuilder(CombatantRenderPipelines.WORLD_COLORED_LIQUID_IGNORE);
55
    private static final MeshBuilder HITBOX_LINES = new MeshBuilder(CombatantRenderPipelines.WORLD_COLORED_LINES_DEPTH);
56
    private final Minecraft mc = Minecraft.getInstance();
57
    private final NumberValue<Float> padding =
58
            num(
59
                    "hitboxPadding",
60
                    "padding",
61
                    2.0f,
62
                    0.2f,
63
                    3.0f
64
            );
65
    private final BooleanValue softDisable =
66
            bool(
67
                    "hitboxSoftDisable",
68
                    "soft_disable_hold",
69
                    true
70
            );
71
    private final BooleanValue renderEnabled =
72
            bool(
73
                    "hitboxRenderEnabled",
74
                    "render_hitboxes",
75
                    true
76
            );
77
    private final NumberValue<Integer> renderDistance =
78
            visibleWhen(num(
79
                    "hitboxRenderDistance",
80
                    "render_distance",
81
                    48,
82
                    8,
83
                    160
84
            ), renderEnabled::get);
85
    private final BooleanMapValue ignoreGroups =
86
            visibleWhen(group(
87
                    "hitboxIgnoreGroups",
88
                    "ignore_categories",
89
                    ignoreCategoryDefaults()
90
            ), renderEnabled::get);
91
    private final RGBColorValue hitboxColor =
92
            visibleWhen(colorNoAlpha(
93
                    "hitboxColor",
94
                    "hitbox_color",
95
                    "#78C8FF"
96
            ), renderEnabled::get);
97
    private final Map<Integer, Long> hitFlashMs = new ConcurrentHashMap<>();
98
    private final List<AABB> precomputedBoxes = new ArrayList<>();
99
    private final List<Entity> precomputedEntities = new ArrayList<>();
100
101
    {
102
        setDefaultBind("G"); // toggle padding/module
103
        addAction(ACTION_SUPPRESS_HITBOX, "MOUSE3", BindMode.HOLD);
104
    }
105
106
    private static Map<String, Boolean> ignoreCategoryDefaults() {
107
        return Map.of(
108
                "friends", false,
109
                "staff", false,
110
                "enemies", false,
111
                "entities", false
112
        );
113
    }
114
115
    // ======================================================
116
    //                      STATE
117
    // ======================================================
118
119
    private static PoseStack buildTransformStack() {
120
        Matrix4f mv = new Matrix4f(RenderSystem.getModelViewMatrixCopy());
121
        Quaternionf camRot = new Quaternionf(RenderState.cameraRotation).conjugate();
122
        Matrix4f rotation = new Matrix4f().rotation(camRot);
123
        Matrix4f transform = mv.invert().mul(rotation);
124
        PoseStack stack = new PoseStack();
125
        stack.last().pose().set(transform);
126
        return stack;
127
    }
128
129
    private static void addFilledBox(MeshBuilder mesh, AABB box, int r, int g, int b, int a) {
130
        double minX = box.minX;
131
        double minY = box.minY;
132
        double minZ = box.minZ;
133
        double maxX = box.maxX;
134
        double maxY = box.maxY;
135
        double maxZ = box.maxZ;
136
137
        quad(mesh, minX, minY, minZ, maxX, minY, minZ, maxX, minY, maxZ, minX, minY, maxZ, r, g, b, a);
138
        quad(mesh, minX, maxY, minZ, minX, maxY, maxZ, maxX, maxY, maxZ, maxX, maxY, minZ, r, g, b, a);
139
        quad(mesh, minX, minY, maxZ, maxX, minY, maxZ, maxX, maxY, maxZ, minX, maxY, maxZ, r, g, b, a);
140
        quad(mesh, minX, minY, minZ, minX, maxY, minZ, maxX, maxY, minZ, maxX, minY, minZ, r, g, b, a);
141
        quad(mesh, maxX, minY, minZ, maxX, maxY, minZ, maxX, maxY, maxZ, maxX, minY, maxZ, r, g, b, a);
142
        quad(mesh, minX, minY, minZ, minX, minY, maxZ, minX, maxY, maxZ, minX, maxY, minZ, r, g, b, a);
143
    }
144
145
    private static void addOutlineBox(MeshBuilder mesh, AABB box, int r, int g, int b, int a) {
146
        double minX = box.minX;
147
        double minY = box.minY;
148
        double minZ = box.minZ;
149
        double maxX = box.maxX;
150
        double maxY = box.maxY;
151
        double maxZ = box.maxZ;
152
153
        line(mesh, minX, minY, minZ, maxX, minY, minZ, r, g, b, a);
154
        line(mesh, maxX, minY, minZ, maxX, minY, maxZ, r, g, b, a);
155
        line(mesh, maxX, minY, maxZ, minX, minY, maxZ, r, g, b, a);
156
        line(mesh, minX, minY, maxZ, minX, minY, minZ, r, g, b, a);
157
158
        line(mesh, minX, maxY, minZ, maxX, maxY, minZ, r, g, b, a);
159
        line(mesh, maxX, maxY, minZ, maxX, maxY, maxZ, r, g, b, a);
160
        line(mesh, maxX, maxY, maxZ, minX, maxY, maxZ, r, g, b, a);
161
        line(mesh, minX, maxY, maxZ, minX, maxY, minZ, r, g, b, a);
162
163
        line(mesh, minX, minY, minZ, minX, maxY, minZ, r, g, b, a);
164
        line(mesh, maxX, minY, minZ, maxX, maxY, minZ, r, g, b, a);
165
        line(mesh, maxX, minY, maxZ, maxX, maxY, maxZ, r, g, b, a);
166
        line(mesh, minX, minY, maxZ, minX, maxY, maxZ, r, g, b, a);
167
    }
168
169
    private static void quad(MeshBuilder mesh,
170
                             double x1, double y1, double z1,
171
                             double x2, double y2, double z2,
172
                             double x3, double y3, double z3,
173
                             double x4, double y4, double z4,
174
                             int r, int g, int b, int a) {
175
        mesh.ensureQuadCapacity();
176
        int i1 = mesh.vec3(x1, y1, z1).color(r, g, b, a).next();
177
        int i2 = mesh.vec3(x2, y2, z2).color(r, g, b, a).next();
178
        int i3 = mesh.vec3(x3, y3, z3).color(r, g, b, a).next();
179
        int i4 = mesh.vec3(x4, y4, z4).color(r, g, b, a).next();
180
        mesh.quad(i1, i2, i3, i4);
181
    }
182
183
    private static void line(MeshBuilder mesh,
184
                             double x1, double y1, double z1,
185
                             double x2, double y2, double z2,
186
                             int r, int g, int b, int a) {
187
        mesh.ensureLineCapacity();
188
        int i1 = mesh.vec3(x1, y1, z1).color(r, g, b, a).next();
189
        int i2 = mesh.vec3(x2, y2, z2).color(r, g, b, a).next();
190
        mesh.line(i1, i2);
191
    }
192
193
    // ======================================================
194
    //                  FILTERING
195
    // ======================================================
196
197
    public static double boxDistanceSq(AABB box, Vec3 p) {
198
        double dx = 0.0;
199
        if (p.x < box.minX) dx = box.minX - p.x;
200
        else if (p.x > box.maxX) dx = p.x - box.maxX;
201
202
        double dy = 0.0;
203
        if (p.y < box.minY) dy = box.minY - p.y;
204
        else if (p.y > box.maxY) dy = p.y - box.maxY;
205
206
        double dz = 0.0;
207
        if (p.z < box.minZ) dz = box.minZ - p.z;
208
        else if (p.z > box.maxZ) dz = p.z - box.maxZ;
209
210
        return dx * dx + dy * dy + dz * dz;
211
    }
212
213
    public boolean isSoftDisabledNow() {
214
        return softDisable.get() && isActionHeld(ACTION_SUPPRESS_HITBOX);
215
    }
216
217
    // ======================================================
218
    //                     RENDER
219
    // ======================================================
220
221
    public boolean isActiveForHitbox() {
222
        return isEnabled() && !isSoftDisabledNow();
223
    }
224
225
    public double getPadding() {
226
        return padding.get();
227
    }
228
229
    public boolean shouldRender() {
230
        return isActiveForHitbox() && renderEnabled.get();
231
    }
232
233
    public int getRenderDistance() {
234
        return renderDistance.get();
235
    }
236
237
    public boolean isAllowed(Entity e) {
238
        if (e instanceof Player p) {
239
            String name = p.getGameProfile().name();
240
            if (name != null) {
241
                CategoryType type = CategoryRules.determine(name);
242
                if (type == CategoryType.BEDWARS_SELF) return false;
243
                if (ignoreGroups.get("friends") && type == CategoryType.FRIEND) return false;
244
                if (ignoreGroups.get("staff") && type == CategoryType.STAFF) return false;
245
                if (ignoreGroups.get("enemies")
246
                        && (type == CategoryType.ENEMY || type == CategoryType.BEDWARS_ENEMY)) return false;
247
            }
248
        }
249
250
        var id = BuiltInRegistries.ENTITY_TYPE.getKey(e.getType());
251
        return id == null || !ignoreGroups.get("entities") || !EntityFilters.get().isIgnoredEntity(id.toString());
252
    }
253
254
    /**
255
     * True when the entity should be skipped entirely (raycast + render).
256
     */
257
    public boolean shouldIgnore(Entity e) {
258
        return !isAllowed(e);
259
    }
260
261
    @Override
262
    public WorldPhase getWorldPhase() {
263
        return WorldPhase.END_MAIN;
264
    }
265
266
    @Override
267
    public void onRenderWorld(PoseStack matrices, net.minecraft.client.renderer.SubmitNodeCollector consumers, float tickDelta) {
268
    }
269
270
    @Override
271
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
272
        if (!shouldRender() || mc.level == null || mc.player == null) return;
273
274
        Vec3 cam = mc.gameRenderer.mainCamera().position();
275
        precomputeBoxes(mc, tickDelta, cam);
276
277
        if (precomputedBoxes.isEmpty()) return;
278
279
        MeshBuilder tris = HITBOX_TRIS;
280
        MeshBuilder lines = HITBOX_LINES;
281
        lines.begin();
282
        tris.begin();
283
284
        for (int i = 0; i < precomputedBoxes.size(); i++) {
285
            AABB box = precomputedBoxes.get(i);
286
            Entity e = precomputedEntities.get(i);
287
288
            float flash = getHitFlashFactor(e);
289
            float[] rgba = resolveColor(e);
290
291
            float r = rgba[0], g = rgba[1], b = rgba[2];
292
            float fillA = Math.min(1.0f, (0.18f + 0.12f * flash) * 1.17f); //альфа тут
293
            float lineA = Math.min(1.0f, 0.65f + 0.25f * flash);
294
295
            r = r * (1 - flash) + flash;
296
            g = g * (1 - flash) + 0.5f * flash;
297
            b = b * (1 - flash) + 0.0f * flash;
298
299
            int ri = (int) (r * 255f);
300
            int gi = (int) (g * 255f);
301
            int bi = (int) (b * 255f);
302
            int fa = (int) (fillA * 255f);
303
            int la = (int) (lineA * 255f);
304
305
            addOutlineBox(lines, box, ri, gi, bi, la);
306
            addFilledBox(tris, box, ri, gi, bi, fa);
307
        }
308
309
        tris.end();
310
        lines.end();
311
312
        PoseStack transform = buildTransformStack();
313
        var fb = mc.gameRenderer.mainRenderTarget();
314
        var depthView = PreTranslucentDepth.getDepthView();
315
        var colorView = fb.getColorTextureView();
316
        if (depthView == null) {
317
            return;
318
        }
319
320
        if (tris.getIndicesCount() > 0) {
321
            MeshRenderer.begin()
322
                    .attachments(colorView, depthView)
323
                    .pipeline(CombatantRenderPipelines.WORLD_COLORED_LIQUID_IGNORE)
324
                    .mesh(tris, transform)
325
                    .end();
326
        }
327
328
        if (lines.getIndicesCount() > 0) {
329
            MeshRenderer.begin()
330
                    .attachments(colorView, depthView)
331
                    .pipeline(CombatantRenderPipelines.WORLD_COLORED_LINES_DEPTH)
332
                    .mesh(lines, transform)
333
                    .end();
334
        }
335
    }
336
337
    private void precomputeBoxes(Minecraft mc, float tickDelta, Vec3 cam) {
338
        precomputedBoxes.clear();
339
        precomputedEntities.clear();
340
341
        double maxDist = getRenderDistance();
342
        double maxDistSq = maxDist * maxDist;
343
344
        AABB search = new AABB(
345
                cam.x - maxDist, cam.y - maxDist, cam.z - maxDist,
346
                cam.x + maxDist, cam.y + maxDist, cam.z + maxDist
347
        );
348
349
        List<Entity> list = mc.level.getEntities(mc.player, search,
350
                e -> e instanceof LivingEntity && e.isAlive() && isAllowed(e) && !isRenderedByEspReplacement(e));
351
352
        for (Entity e : list) {
353
            Vec3 pos = obtainEntityLerpedPos(e, tickDelta);
354
355
            double dx = pos.x - cam.x;
356
            double dy = pos.y - cam.y;
357
            double dz = pos.z - cam.z;
358
            if (dx * dx + dy * dy + dz * dz > maxDistSq) continue;
359
360
            AABB box = e.getBoundingBox()
361
                    .move(pos.subtract(e.position()))
362
                    .inflate(getPadding());
363
364
            precomputedBoxes.add(box);
365
            precomputedEntities.add(e);
366
        }
367
    }
368
369
    private Vec3 obtainEntityLerpedPos(Entity e, float f) {
370
        try {
371
            return e.getPosition(f);
372
        } catch (NoSuchMethodError ex) {
373
            if (e instanceof IEntity access) {
374
                Vec3 last = access.get$InstantRenderPos();
375
                return last.lerp(e.position(), f);
376
            }
377
            return e.position();
378
        }
379
    }
380
381
    private boolean isRenderedByEspReplacement(Entity e) {
382
        ESP esp = Modules.get(ESP.class);
383
        return esp != null && esp.shouldRenderHitboxReplacement(e);
384
    }
385
386
    private float[] resolveColor(Entity e) {
387
        return argbToRgba(hitboxColor.getArgb());
388
    }
389
390
    // ======================================================
391
    //                 HIT FLASH SUPPORT
392
    // ======================================================
393
394
    private float[] argbToRgba(int argb) {
395
        float a = ((argb >> 24) & 255) / 255f;
396
        float r = ((argb >> 16) & 255) / 255f;
397
        float g = ((argb >> 8) & 255) / 255f;
398
        float b = (argb & 255) / 255f;
399
        return new float[]{r, g, b, a};
400
    }
401
402
    public void markHit(Entity e) {
403
        if (e != null) hitFlashMs.put(e.getId(), System.currentTimeMillis());
404
405
    }
406
407
    // ======================================================
408
    //             Utility for other components
409
    // ======================================================
410
411
    private float getHitFlashFactor(Entity e) {
412
        Long t0 = hitFlashMs.get(e.getId());
413
        if (t0 == null) return 0f;
414
415
        long dt = System.currentTimeMillis() - t0;
416
        if (dt >= HIT_FLASH_DURATION_MS) {
417
            hitFlashMs.remove(e.getId());
418
            return 0f;
419
        }
420
421
        float x = 1f - (float) dt / HIT_FLASH_DURATION_MS;
422
        return x * x * (3f - 2f * x);
423
    }
424
425
    /**
426
     * Render/visual replacement predicate: active Hitbox + the same category/entity filters,
427
     * but without the interaction distance check used by raycast expansion.
428
     */
429
    public boolean isReplacementCandidate(Entity e) {
430
        if (!(e instanceof LivingEntity living) || !living.isAlive()) {
431
            return false;
432
        }
433
        return isActiveForHitbox() && isAllowed(e);
434
    }
435
436
    public boolean shouldExpandFor(Entity e) {
437
        if (!(e instanceof LivingEntity living) || !living.isAlive()) {
438
            return false;
439
        }
440
441
        return isEnabled() && !isSoftDisabledNow() && isAllowed(e) && withinMaxDistance(e);
442
    }
443
444
    private boolean withinMaxDistance(Entity e) {
445
        if (mc.player == null) return true;
446
        Vec3 eye = mc.player.getEyePosition(1.0F);
447
        return boxDistanceSq(e.getBoundingBox(), eye) <= 36.0;
448
    }
449
450
    public void updateForLogic(float tickDelta) {
451
        if (mc.player == null || mc.level == null) return;
452
453
        Vec3 eye = mc.player.getEyePosition(tickDelta);
454
        precomputeBoxes(mc, tickDelta, eye);
455
    }
456
457
    public int getPrecomputedCount() {
458
        return precomputedBoxes.size();
459
    }
460
461
    public Entity getPrecomputedEntity(int i) {
462
        return precomputedEntities.get(i);
463
    }
464
465
    public AABB getPrecomputedBox(int i) {
466
        return precomputedBoxes.get(i);
467
    }
468
}
469
LiquidBounce (Kotlin)COMBATsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleHitbox.ktKotlin · 51 lines · 1.7 KB

Enlarges the hit box of targets.

SettingsSizeApplyToDebugHitboxApplyToComponent
ModuleHitbox.ktKotlin · Minecraft 26.2 · 51 lines · 1.7 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.combat
20
21
import net.ccbluex.liquidbounce.event.events.EntityMarginEvent
22
import net.ccbluex.liquidbounce.event.handler
23
import net.ccbluex.liquidbounce.features.module.ClientModule
24
import net.ccbluex.liquidbounce.features.module.ModuleCategories
25
import net.ccbluex.liquidbounce.utils.combat.shouldBeAttacked
26
27
/**
28
 * Hitbox module
29
 *
30
 * Enlarges the hitbox of other entities.
31
 */
32
object ModuleHitbox : ClientModule("Hitbox", ModuleCategories.COMBAT) {
33
34
    val size by float("Size", 0.1f, 0f..1f).apply { tagBy(this) }
35
36
    val applyToDebugHitbox by boolean("ApplyToDebugHitbox", true)
37
38
    /**
39
     * Apply to [net.minecraft.world.item.component.AttackRange.hitboxMargin]
40
     */
41
    val applyToComponent by boolean("ApplyToComponent", true)
42
43
    @Suppress("unused")
44
    private val marginHandler = handler<EntityMarginEvent> { event ->
45
        if (event.entity.shouldBeAttacked()) {
46
            event.margin = size
47
        }
48
    }
49
50
}
51