BlockHighLight module

BlockHighLight: 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/BlockHighLight.javaJava · 63 lines · 3.4 KB

Highlights crosshair block.

SettingsModeColorLineWidth
BlockHighLight.javaJava · Minecraft 26.2 · 63 lines · 3.4 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.render;
2
3
import thunder.hack.features.modules.Module;
4
import thunder.hack.setting.Setting;
5
import thunder.hack.setting.impl.ColorSetting;
6
import thunder.hack.utility.render.Render2DEngine;
7
import thunder.hack.utility.render.Render3DEngine.FillAction;
8
import thunder.hack.utility.render.Render3DEngine.FillSideAction;
9
import thunder.hack.utility.render.Render3DEngine.OutlineAction;
10
import thunder.hack.utility.render.Render3DEngine.OutlineSideAction;
11
12
import static thunder.hack.utility.render.Render3DEngine.*;
13
import static thunder.hack.utility.render.Render3DEngine.OUTLINE_QUEUE;
14
import static thunder.hack.utility.render.Render3DEngine.OUTLINE_SIDE_QUEUE;
15
import static thunder.hack.utility.render.Render3DEngine.FILLED_QUEUE;
16
import static thunder.hack.utility.render.Render3DEngine.FILLED_SIDE_QUEUE;
17
import static thunder.hack.utility.render.Render3DEngine.OutlineAction;
18
import static thunder.hack.utility.render.Render3DEngine.OutlineSideAction;
19
20
import com.mojang.blaze3d.vertex.PoseStack;
21
import net.minecraft.world.phys.AABB;
22
import net.minecraft.world.phys.BlockHitResult;
23
import net.minecraft.world.phys.HitResult;
24
25
import static thunder.hack.utility.render.Render3DEngine.FillAction;
26
import static thunder.hack.utility.render.Render3DEngine.FillSideAction;
27
28
public class BlockHighLight extends Module {
29
    public BlockHighLight() {
30
        super("BlockHighLight", Category.RENDER);
31
    }
32
33
    private final Setting<Mode> mode = new Setting("Mode", Mode.Outline);
34
    private final Setting<ColorSetting> color = new Setting<>("Color", new ColorSetting(0xFFFFFFFF));
35
    private final Setting<Float> lineWidth = new Setting<>("LineWidth", 1F, 0f, 5F);
36
37
    private enum Mode {
38
        Both, BothSide, Fill, FilledSide, Outline, OutlinedSide
39
    }
40
41
    public void onRender3D(PoseStack stack) {
42
        if (mc.hitResult == null) return;
43
        if (mc.hitResult.getType() != HitResult.Type.BLOCK) return;
44
        if (!(mc.hitResult instanceof BlockHitResult bhr)) return;
45
46
        switch (mode.getValue()) {
47
            case Both -> {
48
                OUTLINE_QUEUE.add(new OutlineAction(new AABB(bhr.getBlockPos()), Render2DEngine.injectAlpha(color.getValue().getColorObject(), 255), lineWidth.getValue()));
49
                FILLED_QUEUE.add(new FillAction(new AABB(bhr.getBlockPos()), color.getValue().getColorObject()));
50
            }
51
            case BothSide -> {
52
                OUTLINE_SIDE_QUEUE.add(new OutlineSideAction(new AABB(bhr.getBlockPos()), Render2DEngine.injectAlpha(color.getValue().getColorObject(),255), lineWidth.getValue(),bhr.getDirection()));
53
                FILLED_SIDE_QUEUE.add(new FillSideAction(new AABB(bhr.getBlockPos()),color.getValue().getColorObject(),bhr.getDirection()));
54
            }
55
            case Fill -> FILLED_QUEUE.add(new FillAction(new AABB(bhr.getBlockPos()), color.getValue().getColorObject()));
56
            case FilledSide -> FILLED_SIDE_QUEUE.add(new FillSideAction(new AABB(bhr.getBlockPos()),color.getValue().getColorObject(),bhr.getDirection()));
57
58
            case Outline ->  OUTLINE_QUEUE.add(new OutlineAction(new AABB(bhr.getBlockPos()), Render2DEngine.injectAlpha(color.getValue().getColorObject(),255), lineWidth.getValue()));
59
            case OutlinedSide -> OUTLINE_SIDE_QUEUE.add(new OutlineSideAction(new AABB(bhr.getBlockPos()), Render2DEngine.injectAlpha(color.getValue().getColorObject(),255), lineWidth.getValue(),bhr.getDirection()));
60
        }
61
    }
62
}
63
CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/BlockHighlight.javaJava · 597 lines · 21.3 KB
Settingsoutline_enabledoutline_modeoutline_coloroutline_color_modeoutline_color2outline_color_speedoutline_thicknessoutline_depth_testbreaking_enabledbreaking_selfbreaking_other_playersbreaking_animationbreaking_colorbreaking_color2
BlockHighlight.javaJava · Minecraft 26.2 · 597 lines · 21.3 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.multiplayer.MultiPlayerGameMode;
12
import net.minecraft.core.BlockPos;
13
import net.minecraft.server.level.BlockDestructionProgress;
14
import net.minecraft.util.Mth;
15
import net.minecraft.world.entity.Entity;
16
import net.minecraft.world.level.block.state.BlockState;
17
import net.minecraft.world.phys.AABB;
18
import net.minecraft.world.phys.BlockHitResult;
19
import net.minecraft.world.phys.HitResult;
20
import net.minecraft.world.phys.shapes.CollisionContext;
21
import net.minecraft.world.phys.shapes.VoxelShape;
22
import combatant.client.config.common.CommonSettingSchemas;
23
import combatant.client.config.values.BooleanValue;
24
import combatant.client.config.values.EnumValue;
25
import combatant.client.config.values.NumberValue;
26
import combatant.client.config.values.RGBAColorValue;
27
import combatant.client.features.module.Module;
28
import combatant.client.features.module.ModuleCategory;
29
import combatant.client.features.module.ModuleInfo;
30
import combatant.client.features.module.WorldPhase;
31
import combatant.client.mixins.accessors.MultiPlayerGameModeAccessor;
32
import combatant.client.render.engine.RenderState;
33
import combatant.client.render.engine.animation.AnimatedRenderColors;
34
import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
35
import combatant.client.render.engine.renderer.Renderer3D;
36
import combatant.client.render.engine.uniform.MeshBuilder;
37
38
39
//todo Description
40
@ModuleInfo(
41
        id = "blockhighlight",
42
        displayName = "BlockHighlight",
43
        category = ModuleCategory.VISUALS
44
)
45
public class BlockHighlight extends Module {
46
47
    private static final double RAINBOW_SPATIAL_SCALE = 12.0;
48
    private static final double GEOMETRY_EXPAND = 0.0025;
49
    private final Minecraft mc = Minecraft.getInstance();
50
    private final BooleanValue outlineEnabled =
51
            bool(
52
                    "outline_enabled",
53
                    true
54
            );
55
    private final EnumValue<OutlineMode> outlineMode =
56
            visibleWhen(enumMode(
57
                    "outline_mode",
58
                    OutlineMode.LINES,
59
                    OutlineMode.values()
60
            ), outlineEnabled::get);
61
    private final RGBAColorValue outlineColor =
62
            visibleWhen(color(
63
                    "outline_color",
64
                    "#66FFFFFF"
65
            ), outlineEnabled::get);
66
    private final EnumValue<ColorMode> outlineColorMode =
67
            visibleWhen(enumCommon(
68
                    "outline_color_mode",
69
                    "outline_color_mode",
70
                    CommonSettingSchemas.RENDER_COLOR_MODE,
71
                    ColorMode.STATIC,
72
                    ColorMode.values()
73
            ), outlineEnabled::get);
74
    private final RGBAColorValue outlineColor2 =
75
            visibleWhen(color(
76
                    "outline_color2",
77
                    "#FFFFAA00"
78
            ), this::usesSecondaryOutlineColor);
79
    private final NumberValue<Integer> outlineColorSpeed =
80
            visibleWhen(num(
81
                    "outline_color_speed",
82
                    18,
83
                    2,
84
                    54
85
            ), outlineEnabled::get);
86
    private final NumberValue<Float> outlineThickness =
87
            visibleWhen(num(
88
                    "outline_thickness",
89
                    1.0f,
90
                    0.5f,
91
                    4.0f
92
            ), outlineEnabled::get);
93
    private final BooleanValue outlineDepthTest =
94
            visibleWhen(bool(
95
                    "outline_depth_test",
96
                    false
97
            ), outlineEnabled::get);
98
    private final BooleanValue breakingEnabled =
99
            bool(
100
                    "breaking_enabled",
101
                    true
102
            );
103
    private final BooleanValue breakingSelf =
104
            visibleWhen(bool(
105
                    "breaking_self",
106
                    true
107
            ), breakingEnabled::get);
108
    private final BooleanValue breakingOtherPlayers =
109
            visibleWhen(bool(
110
                    "breaking_other_players",
111
                    true
112
            ), breakingEnabled::get);
113
    private final EnumValue<BreakAnimation> breakingAnimation =
114
            visibleWhen(enumMode(
115
                    "breaking_animation",
116
                    BreakAnimation.GROW,
117
                    BreakAnimation.values()
118
            ), breakingEnabled::get);
119
    private final RGBAColorValue breakingColor =
120
            visibleWhen(color(
121
                    "breaking_color",
122
                    "#66FFFFFF"
123
            ), breakingEnabled::get);
124
    private final RGBAColorValue breakingColor2 =
125
            visibleWhen(color(
126
                    "breaking_color2",
127
                    "#22FFAA00"
128
            ), breakingEnabled::get);
129
130
    private static void addGradientLine(MeshBuilder mesh,
131
                                        double x1, double y1, double z1,
132
                                        double x2, double y2, double z2,
133
                                        int argb1,
134
                                        int argb2) {
135
        mesh.ensureLineCapacity();
136
137
        putColorVertex(mesh, x1, y1, z1, argb1);
138
        int i1 = mesh.next();
139
140
        putColorVertex(mesh, x2, y2, z2, argb2);
141
        int i2 = mesh.next();
142
143
        mesh.line(i1, i2);
144
    }
145
146
    private static void addGradientQuad(MeshBuilder mesh,
147
                                        double x1, double y1, double z1, int c1,
148
                                        double x2, double y2, double z2, int c2,
149
                                        double x3, double y3, double z3, int c3,
150
                                        double x4, double y4, double z4, int c4) {
151
        mesh.ensureQuadCapacity();
152
153
        putColorVertex(mesh, x1, y1, z1, c1);
154
        int i1 = mesh.next();
155
156
        putColorVertex(mesh, x2, y2, z2, c2);
157
        int i2 = mesh.next();
158
159
        putColorVertex(mesh, x3, y3, z3, c3);
160
        int i3 = mesh.next();
161
162
        putColorVertex(mesh, x4, y4, z4, c4);
163
        int i4 = mesh.next();
164
165
        mesh.quad(i1, i2, i3, i4);
166
    }
167
168
    private static void putColorVertex(MeshBuilder mesh, double x, double y, double z, int argb) {
169
        mesh.vec3(x, y, z).color(red(argb), green(argb), blue(argb), alpha(argb));
170
    }
171
172
    private static void addFilledBox(Renderer3D renderer, AABB box, int argb) {
173
        int a = alpha(argb);
174
        int r = red(argb);
175
        int g = green(argb);
176
        int b = blue(argb);
177
178
        double minX = box.minX;
179
        double minY = box.minY;
180
        double minZ = box.minZ;
181
        double maxX = box.maxX;
182
        double maxY = box.maxY;
183
        double maxZ = box.maxZ;
184
185
        renderer.quad(minX, minY, minZ, maxX, minY, minZ, maxX, minY, maxZ, minX, minY, maxZ, r, g, b, a);
186
        renderer.quad(minX, maxY, minZ, minX, maxY, maxZ, maxX, maxY, maxZ, maxX, maxY, minZ, r, g, b, a);
187
        renderer.quad(minX, minY, maxZ, maxX, minY, maxZ, maxX, maxY, maxZ, minX, maxY, maxZ, r, g, b, a);
188
        renderer.quad(minX, minY, minZ, minX, maxY, minZ, maxX, maxY, minZ, maxX, minY, minZ, r, g, b, a);
189
        renderer.quad(maxX, minY, minZ, maxX, maxY, minZ, maxX, maxY, maxZ, maxX, minY, maxZ, r, g, b, a);
190
        renderer.quad(minX, minY, minZ, minX, minY, maxZ, minX, maxY, maxZ, minX, maxY, minZ, r, g, b, a);
191
    }
192
193
    private static float stageToProgress(int stage) {
194
        if (stage < 0) return 0.0f;
195
        return Mth.clamp(stage / 10.0f, 0.0f, 1.0f);
196
    }
197
198
    private static int interpolateArgb(int from, int to, float amount) {
199
        amount = Mth.clamp(amount, 0.0f, 1.0f);
200
201
        int a = interpolateChannel(alpha(from), alpha(to), amount);
202
        int r = interpolateChannel(red(from), red(to), amount);
203
        int g = interpolateChannel(green(from), green(to), amount);
204
        int b = interpolateChannel(blue(from), blue(to), amount);
205
206
        return (a << 24) | (r << 16) | (g << 8) | b;
207
    }
208
209
    private static int interpolateChannel(int from, int to, float amount) {
210
        return from + Math.round((to - from) * amount);
211
    }
212
213
    private static int withAlpha(int argb, int alpha) {
214
        return (Mth.clamp(alpha, 0, 255) << 24) | (argb & 0x00FFFFFF);
215
    }
216
217
    private static int red(int argb) {
218
        return (argb >>> 16) & 255;
219
    }
220
221
    private static int green(int argb) {
222
        return (argb >>> 8) & 255;
223
    }
224
225
    private static int blue(int argb) {
226
        return argb & 255;
227
    }
228
229
    private static int alpha(int argb) {
230
        return (argb >>> 24) & 255;
231
    }
232
233
    public boolean isOutlineActive() {
234
        return isEnabled() && outlineEnabled.get();
235
    }
236
237
    @Override
238
    public WorldPhase getWorldPhase() {
239
        return WorldPhase.BEFORE_TRANSLUCENT;
240
    }
241
242
    @Override
243
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
244
        if (!isEnabled() || mc.level == null || mc.player == null) return;
245
246
        if (outlineEnabled.get()) {
247
            renderTargetOutline(renderer);
248
        }
249
250
        if (breakingEnabled.get()) {
251
            renderBreakingHighlight(renderer);
252
        }
253
    }
254
255
    private void renderTargetOutline(Renderer3D renderer) {
256
        HitResult hit = mc.hitResult;
257
        if (!(hit instanceof BlockHitResult blockHit)) return;
258
        if (hit.getType() == HitResult.Type.MISS) return;
259
260
        BlockPos pos = blockHit.getBlockPos();
261
        BlockState state = mc.level.getBlockState(pos);
262
        if (state.isAir()) return;
263
264
        Entity cameraEntity = mc.getCameraEntity();
265
        CollisionContext context = cameraEntity != null ? CollisionContext.of(cameraEntity) : CollisionContext.empty();
266
        VoxelShape shape = state.getShape(mc.level, pos, context);
267
        if (shape.isEmpty()) return;
268
269
        VoxelShape worldShape = shape.move(pos.getX(), pos.getY(), pos.getZ());
270
        OutlineMode mode = outlineMode.get();
271
272
        if (mode == OutlineMode.BOX || mode == OutlineMode.BOTH) {
273
            renderShapeBoxes(renderer, worldShape);
274
        }
275
276
        if (mode == OutlineMode.LINES || mode == OutlineMode.BOTH) {
277
            renderShapeLines(renderer, worldShape);
278
        }
279
    }
280
281
    private void renderShapeLines(Renderer3D renderer, VoxelShape worldShape) {
282
        MeshBuilder mesh = renderer.batch(
283
                outlineDepthTest.get()
284
                        ? CombatantRenderPipelines.WORLD_COLORED_COPLANAR_DEPTH
285
                        : CombatantRenderPipelines.WORLD_COLORED,
286
                outlineDepthTest.get()
287
                        ? Renderer3D.DepthMode.PRE_DEPTH
288
                        : Renderer3D.DepthMode.NONE
289
        );
290
291
        if (mesh == null) return;
292
293
        double overlap = outlineDepthTest.get()
294
                ? Math.max(0.0015, outlineThickness.get() * 0.003)
295
                : 0.0008;
296
297
        worldShape.forAllEdges((x1, y1, z1, x2, y2, z2) -> {
298
            int c1 = getOutlineColor(x1, y1, z1);
299
            int c2 = getOutlineColor(x2, y2, z2);
300
301
            addEdgeRibbon(
302
                    mesh,
303
                    x1, y1, z1,
304
                    x2, y2, z2,
305
                    overlap,
306
                    c1,
307
                    c2
308
            );
309
        });
310
    }
311
312
    private void addEdgeRibbon(MeshBuilder mesh,
313
                               double x1, double y1, double z1,
314
                               double x2, double y2, double z2,
315
                               double overlap,
316
                               int argb1,
317
                               int argb2) {
318
        double mx = (x1 + x2) * 0.5;
319
        double my = (y1 + y2) * 0.5;
320
        double mz = (z1 + z2) * 0.5;
321
322
        double ex = x2 - x1;
323
        double ey = y2 - y1;
324
        double ez = z2 - z1;
325
        double edgeLenSq = ex * ex + ey * ey + ez * ez;
326
        if (edgeLenSq <= 1.0e-10) {
327
            return;
328
        }
329
330
        double toCamX = RenderState.cameraPos.x - mx;
331
        double toCamY = RenderState.cameraPos.y - my;
332
        double toCamZ = RenderState.cameraPos.z - mz;
333
        double toCamLenSq = toCamX * toCamX + toCamY * toCamY + toCamZ * toCamZ;
334
        if (toCamLenSq <= 1.0e-10) {
335
            return;
336
        }
337
338
        double sideX = ey * toCamZ - ez * toCamY;
339
        double sideY = ez * toCamX - ex * toCamZ;
340
        double sideZ = ex * toCamY - ey * toCamX;
341
        double sideLenSq = sideX * sideX + sideY * sideY + sideZ * sideZ;
342
        if (sideLenSq <= 1.0e-10) {
343
            return;
344
        }
345
346
        double sideInv = 1.0 / Math.sqrt(sideLenSq);
347
        double halfWidth = computeRibbonHalfWidth(mx, my, mz);
348
349
        sideX *= sideInv * halfWidth;
350
        sideY *= sideInv * halfWidth;
351
        sideZ *= sideInv * halfWidth;
352
353
        double camInv = 1.0 / Math.sqrt(toCamLenSq);
354
        double biasX = toCamX * camInv * overlap;
355
        double biasY = toCamY * camInv * overlap;
356
        double biasZ = toCamZ * camInv * overlap;
357
358
        addGradientQuad(
359
                mesh,
360
                x1 - sideX + biasX, y1 - sideY + biasY, z1 - sideZ + biasZ, argb1,
361
                x1 + sideX + biasX, y1 + sideY + biasY, z1 + sideZ + biasZ, argb1,
362
                x2 + sideX + biasX, y2 + sideY + biasY, z2 + sideZ + biasZ, argb2,
363
                x2 - sideX + biasX, y2 - sideY + biasY, z2 - sideZ + biasZ, argb2
364
        );
365
    }
366
367
    private double computeRibbonHalfWidth(double x, double y, double z) {
368
        double dx = RenderState.cameraPos.x - x;
369
        double dy = RenderState.cameraPos.y - y;
370
        double dz = RenderState.cameraPos.z - z;
371
        double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
372
373
        return 0.003 + outlineThickness.get() * (0.0025 + dist * 0.00018);
374
    }
375
376
    private void renderShapeBoxes(Renderer3D renderer, VoxelShape worldShape) {
377
        MeshBuilder mesh = renderer.batch(
378
                outlineDepthTest.get()
379
                        ? CombatantRenderPipelines.WORLD_COLORED_COPLANAR_DEPTH
380
                        : CombatantRenderPipelines.WORLD_COLORED,
381
                outlineDepthTest.get()
382
                        ? Renderer3D.DepthMode.PRE_DEPTH
383
                        : Renderer3D.DepthMode.NONE
384
        );
385
386
        if (mesh == null) return;
387
388
        worldShape.forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> {
389
            double x1 = minX - GEOMETRY_EXPAND;
390
            double y1 = minY - GEOMETRY_EXPAND;
391
            double z1 = minZ - GEOMETRY_EXPAND;
392
            double x2 = maxX + GEOMETRY_EXPAND;
393
            double y2 = maxY + GEOMETRY_EXPAND;
394
            double z2 = maxZ + GEOMETRY_EXPAND;
395
396
            addGradientBox(mesh, x1, y1, z1, x2, y2, z2);
397
        });
398
    }
399
400
    private void addGradientBox(MeshBuilder mesh,
401
                                double x1, double y1, double z1,
402
                                double x2, double y2, double z2) {
403
        int c000 = getOutlineColor(x1, y1, z1);
404
        int c001 = getOutlineColor(x1, y1, z2);
405
        int c010 = getOutlineColor(x1, y2, z1);
406
        int c011 = getOutlineColor(x1, y2, z2);
407
        int c100 = getOutlineColor(x2, y1, z1);
408
        int c101 = getOutlineColor(x2, y1, z2);
409
        int c110 = getOutlineColor(x2, y2, z1);
410
        int c111 = getOutlineColor(x2, y2, z2);
411
412
        addGradientQuad(mesh, x1, y1, z1, c000, x2, y1, z1, c100, x2, y2, z1, c110, x1, y2, z1, c010);
413
        addGradientQuad(mesh, x2, y1, z2, c101, x1, y1, z2, c001, x1, y2, z2, c011, x2, y2, z2, c111);
414
        addGradientQuad(mesh, x1, y1, z2, c001, x1, y1, z1, c000, x1, y2, z1, c010, x1, y2, z2, c011);
415
        addGradientQuad(mesh, x2, y1, z1, c100, x2, y1, z2, c101, x2, y2, z2, c111, x2, y2, z1, c110);
416
        addGradientQuad(mesh, x1, y2, z1, c010, x2, y2, z1, c110, x2, y2, z2, c111, x1, y2, z2, c011);
417
        addGradientQuad(mesh, x1, y1, z2, c001, x2, y1, z2, c101, x2, y1, z1, c100, x1, y1, z1, c000);
418
    }
419
420
    private void renderBreakingHighlight(Renderer3D renderer) {
421
        if (breakingSelf.get()) {
422
            renderSelfBreaking(renderer);
423
        }
424
425
        if (breakingOtherPlayers.get() && mc.level != null) {
426
            var destructionProgress = mc.level.destructionProgress();
427
            if (destructionProgress != null && !destructionProgress.isEmpty()) {
428
                destructionProgress.forEach((packedPos, infos) -> {
429
                    if (infos == null || infos.isEmpty()) {
430
                        return;
431
                    }
432
433
                    BlockDestructionProgress info = infos.last();
434
                    if (mc.player != null && info.getId() == mc.player.getId()) {
435
                        return;
436
                    }
437
438
                    renderBreakingInfo(renderer, info.getPos(), stageToProgress(info.getProgress()));
439
                });
440
            }
441
        }
442
    }
443
444
    private void renderSelfBreaking(Renderer3D renderer) {
445
        MultiPlayerGameMode interactionManager = mc.gameMode;
446
        if (interactionManager == null || !interactionManager.isDestroying()) return;
447
        if (!(interactionManager instanceof MultiPlayerGameModeAccessor accessor)) return;
448
449
        BlockPos pos = accessor.combatant$getCurrentBreakingPos();
450
        if (pos == null) return;
451
452
        float progress = Mth.clamp(accessor.combatant$getCurrentBreakingProgress(), 0.0f, 1.0f);
453
        renderBreakingInfo(renderer, pos, progress);
454
    }
455
456
    private void renderBreakingInfo(Renderer3D renderer, BlockPos pos, float progress) {
457
        if (mc.level == null || pos == null) return;
458
459
        BlockState state = mc.level.getBlockState(pos);
460
        if (state.isAir()) return;
461
462
        VoxelShape shape = state.getShape(mc.level, pos, CollisionContext.empty());
463
        if (shape.isEmpty()) return;
464
465
        float clamped = Mth.clamp(progress, 0.0f, 1.0f);
466
        int argb = interpolateArgb(breakingColor.getArgb(), breakingColor2.getArgb(), clamped);
467
468
        shape.move(pos.getX(), pos.getY(), pos.getZ()).forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> {
469
            AABB box = animateBox(new AABB(minX, minY, minZ, maxX, maxY, maxZ), clamped);
470
            if (isRenderable(box)) {
471
                addFilledBox(renderer, box, argb);
472
            }
473
        });
474
    }
475
476
    private AABB animateBox(AABB box, float progress) {
477
        double scale = switch (breakingAnimation.get()) {
478
            case GROW -> progress;
479
            case SHRINK -> 1.0 - progress;
480
            case STATIC -> 1.0;
481
        };
482
483
        scale = Mth.clamp((float) scale, 0.0f, 1.0f);
484
        if (scale >= 0.999f) {
485
            return box;
486
        }
487
488
        double cx = (box.minX + box.maxX) * 0.5;
489
        double cy = (box.minY + box.maxY) * 0.5;
490
        double cz = (box.minZ + box.maxZ) * 0.5;
491
        double hx = (box.maxX - box.minX) * 0.5 * scale;
492
        double hy = (box.maxY - box.minY) * 0.5 * scale;
493
        double hz = (box.maxZ - box.minZ) * 0.5 * scale;
494
495
        return new AABB(cx - hx, cy - hy, cz - hz, cx + hx, cy + hy, cz + hz);
496
    }
497
498
    private boolean isRenderable(AABB box) {
499
        return box.maxX - box.minX > 1.0e-4
500
                && box.maxY - box.minY > 1.0e-4
501
                && box.maxZ - box.minZ > 1.0e-4;
502
    }
503
504
    private int getOutlineColor(double x, double y, double z) {
505
        int base = outlineColor.getArgb();
506
        return AnimatedRenderColors.resolve(
507
                animatedOutlineColorMode(),
508
                outlineColorSpeed.get(),
509
                spatialIndex(x, y, z),
510
                base,
511
                outlineColor2.getArgb(),
512
                true
513
        );
514
    }
515
516
    private int spatialIndex(double x, double y, double z) {
517
        int xs = (int) Math.round(x * (RAINBOW_SPATIAL_SCALE + 1.0));
518
        int ys = (int) Math.round(y * (RAINBOW_SPATIAL_SCALE - 2.0));
519
        int zs = (int) Math.round(z * (RAINBOW_SPATIAL_SCALE + 3.0));
520
        return Math.floorMod(xs + ys + zs, 3600);
521
    }
522
523
    private boolean usesSecondaryOutlineColor() {
524
        if (!outlineEnabled.get()) return false;
525
        return AnimatedRenderColors.usesSecondary(animatedOutlineColorMode());
526
    }
527
528
    private AnimatedRenderColors.Mode animatedOutlineColorMode() {
529
        return switch (outlineColorMode.get()) {
530
            case RAINBOW -> AnimatedRenderColors.Mode.RAINBOW;
531
            case LIGHT_RAINBOW -> AnimatedRenderColors.Mode.LIGHT_RAINBOW;
532
            case SKY -> AnimatedRenderColors.Mode.SKY;
533
            case FADE -> AnimatedRenderColors.Mode.FADE;
534
            case DOUBLE_COLOR -> AnimatedRenderColors.Mode.DOUBLE_COLOR;
535
            case ANALOGOUS -> AnimatedRenderColors.Mode.ANALOGOUS;
536
            case THEME -> AnimatedRenderColors.Mode.THEME;
537
            case STATIC -> AnimatedRenderColors.Mode.STATIC;
538
        };
539
    }
540
541
    public enum ColorMode implements EnumValue.IdProvider {
542
        STATIC("static"),
543
        RAINBOW("rainbow"),
544
        LIGHT_RAINBOW("light_rainbow"),
545
        SKY("sky"),
546
        FADE("fade"),
547
        DOUBLE_COLOR("double_color"),
548
        ANALOGOUS("analogous"),
549
        THEME("theme");
550
551
        private final String id;
552
553
        ColorMode(String id) {
554
            this.id = id;
555
        }
556
557
        @Override
558
        public String id() {
559
            return id;
560
        }
561
    }
562
563
    public enum OutlineMode implements EnumValue.IdProvider {
564
        LINES("lines"),
565
        BOX("box"),
566
        BOTH("both");
567
568
        private final String id;
569
570
        OutlineMode(String id) {
571
            this.id = id;
572
        }
573
574
        @Override
575
        public String id() {
576
            return id;
577
        }
578
    }
579
580
    public enum BreakAnimation implements EnumValue.IdProvider {
581
        GROW("grow"),
582
        SHRINK("shrink"),
583
        STATIC("static");
584
585
        private final String id;
586
587
        BreakAnimation(String id) {
588
            this.id = id;
589
        }
590
591
        @Override
592
        public String id() {
593
            return id;
594
        }
595
    }
596
}
597