HoleESP module

HoleESP: Minecraft 26.3 cheat module, full source for every implementation (5 clients: MelaHack (ThunderHack fork), OfflineClient, Combatant, …).

5 implementationsRENDERVISUALSRender

Full module source: 5 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/HoleESP.javaJava · 190 lines · 8.2 KB

Highlights safe holes.

SettingsModeRange XYRange YIndestructibleBedrockHeightLine WidthCulling
HoleESP.javaJava · Minecraft 26.2 · 190 lines · 8.2 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.render;
2
3
import org.jetbrains.annotations.NotNull;
4
import thunder.hack.features.modules.Module;
5
import thunder.hack.setting.Setting;
6
import thunder.hack.setting.impl.ColorSetting;
7
import thunder.hack.utility.Timer;
8
import thunder.hack.utility.math.MathUtility;
9
import thunder.hack.utility.player.PlayerUtility;
10
import thunder.hack.utility.render.Render2DEngine;
11
import thunder.hack.utility.render.Render3DEngine;
12
import thunder.hack.utility.world.HoleUtility;
13
import com.mojang.blaze3d.vertex.PoseStack;
14
import java.awt.*;
15
import java.util.ArrayList;
16
import java.util.List;
17
import java.util.concurrent.CopyOnWriteArrayList;
18
import net.minecraft.core.BlockPos;
19
import net.minecraft.core.Direction;
20
import net.minecraft.world.phys.AABB;
21
22
public class HoleESP extends Module {
23
    public HoleESP() {
24
        super("HoleESP", Category.RENDER);
25
    }
26
27
    private final Setting<Mode> mode = new Setting<>("Mode", Mode.CubeOutline);
28
    private final Setting<Integer> rangeXZ = new Setting<>("Range XY", 10, 1, 128);
29
    private final Setting<Integer> rangeY = new Setting<>("Range Y", 5, 1, 128);
30
31
    private final Setting<ColorSetting> indestrictibleColor = new Setting<>("Indestructible", new ColorSetting(new Color(0x7A00FF).getRGB()));
32
    private final Setting<ColorSetting> bedrockColor = new Setting<>("Bedrock", new ColorSetting(new Color(0x00FF51).getRGB()));
33
34
    private final Setting<Float> height = new Setting<>("Height", 1f, 0.01f, 5f);
35
    private final Setting<Float> lineWith = new Setting<>("Line Width", 0.5f, 0.01f, 5f);
36
    public final Setting<Boolean> culling = new Setting<>("Culling", true, v -> mode.getValue() == Mode.Fade || mode.getValue() == Mode.Fade2);
37
38
    private final Timer logicTimer = new Timer();
39
    private final List<BoxWithColor> positions = new CopyOnWriteArrayList<>();
40
41
    @Override
42
    public void onDisable() {
43
        positions.clear();
44
    }
45
46
    @Override
47
    public void onRender3D(PoseStack stack) {
48
        if (positions.isEmpty()) return;
49
50
        for (BoxWithColor pwc : positions) {
51
            switch (mode.getValue()) {
52
                case Fade -> renderFade(pwc);
53
                case Fade2 -> renderFade2(pwc);
54
                case CubeFill -> renderFill(pwc);
55
                case CubeOutline -> renderOutline(pwc);
56
                case CubeBoth -> {
57
                    renderOutline(pwc);
58
                    renderFill(pwc);
59
                }
60
            }
61
        }
62
    }
63
64
    public void renderFade(@NotNull HoleESP.BoxWithColor posWithColor) {
65
        Render3DEngine.FADE_QUEUE.add(
66
                new Render3DEngine.FadeAction(posWithColor.box, getColor(posWithColor.box, posWithColor.color(), 60), getColor(posWithColor.box, posWithColor.color(), 0))
67
        );
68
        Render3DEngine.OUTLINE_SIDE_QUEUE.add(
69
                new Render3DEngine.OutlineSideAction(posWithColor.box, getColor(posWithColor.box, posWithColor.color(), posWithColor.color.getAlpha()), lineWith.getValue(), Direction.DOWN)
70
        );
71
    }
72
73
    public void renderFade2(@NotNull HoleESP.BoxWithColor boxWithColor) {
74
        Render3DEngine.FADE_QUEUE.add(
75
                new Render3DEngine.FadeAction(boxWithColor.box, getColor(boxWithColor.box, boxWithColor.color(), 60), getColor(boxWithColor.box, boxWithColor.color(), 0)
76
                ));
77
78
        Render3DEngine.drawHoleOutline(
79
                boxWithColor.box, getColor(boxWithColor.box, boxWithColor.color(), boxWithColor.color.getAlpha()), lineWith.getValue()
80
        );
81
82
        Render3DEngine.FILLED_QUEUE.add(
83
                new Render3DEngine.FillAction(new AABB(boxWithColor.box.minX, boxWithColor.box.minY, boxWithColor.box.minZ,
84
                        boxWithColor.box.maxX, boxWithColor.box.minY + 0.01f, boxWithColor.box.maxZ), getColor(boxWithColor.box, boxWithColor.color(), boxWithColor.color.getAlpha())
85
                )
86
        );
87
    }
88
89
    private Color getColor(AABB box, Color color, int alpha) {
90
        float dist = PlayerUtility.squaredDistance2d(box.getCenter().x(), box.getCenter().z());
91
        float factor = dist / (rangeXZ.getPow2Value());
92
93
        factor = 1f - easeOutExpo(factor);
94
95
        factor = MathUtility.clamp(factor, 0f, 1f);
96
97
        return Render2DEngine.injectAlpha(color, (int) (factor * alpha));
98
    }
99
100
    private float easeOutExpo(float x) {
101
        return x == 1f ? 1f : (float) (1f - Math.pow(2f, -10f * x));
102
    }
103
104
    public void renderOutline(@NotNull HoleESP.BoxWithColor boxWithColor) {
105
        Render3DEngine.OUTLINE_QUEUE.add(
106
                new Render3DEngine.OutlineAction(boxWithColor.box, getColor(boxWithColor.box, boxWithColor.color(), boxWithColor.color.getAlpha()), lineWith.getValue())
107
        );
108
    }
109
110
    public void renderFill(@NotNull HoleESP.BoxWithColor boxWithColor) {
111
        Render3DEngine.FILLED_QUEUE.add(
112
                new Render3DEngine.FillAction(boxWithColor.box(), getColor(boxWithColor.box, boxWithColor.color(), boxWithColor.color.getAlpha()))
113
        );
114
    }
115
116
    @Override
117
    public void onThread() {
118
        if (fullNullCheck() || !logicTimer.passedMs(500))
119
            return;
120
        findHoles();
121
        logicTimer.reset();
122
    }
123
124
    private void findHoles() {
125
        ArrayList<BoxWithColor> blocks = new ArrayList<>();
126
        if (mc.level == null || mc.player == null) {
127
            positions.clear();
128
            return;
129
        }
130
        BlockPos centerPos = BlockPos.containing(mc.player.position());
131
        List<AABB> boxes = new ArrayList<>();
132
133
        for (int i = centerPos.getX() - rangeXZ.getValue(); i < centerPos.getX() + rangeXZ.getValue(); i++) {
134
            for (int j = centerPos.getY() - rangeY.getValue(); j < centerPos.getY() + rangeY.getValue(); j++) {
135
                for (int k = centerPos.getZ() - rangeXZ.getValue(); k < centerPos.getZ() + rangeXZ.getValue(); k++) {
136
                    BlockPos pos = new BlockPos(i, j, k);
137
                    AABB box = new AABB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + height.getValue(), pos.getZ() + 1);
138
                    Color color = indestrictibleColor.getValue().getColorObject();
139
                    if (HoleUtility.validIndestructible(pos)) {
140
141
                    } else if (HoleUtility.validBedrock(pos)) {
142
                        color = bedrockColor.getValue().getColorObject();
143
                    } else if (HoleUtility.validTwoBlockBedrock(pos)) {
144
                        boolean east = mc.level.isEmptyBlock(pos.relative(Direction.EAST));
145
                        boolean south = mc.level.isEmptyBlock(pos.relative(Direction.SOUTH));
146
                        box = new AABB(box.minX, box.minY, box.minZ, box.maxX + (east ? 1 : 0), box.maxY, box.maxZ + (south ? 1 : 0));
147
                        color = bedrockColor.getValue().getColorObject();
148
                    } else if (HoleUtility.validTwoBlockIndestructible(pos)) {
149
                        boolean east = mc.level.isEmptyBlock(pos.relative(Direction.EAST));
150
                        boolean south = mc.level.isEmptyBlock(pos.relative(Direction.SOUTH));
151
                        box = new AABB(box.minX, box.minY, box.minZ, box.maxX + (east ? 1 : 0), box.maxY, box.maxZ + (south ? 1 : 0));
152
                    } else if (HoleUtility.validQuadBedrock(pos)) {
153
                        box = new AABB(box.minX, box.minY, box.minZ, box.maxX + 1, box.maxY, box.maxZ + 1);
154
                        color = bedrockColor.getValue().getColorObject();
155
                    } else if (HoleUtility.validQuadIndestructible(pos)) {
156
                        box = new AABB(box.minX, box.minY, box.minZ, box.maxX + 1, box.maxY, box.maxZ + 1);
157
                    } else {
158
                        continue;
159
                    }
160
161
                    boolean skip = false;
162
                    for (AABB boxOffset : boxes) {
163
                        if (boxOffset.intersects(box))
164
                            skip = true;
165
                    }
166
167
                    if (skip)
168
                        continue;
169
170
                    blocks.add(new BoxWithColor(box, color));
171
                    boxes.add(box);
172
                }
173
            }
174
        }
175
        positions.clear();
176
        positions.addAll(blocks);
177
    }
178
179
    public record BoxWithColor(AABB box, Color color) {
180
    }
181
182
    private enum Mode {
183
        Fade,
184
        Fade2,
185
        CubeOutline,
186
        CubeFill,
187
        CubeBoth
188
    }
189
}
190
OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/HoleEsp.javaJava · 283 lines · 11.0 KB

Highlights safe holes to stand in.

SettingsHorizontal rangeVertical rangeMin heightDoublesIgnore ownWebsRefreshHeightTop faceBottom faceBedrock topBedrock bottomObsidian topObsidian bottomMixed topMixed bottomThrough walls
HoleEsp.javaJava · Minecraft 26.2 · 283 lines · 11.0 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.render;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.Render3DEvent;
5
import com.jellypudding.offlineclient.event.events.TickEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.Module;
8
import com.jellypudding.offlineclient.render.BoxStyle;
9
import com.jellypudding.offlineclient.render.DrawBatch;
10
import com.jellypudding.offlineclient.setting.BoolSetting;
11
import com.jellypudding.offlineclient.setting.ColorSetting;
12
import com.jellypudding.offlineclient.setting.NumberSetting;
13
import com.jellypudding.offlineclient.util.BlockUtil;
14
import com.jellypudding.offlineclient.util.ColorUtil;
15
import net.minecraft.core.BlockPos;
16
import net.minecraft.core.Direction;
17
import net.minecraft.world.level.block.Block;
18
import net.minecraft.world.level.block.Blocks;
19
import net.minecraft.world.level.block.state.BlockState;
20
import net.minecraft.world.phys.AABB;
21
22
import java.util.ArrayList;
23
import java.util.HashSet;
24
import java.util.List;
25
import java.util.Set;
26
27
// Finds one block wide holes walled in bedrock or obsidian. Those survive crystal blasts.
28
public final class HoleEsp extends Module {
29
30
    private enum Wall {
31
        BEDROCK,
32
        OBSIDIAN,
33
        MIXED
34
    }
35
36
    private record Hole(AABB box, Wall wall) {
37
    }
38
39
    // Reused by every column test. One scan probes thousands of positions.
40
    private final BlockPos.MutableBlockPos probe = new BlockPos.MutableBlockPos();
41
    private final BlockPos.MutableBlockPos under = new BlockPos.MutableBlockPos();
42
43
    private final NumberSetting horizontal = new NumberSetting("Horizontal range",
44
        "How far sideways to look for holes.", 8, 1, 16, 1, " blocks").max(32);
45
    private final NumberSetting vertical = new NumberSetting("Vertical range",
46
        "How far up and down to look for holes.", 4, 1, 16, 1, " blocks").max(64);
47
    private final NumberSetting minHeight = new NumberSetting("Min height",
48
        "How many air blocks the hole must have above its floor.", 3, 1, 5, 1).min(1);
49
    private final BoolSetting doubles = new BoolSetting("Doubles",
50
        "Also show two block wide holes you can stand across.", true);
51
    private final BoolSetting ignoreOwn = new BoolSetting("Ignore own",
52
        "Hide the hole you are standing in.", false);
53
    private final BoolSetting webs = new BoolSetting("Webs",
54
        "Count holes that have cobwebs in them.", false);
55
    private final NumberSetting refresh = new NumberSetting("Refresh",
56
        "Ticks between scans.", 2, 1, 20, 1, " ticks").min(1);
57
    private final NumberSetting height = new NumberSetting("Height",
58
        "How tall the drawn box is.", 0.3, 0.1, 1, 0.1).min(0.05);
59
    private final BoxStyle style = BoxStyle.shapeOnly(BoxStyle.Shape.BOTH);
60
    private final BoolSetting topFace = new BoolSetting("Top face",
61
        "Tint the top of each box.", true).visibleWhen(style::drawsSides);
62
    private final BoolSetting bottomFace = new BoolSetting("Bottom face",
63
        "Tint the floor of each box.", false).visibleWhen(style::drawsSides);
64
    private final ColorSetting bedrockTop = new ColorSetting("Bedrock top",
65
        "Colour at the top of a bedrock hole.", 96, 1f, 1f, false);
66
    private final ColorSetting bedrockBottom = new ColorSetting("Bedrock bottom",
67
        "Colour the sides of a bedrock hole fade down to.", 96, 1f, 1f, false);
68
    private final ColorSetting obsidianTop = new ColorSetting("Obsidian top",
69
        "Colour at the top of an obsidian hole.", 0, 1f, 1f, false);
70
    private final ColorSetting obsidianBottom = new ColorSetting("Obsidian bottom",
71
        "Colour the sides of an obsidian hole fade down to.", 0, 1f, 1f, false);
72
    private final ColorSetting mixedTop = new ColorSetting("Mixed top",
73
        "Colour at the top of a hole walled in bedrock and obsidian.", 30, 1f, 1f, false);
74
    private final ColorSetting mixedBottom = new ColorSetting("Mixed bottom",
75
        "Colour the sides of a mixed hole fade down to.", 30, 1f, 1f, false);
76
    private final BoolSetting throughWalls = new BoolSetting("Through walls",
77
        "Show holes behind blocks.", true);
78
79
    private final List<Hole> holes = new ArrayList<>();
80
    private int timer;
81
82
    public HoleEsp() {
83
        super("HoleESP", "Highlights safe holes to stand in.", Category.RENDER);
84
        addSettings(horizontal, vertical, minHeight, doubles, ignoreOwn, webs, refresh, height);
85
        addSettings(style.settings());
86
        addSettings(topFace, bottomFace, bedrockTop, bedrockBottom, obsidianTop, obsidianBottom,
87
            mixedTop, mixedBottom, throughWalls);
88
        searchTags("bedrock", "obsidian", "crystal");
89
    }
90
91
    @Override
92
    public String getSuffix() {
93
        return count(holes.size());
94
    }
95
96
    @Override
97
    protected void onEnable() {
98
        timer = 0;
99
        holes.clear();
100
    }
101
102
    @Override
103
    protected void onDisable() {
104
        holes.clear();
105
    }
106
107
    @Subscribe
108
    private void onTick(TickEvent event) {
109
        if (!inGame()) {
110
            holes.clear();
111
            return;
112
        }
113
        if (timer > 0) {
114
            timer--;
115
            return;
116
        }
117
        timer = refresh.getInt();
118
        scan();
119
    }
120
121
    private void scan() {
122
        holes.clear();
123
        BlockPos center = mc.player.blockPosition();
124
        int h = horizontal.getInt();
125
        int v = vertical.getInt();
126
        BlockPos.MutableBlockPos cursor = new BlockPos.MutableBlockPos();
127
        Set<BlockPos> seen = new HashSet<>();
128
129
        for (int dx = -h; dx <= h; dx++) {
130
            for (int dz = -h; dz <= h; dz++) {
131
                for (int dy = -v; dy <= v; dy++) {
132
                    cursor.set(center.getX() + dx, center.getY() + dy, center.getZ() + dz);
133
                    // A blast proof floor is rare.
134
                    if (wallAt(under.setWithOffset(cursor, Direction.DOWN)) == null) {
135
                        continue;
136
                    }
137
                    if (!isOpen(cursor)) {
138
                        continue;
139
                    }
140
                    if ((ignoreOwn.isOn() && cursor.equals(center)) || seen.contains(cursor)) {
141
                        continue;
142
                    }
143
                    check(cursor.immutable(), seen);
144
                }
145
            }
146
        }
147
    }
148
149
    // Every side but the top must be bedrock or obsidian.
150
    // One side may be an open block for a double hole if its own sides are safe too.
151
    private void check(BlockPos pos, Set<BlockPos> seen) {
152
        int bedrock = 0;
153
        int obsidian = 0;
154
        BlockPos partner = null;
155
156
        for (Direction side : Direction.values()) {
157
            if (side == Direction.UP) {
158
                continue;
159
            }
160
            BlockPos next = pos.relative(side);
161
            Wall wall = wallAt(next);
162
            if (wall == Wall.BEDROCK) {
163
                bedrock++;
164
            } else if (wall == Wall.OBSIDIAN) {
165
                obsidian++;
166
            } else if (side == Direction.DOWN || partner != null || !doubles.isOn() || !isOpen(next)) {
167
                return;
168
            } else {
169
                // The other half of a double hole.
170
                for (Direction other : Direction.values()) {
171
                    if (other == Direction.UP || other == side.getOpposite()) {
172
                        continue;
173
                    }
174
                    Wall otherWall = wallAt(next.relative(other));
175
                    if (otherWall == Wall.BEDROCK) {
176
                        bedrock++;
177
                    } else if (otherWall == Wall.OBSIDIAN) {
178
                        obsidian++;
179
                    } else {
180
                        return;
181
                    }
182
                }
183
                partner = next;
184
            }
185
        }
186
187
        int total = bedrock + obsidian;
188
        if (partner == null && total != 5) {
189
            return;
190
        }
191
        if (partner != null && total != 8) {
192
            return;
193
        }
194
195
        Wall kind = obsidian == 0 ? Wall.BEDROCK : bedrock == 0 ? Wall.OBSIDIAN : Wall.MIXED;
196
        double top = height.getValue();
197
        AABB box = new AABB(pos.getX(), pos.getY(), pos.getZ(),
198
            pos.getX() + 1, pos.getY() + top, pos.getZ() + 1);
199
        if (partner != null) {
200
            box = box.minmax(new AABB(partner.getX(), partner.getY(), partner.getZ(),
201
                partner.getX() + 1, partner.getY() + top, partner.getZ() + 1));
202
            seen.add(partner);
203
        }
204
        seen.add(pos);
205
        holes.add(new Hole(box, kind));
206
    }
207
208
    // The block and the ones above it must have no collision.
209
    private boolean isOpen(BlockPos pos) {
210
        int needed = minHeight.getInt();
211
        BlockPos.MutableBlockPos cursor = probe;
212
        for (int i = 0; i < needed; i++) {
213
            cursor.set(pos.getX(), pos.getY() + i, pos.getZ());
214
            BlockState state = mc.level.getBlockState(cursor);
215
            if (state.getBlock() == Blocks.COBWEB) {
216
                if (!webs.isOn()) {
217
                    return false;
218
                }
219
                continue;
220
            }
221
            if (!state.getCollisionShape(mc.level, cursor).isEmpty()) {
222
                return false;
223
            }
224
        }
225
        return true;
226
    }
227
228
    // Null for blocks that do not survive a crystal.
229
    private Wall wallAt(BlockPos pos) {
230
        BlockState state = mc.level.getBlockState(pos);
231
        Block block = state.getBlock();
232
        boolean breakable = block.defaultDestroyTime() >= 0;
233
        if (!breakable && BlockUtil.blocksMotion(state)) {
234
            return Wall.BEDROCK;
235
        }
236
        if (breakable && block.getExplosionResistance() >= BlockUtil.BLAST_PROOF && BlockUtil.blocksMotion(state)) {
237
            return Wall.OBSIDIAN;
238
        }
239
        return null;
240
    }
241
242
    @Subscribe
243
    private void onRender3D(Render3DEvent event) {
244
        DrawBatch batch = event.getBatch();
245
        boolean through = throughWalls.isOn();
246
        float share = style.fillShare();
247
        for (Hole hole : holes) {
248
            int top = topColor(hole.wall());
249
            int bottom = bottomColor(hole.wall());
250
            AABB box = hole.box();
251
            if (style.drawsSides()) {
252
                batch.gradientSides(box, ColorUtil.fade(bottom, 0), ColorUtil.fade(top, share), through);
253
                if (topFace.isOn()) {
254
                    batch.solidFace(box, Direction.UP, ColorUtil.fade(top, share), through);
255
                }
256
                if (bottomFace.isOn()) {
257
                    batch.solidFace(box, Direction.DOWN, ColorUtil.fade(bottom, share), through);
258
                }
259
            }
260
            if (style.drawsLines()) {
261
                batch.outlineBox(box, top, through);
262
                batch.outlineFace(box, Direction.DOWN, bottom, through);
263
            }
264
        }
265
    }
266
267
    private int topColor(Wall wall) {
268
        return switch (wall) {
269
            case BEDROCK -> bedrockTop.getColor();
270
            case OBSIDIAN -> obsidianTop.getColor();
271
            case MIXED -> mixedTop.getColor();
272
        };
273
    }
274
275
    private int bottomColor(Wall wall) {
276
        return switch (wall) {
277
            case BEDROCK -> bedrockBottom.getColor();
278
            case OBSIDIAN -> obsidianBottom.getColor();
279
            case MIXED -> mixedBottom.getColor();
280
        };
281
    }
282
}
283
CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/HoleESP.javaJava · 491 lines · 19.3 KB

Highlights safe holes with a distance-faded fill.

Settingsholeesp_range_xzholeesp_range_yholeesp_heightholeesp_line_widthholeesp_cullingholeesp_indestructible_colorholeesp_bedrock_color
HoleESP.javaJava · Minecraft 26.2 · 491 lines · 19.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 combatant.client.config.values.BooleanValue;
11
import combatant.client.config.values.NumberValue;
12
import combatant.client.config.values.RGBAColorValue;
13
import combatant.client.features.module.Module;
14
import combatant.client.features.module.ModuleCategory;
15
import combatant.client.features.module.ModuleInfo;
16
import combatant.client.features.module.WorldPhase;
17
import combatant.client.render.engine.RenderState;
18
import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
19
import combatant.client.render.engine.renderer.Renderer3D;
20
import combatant.client.render.engine.uniform.MeshBuilder;
21
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
22
import net.minecraft.client.Minecraft;
23
import net.minecraft.client.multiplayer.ClientLevel;
24
import net.minecraft.core.BlockPos;
25
import net.minecraft.core.Direction;
26
import net.minecraft.util.Mth;
27
import net.minecraft.world.level.block.Block;
28
import net.minecraft.world.level.block.Blocks;
29
import net.minecraft.world.level.block.state.BlockState;
30
import net.minecraft.world.phys.AABB;
31
import net.minecraft.world.phys.Vec3;
32
33
import java.util.ArrayList;
34
import java.util.List;
35
36
@ModuleInfo(
37
        id = "holeesp",
38
        displayName = "HoleESP",
39
        aliases = {"holes"},
40
        category = ModuleCategory.VISUALS,
41
        description = "module.holeesp.description"
42
)
43
public final class HoleESP extends Module {
44
    private static final Direction[] HORIZONTAL = {
45
            Direction.NORTH,
46
            Direction.SOUTH,
47
            Direction.EAST,
48
            Direction.WEST
49
    };
50
    private static final int RESCAN_TICKS = 10;
51
    private static final int BASE_FILL_ALPHA = 60;
52
53
    private final Minecraft mc = Minecraft.getInstance();
54
55
    private final NumberValue<Integer> rangeXZ =
56
            num("holeesp_range_xz", "range_xz", 10, 1, 128);
57
    private final NumberValue<Integer> rangeY =
58
            num("holeesp_range_y", "range_y", 5, 1, 128);
59
    private final NumberValue<Float> height =
60
            num("holeesp_height", "height", 1.0f, 0.01f, 5.0f);
61
    private final NumberValue<Float> lineWidth =
62
            num("holeesp_line_width", "line_width", 0.5f, 0.01f, 5.0f);
63
    private final BooleanValue culling =
64
            bool("holeesp_culling", "culling", true);
65
    private final RGBAColorValue indestructibleColor =
66
            color("holeesp_indestructible_color", "indestructible_color", "#FF7A00FF");
67
    private final RGBAColorValue bedrockColor =
68
            color("holeesp_bedrock_color", "bedrock_color", "#FF00FF51");
69
70
    private List<Hole> holes = List.of();
71
    private int ticks;
72
73
    @Override
74
    public void onDisable() {
75
        holes = List.of();
76
        ticks = 0;
77
    }
78
79
    @Override
80
    public void onTick() {
81
        if (!isEnabled() || mc.level == null || mc.player == null) {
82
            holes = List.of();
83
            return;
84
        }
85
86
        if (ticks++ % RESCAN_TICKS == 0) {
87
            holes = scanHoles(mc.level, mc.player.position());
88
        }
89
    }
90
91
    @Override
92
    public WorldPhase getWorldPhase() {
93
        return WorldPhase.END_MAIN;
94
    }
95
96
    @Override
97
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
98
        if (!isEnabled() || renderer == null || mc.level == null || mc.player == null || holes.isEmpty()) {
99
            return;
100
        }
101
102
        float previousLineWidth = RenderState.lineWidth;
103
        RenderState.lineWidth = Math.max(0.01f, lineWidth.get());
104
        try {
105
            for (Hole hole : holes) {
106
                if (culling.get() && !shouldRender(hole.box())) {
107
                    continue;
108
                }
109
                renderFade(renderer, hole);
110
            }
111
        } finally {
112
            RenderState.lineWidth = previousLineWidth;
113
        }
114
    }
115
116
    private List<Hole> scanHoles(ClientLevel level, Vec3 center) {
117
        int xz = rangeXZ.get();
118
        int y = rangeY.get();
119
        List<Hole> found = new ArrayList<>();
120
        List<AABB> acceptedBoxes = new ArrayList<>();
121
        LongOpenHashSet consumed = new LongOpenHashSet();
122
123
        int minX = Mth.floor(center.x - xz);
124
        int minY = Math.max(level.getMinY(), Mth.floor(center.y - y));
125
        int minZ = Mth.floor(center.z - xz);
126
        int maxX = Mth.floor(center.x + xz);
127
        int maxY = Math.min(level.getMaxY() - 1, Mth.floor(center.y + y));
128
        int maxZ = Mth.floor(center.z + xz);
129
        BlockPos.MutableBlockPos cursor = new BlockPos.MutableBlockPos();
130
        BlockPos.MutableBlockPos floor = new BlockPos.MutableBlockPos();
131
132
        /*
133
         * Do not materialize the whole search cuboid as BlockPos + entry objects. Most
134
         * positions are impossible candidates because their floor is not a safe block, so
135
         * reject those using two reusable cursors before allocating an immutable position.
136
         */
137
        for (int x = minX; x <= maxX; x++) {
138
            if (Math.abs((x + 0.5) - center.x) > xz) continue;
139
            for (int z = minZ; z <= maxZ; z++) {
140
                if (Math.abs((z + 0.5) - center.z) > xz) continue;
141
                for (int scanY = minY; scanY <= maxY; scanY++) {
142
                    if (Math.abs((scanY + 0.5) - center.y) > y) continue;
143
                    cursor.set(x, scanY, z);
144
                    if (!isReplaceable(level.getBlockState(cursor))) continue;
145
146
                    floor.set(x, scanY - 1, z);
147
                    if (!isSafeBlock(level, floor)) continue;
148
149
                    long packed = cursor.asLong();
150
                    if (consumed.contains(packed)) continue;
151
152
                    BlockPos pos = cursor.immutable();
153
                    Hole hole = resolveHole(level, pos);
154
                    if (hole == null || intersectsAny(hole.box(), acceptedBoxes)) continue;
155
156
                    found.add(hole);
157
                    acceptedBoxes.add(hole.box());
158
                    for (BlockPos holePos : hole.positions()) {
159
                        consumed.add(holePos.asLong());
160
                    }
161
                }
162
            }
163
        }
164
165
        return List.copyOf(found);
166
    }
167
168
    private Hole resolveHole(ClientLevel level, BlockPos pos) {
169
        if (validIndestructible(level, pos)) {
170
            return new Hole(box(pos, 1, 1), indestructibleColor.getArgb(), List.of(pos));
171
        }
172
        if (validBedrock(level, pos)) {
173
            return new Hole(box(pos, 1, 1), bedrockColor.getArgb(), List.of(pos));
174
        }
175
176
        List<BlockPos> two = twoBlockShape(level, pos);
177
        if (two != null) {
178
            if (validBedrockShape(level, two)) {
179
                return new Hole(box(two), bedrockColor.getArgb(), two);
180
            }
181
            if (validIndestructibleShape(level, two)) {
182
                return new Hole(box(two), indestructibleColor.getArgb(), two);
183
            }
184
        }
185
186
        List<BlockPos> quad = quadShape(level, pos);
187
        if (quad != null) {
188
            if (validBedrockShape(level, quad)) {
189
                return new Hole(box(quad), bedrockColor.getArgb(), quad);
190
            }
191
            if (validIndestructibleShape(level, quad)) {
192
                return new Hole(box(quad), indestructibleColor.getArgb(), quad);
193
            }
194
        }
195
196
        return null;
197
    }
198
199
    private void renderFade(Renderer3D renderer, Hole hole) {
200
        AABB box = hole.box();
201
        int fillBottom = colorForDistance(box, hole.argb(), BASE_FILL_ALPHA);
202
        int fillTop = colorForDistance(box, hole.argb(), 0);
203
        int line = colorForDistance(box, hole.argb(), (hole.argb() >>> 24) & 0xFF);
204
205
        addVerticalFadeBox(renderer, box, fillBottom, fillTop);
206
        addBottomOutline(renderer, box, line);
207
    }
208
209
    private int colorForDistance(AABB box, int argb, int alpha) {
210
        Vec3 center = box.getCenter();
211
        double dx = center.x - mc.player.getX();
212
        double dz = center.z - mc.player.getZ();
213
        double distSqr = dx * dx + dz * dz;
214
        double maxSqr = Math.max(1.0, (double) rangeXZ.get() * rangeXZ.get());
215
        float factor = (float) (distSqr / maxSqr);
216
        factor = 1.0f - easeOutExpo(factor);
217
        factor = Mth.clamp(factor, 0.0f, 1.0f);
218
219
        int baseAlpha = (argb >>> 24) & 0xFF;
220
        int outAlpha = Mth.clamp((int) (factor * Math.min(alpha, baseAlpha)), 0, 255);
221
        return (outAlpha << 24) | (argb & 0x00FFFFFF);
222
    }
223
224
    private static float easeOutExpo(float x) {
225
        return x >= 1.0f ? 1.0f : (float) (1.0f - Math.pow(2.0, -10.0f * x));
226
    }
227
228
    private static boolean shouldRender(AABB box) {
229
        return Renderer3D.Culling.isInFrustum(box) && Renderer3D.Culling.isSectionVisible(box);
230
    }
231
232
    private static boolean intersectsAny(AABB box, List<AABB> boxes) {
233
        for (AABB other : boxes) {
234
            if (other.intersects(box)) {
235
                return true;
236
            }
237
        }
238
        return false;
239
    }
240
241
    private AABB box(BlockPos pos, int widthX, int widthZ) {
242
        return new AABB(
243
                pos.getX(),
244
                pos.getY(),
245
                pos.getZ(),
246
                pos.getX() + widthX,
247
                pos.getY() + height.get(),
248
                pos.getZ() + widthZ
249
        );
250
    }
251
252
    private AABB box(List<BlockPos> positions) {
253
        int minX = Integer.MAX_VALUE;
254
        int minY = Integer.MAX_VALUE;
255
        int minZ = Integer.MAX_VALUE;
256
        int maxX = Integer.MIN_VALUE;
257
        int maxZ = Integer.MIN_VALUE;
258
259
        for (BlockPos pos : positions) {
260
            minX = Math.min(minX, pos.getX());
261
            minY = Math.min(minY, pos.getY());
262
            minZ = Math.min(minZ, pos.getZ());
263
            maxX = Math.max(maxX, pos.getX());
264
            maxZ = Math.max(maxZ, pos.getZ());
265
        }
266
267
        return new AABB(minX, minY, minZ, maxX + 1, minY + height.get(), maxZ + 1);
268
    }
269
270
    private static List<BlockPos> twoBlockShape(ClientLevel level, BlockPos pos) {
271
        if (!isReplaceable(level, pos)) {
272
            return null;
273
        }
274
        for (Direction direction : HORIZONTAL) {
275
            BlockPos other = pos.relative(direction);
276
            if (isReplaceable(level, other)) {
277
                return List.of(pos, other);
278
            }
279
        }
280
        return null;
281
    }
282
283
    private static List<BlockPos> quadShape(ClientLevel level, BlockPos pos) {
284
        if (!isReplaceable(level, pos)) {
285
            return null;
286
        }
287
288
        List<BlockPos> eastSouth = quadIfReplaceable(level, pos, pos.east(), pos.south(), pos.east().south());
289
        if (eastSouth != null) return eastSouth;
290
291
        List<BlockPos> westNorth = quadIfReplaceable(level, pos, pos.west(), pos.north(), pos.west().north());
292
        if (westNorth != null) return westNorth;
293
294
        List<BlockPos> eastNorth = quadIfReplaceable(level, pos, pos.east(), pos.north(), pos.east().north());
295
        if (eastNorth != null) return eastNorth;
296
297
        return quadIfReplaceable(level, pos, pos.west(), pos.south(), pos.west().south());
298
    }
299
300
    private static List<BlockPos> quadIfReplaceable(ClientLevel level, BlockPos a, BlockPos b, BlockPos c, BlockPos d) {
301
        if (isReplaceable(level, b) && isReplaceable(level, c) && isReplaceable(level, d)) {
302
            return List.of(a, b, c, d);
303
        }
304
        return null;
305
    }
306
307
    private static boolean validBedrock(ClientLevel level, BlockPos pos) {
308
        return isBedrock(level, pos.below())
309
                && isBedrock(level, pos.east())
310
                && isBedrock(level, pos.west())
311
                && isBedrock(level, pos.south())
312
                && isBedrock(level, pos.north())
313
                && isReplaceable(level, pos)
314
                && isReplaceable(level, pos.above())
315
                && isReplaceable(level, pos.above(2));
316
    }
317
318
    private static boolean validIndestructible(ClientLevel level, BlockPos pos) {
319
        // resolveHole() has already rejected the all-bedrock variant.
320
        return isSafeBlock(level, pos.below())
321
                && isSafeBlock(level, pos.east())
322
                && isSafeBlock(level, pos.west())
323
                && isSafeBlock(level, pos.south())
324
                && isSafeBlock(level, pos.north())
325
                && isReplaceable(level, pos)
326
                && isReplaceable(level, pos.above())
327
                && isReplaceable(level, pos.above(2));
328
    }
329
330
    private static boolean validBedrockShape(ClientLevel level, List<BlockPos> positions) {
331
        for (BlockPos check : positions) {
332
            if (!isReplaceable(level, check) || !isReplaceable(level, check.above()) || !isReplaceable(level, check.above(2))) {
333
                return false;
334
            }
335
            if (!isBedrock(level, check.below())) {
336
                return false;
337
            }
338
            for (Direction direction : HORIZONTAL) {
339
                BlockPos surround = check.relative(direction);
340
                if (!positions.contains(surround) && !isBedrock(level, surround)) {
341
                    return false;
342
                }
343
            }
344
        }
345
        return true;
346
    }
347
348
    private static boolean validIndestructibleShape(ClientLevel level, List<BlockPos> positions) {
349
        boolean hasIndestructible = false;
350
        for (BlockPos check : positions) {
351
            if (!isReplaceable(level, check) || !isReplaceable(level, check.above()) || !isReplaceable(level, check.above(2))) {
352
                return false;
353
            }
354
355
            BlockPos below = check.below();
356
            if (isIndestructible(level, below)) {
357
                hasIndestructible = true;
358
            } else if (!isBedrock(level, below)) {
359
                return false;
360
            }
361
362
            for (Direction direction : HORIZONTAL) {
363
                BlockPos surround = check.relative(direction);
364
                if (positions.contains(surround)) {
365
                    continue;
366
                }
367
                if (isIndestructible(level, surround)) {
368
                    hasIndestructible = true;
369
                } else if (!isBedrock(level, surround)) {
370
                    return false;
371
                }
372
            }
373
        }
374
        return hasIndestructible;
375
    }
376
377
    private static boolean isSafeBlock(ClientLevel level, BlockPos pos) {
378
        return isBedrock(level, pos) || isIndestructible(level, pos);
379
    }
380
381
    private static boolean isBedrock(ClientLevel level, BlockPos pos) {
382
        return level != null && block(level, pos) == Blocks.BEDROCK;
383
    }
384
385
    private static boolean isIndestructible(ClientLevel level, BlockPos pos) {
386
        Block block = block(level, pos);
387
        return block == Blocks.OBSIDIAN
388
                || block == Blocks.NETHERITE_BLOCK
389
                || block == Blocks.CRYING_OBSIDIAN
390
                || block == Blocks.RESPAWN_ANCHOR;
391
    }
392
393
    private static boolean isReplaceable(ClientLevel level, BlockPos pos) {
394
        if (level == null || pos == null || pos.getY() < level.getMinY() || pos.getY() >= level.getMaxY()) {
395
            return false;
396
        }
397
        return isReplaceable(level.getBlockState(pos));
398
    }
399
400
    private static boolean isReplaceable(BlockState state) {
401
        return state.isAir() || state.canBeReplaced() || !state.getFluidState().isEmpty();
402
    }
403
404
    private static Block block(ClientLevel level, BlockPos pos) {
405
        if (level == null || pos == null || pos.getY() < level.getMinY() || pos.getY() >= level.getMaxY()) {
406
            return Blocks.AIR;
407
        }
408
        return level.getBlockState(pos).getBlock();
409
    }
410
411
    private static void addVerticalFadeBox(Renderer3D renderer, AABB box, int bottomArgb, int topArgb) {
412
        MeshBuilder mesh = renderer.batch(CombatantRenderPipelines.WORLD_COLORED, Renderer3D.DepthMode.MAIN);
413
        if (mesh == null) {
414
            return;
415
        }
416
417
        int bottomA = (bottomArgb >>> 24) & 0xFF;
418
        int bottomR = (bottomArgb >>> 16) & 0xFF;
419
        int bottomG = (bottomArgb >>> 8) & 0xFF;
420
        int bottomB = bottomArgb & 0xFF;
421
        int topA = (topArgb >>> 24) & 0xFF;
422
        int topR = (topArgb >>> 16) & 0xFF;
423
        int topG = (topArgb >>> 8) & 0xFF;
424
        int topB = topArgb & 0xFF;
425
426
        addGradientQuad(mesh, box.minX, box.minY, box.maxZ, box.maxX, box.minY, box.maxZ,
427
                box.maxX, box.maxY, box.maxZ, box.minX, box.maxY, box.maxZ,
428
                bottomR, bottomG, bottomB, bottomA, topR, topG, topB, topA);
429
        addGradientQuad(mesh, box.minX, box.minY, box.minZ, box.minX, box.maxY, box.minZ,
430
                box.maxX, box.maxY, box.minZ, box.maxX, box.minY, box.minZ,
431
                bottomR, bottomG, bottomB, bottomA, topR, topG, topB, topA);
432
        addGradientQuad(mesh, box.maxX, box.minY, box.minZ, box.maxX, box.maxY, box.minZ,
433
                box.maxX, box.maxY, box.maxZ, box.maxX, box.minY, box.maxZ,
434
                bottomR, bottomG, bottomB, bottomA, topR, topG, topB, topA);
435
        addGradientQuad(mesh, box.minX, box.minY, box.minZ, box.minX, box.minY, box.maxZ,
436
                box.minX, box.maxY, box.maxZ, box.minX, box.maxY, box.minZ,
437
                bottomR, bottomG, bottomB, bottomA, topR, topG, topB, topA);
438
    }
439
440
    private static void addGradientQuad(MeshBuilder mesh,
441
                                        double x1, double y1, double z1,
442
                                        double x2, double y2, double z2,
443
                                        double x3, double y3, double z3,
444
                                        double x4, double y4, double z4,
445
                                        int bottomR, int bottomG, int bottomB, int bottomA,
446
                                        int topR, int topG, int topB, int topA) {
447
        mesh.ensureQuadCapacity();
448
        double minY = Math.min(Math.min(y1, y2), Math.min(y3, y4));
449
        double maxY = Math.max(Math.max(y1, y2), Math.max(y3, y4));
450
        double midY = (minY + maxY) * 0.5;
451
        int i1 = fadeVertex(mesh, x1, y1, z1, midY, bottomR, bottomG, bottomB, bottomA, topR, topG, topB, topA);
452
        int i2 = fadeVertex(mesh, x2, y2, z2, midY, bottomR, bottomG, bottomB, bottomA, topR, topG, topB, topA);
453
        int i3 = fadeVertex(mesh, x3, y3, z3, midY, bottomR, bottomG, bottomB, bottomA, topR, topG, topB, topA);
454
        int i4 = fadeVertex(mesh, x4, y4, z4, midY, bottomR, bottomG, bottomB, bottomA, topR, topG, topB, topA);
455
        mesh.quad(i1, i2, i3, i4);
456
    }
457
458
    private static int fadeVertex(MeshBuilder mesh,
459
                                  double x, double y, double z, double midY,
460
                                  int bottomR, int bottomG, int bottomB, int bottomA,
461
                                  int topR, int topG, int topB, int topA) {
462
        boolean bottom = y <= midY;
463
        return mesh.vec3(x, y, z)
464
                .color(
465
                        bottom ? bottomR : topR,
466
                        bottom ? bottomG : topG,
467
                        bottom ? bottomB : topB,
468
                        bottom ? bottomA : topA
469
                )
470
                .next();
471
    }
472
473
    private static void addBottomOutline(Renderer3D renderer, AABB box, int argb) {
474
        int a = (argb >>> 24) & 0xFF;
475
        if (a <= 0) {
476
            return;
477
        }
478
        int r = (argb >>> 16) & 0xFF;
479
        int g = (argb >>> 8) & 0xFF;
480
        int b = argb & 0xFF;
481
482
        renderer.line(box.minX, box.minY, box.minZ, box.maxX, box.minY, box.minZ, r, g, b, a);
483
        renderer.line(box.maxX, box.minY, box.minZ, box.maxX, box.minY, box.maxZ, r, g, b, a);
484
        renderer.line(box.maxX, box.minY, box.maxZ, box.minX, box.minY, box.maxZ, r, g, b, a);
485
        renderer.line(box.minX, box.minY, box.maxZ, box.minX, box.minY, box.minZ, r, g, b, a);
486
    }
487
488
    private record Hole(AABB box, int argb, List<BlockPos> positions) {
489
    }
490
}
491
NicotineRendersrc/client/java/nicotine/mod/mods/render/HoleESP.javaJava · 106 lines · 3.2 KB

Shows safe spots against end crystals

SettingsWidthHeight
HoleESP.javaJava · Minecraft 26.3 · 106 lines · 3.2 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.render;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.util.CommonColors;
5
import net.minecraft.world.level.block.Block;
6
import net.minecraft.world.level.block.Blocks;
7
import nicotine.events.ClientLevelTickEvent;
8
import nicotine.events.RenderEvent;
9
import nicotine.mod.Mod;
10
import nicotine.mod.ModCategory;
11
import nicotine.mod.option.SliderOption;
12
import nicotine.util.EventBus;
13
import nicotine.util.Player;
14
import nicotine.util.render.Render3D;
15
import nicotine.util.math.BoxUtil;
16
17
import java.util.ArrayList;
18
import java.util.Arrays;
19
import java.util.List;
20
21
import static nicotine.util.Common.*;
22
23
public class HoleESP extends Mod {
24
25
    public List<BlockPos> holeSpots = new ArrayList<>();
26
27
    private final List<Block> validBlocks =  Arrays.asList(Blocks.OBSIDIAN, Blocks.BEDROCK);
28
29
    private final SliderOption width = new SliderOption(
30
            "Width",
31
            6,
32
            5,
33
            35
34
    );
35
36
    private final SliderOption height = new SliderOption(
37
            "Height",
38
            10,
39
            5,
40
            35
41
    );
42
43
    public HoleESP() {
44
        super(ModCategory.Render,"HoleESP", "Shows safe spots against end crystals");
45
        this.addOptions(Arrays.asList(width, height));
46
    }
47
48
    private List<BlockPos> getHoleSpots(int horizontal, int vertical) {
49
        BlockPos initPos = mc.player.blockPosition();
50
51
        for (int x = -horizontal; x <= horizontal; x++) {
52
            for (int y = -vertical; y <= vertical; y++) {
53
                for (int z = -horizontal; z <= horizontal; z++) {
54
                    BlockPos pos = initPos.offset(x, y, z);
55
                    if (validBlocks.contains(mc.level.getBlockState(pos).getBlock())) {
56
57
                        if (mc.level.getBlockState(pos.offset(0, 1, 0)).getBlock() != Blocks.AIR) {
58
                            continue;
59
                        }
60
61
                        if (mc.level.getBlockState(pos.offset(0, 2, 0)).getBlock() != Blocks.AIR) {
62
                            continue;
63
                        }
64
65
                        boolean allValidBlocks = true;
66
67
                        for (BlockPos surroundPos : Player.getSurroundBlocks(pos, 1)) {
68
                            if (!validBlocks.contains(mc.level.getBlockState(surroundPos).getBlock())) {
69
                                allValidBlocks = false;
70
                                break;
71
                            }
72
                        }
73
74
                        if (allValidBlocks) {
75
                            holeSpots.add(pos);
76
                        }
77
                    }
78
                }
79
            }
80
        }
81
82
        return holeSpots;
83
    }
84
85
    @Override
86
    protected void init() {
87
        EventBus.register(RenderEvent.class, event -> {
88
            if (!this.enabled)
89
                return true;
90
91
            for (BlockPos holeSpot : holeSpots) {
92
                Render3D.drawFilledBox(event.submitNodeStorage, event.camera, event.matrixStack, BoxUtil.getBlockBoundingBoxf(holeSpot.offset(0, 1, 0)), CommonColors.SOFT_RED);
93
            }
94
95
            return true;
96
        });
97
98
        EventBus.register(ClientLevelTickEvent.class, event -> {
99
            holeSpots.clear();
100
            holeSpots = getHoleSpots((int)width.value, (int)height.value);
101
102
            return true;
103
        });
104
   }
105
}
106
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleHoleESP.ktKotlin · 178 lines · 6.7 KB

Detects and displays safe spots for crystal PvP.

SettingsHorizontalScanDistanceVerticalScanDistanceDistanceFade1x1Bedrock1x11x22x2OutlineGlowHeight
ModuleHoleESP.ktKotlin · Minecraft 26.2 · 178 lines · 6.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.render
20
21
import net.ccbluex.liquidbounce.config.types.group.Mode
22
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
23
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
24
import net.ccbluex.liquidbounce.event.handler
25
import net.ccbluex.liquidbounce.features.module.ClientModule
26
import net.ccbluex.liquidbounce.features.module.ModuleCategories
27
import net.ccbluex.liquidbounce.render.drawBox
28
import net.ccbluex.liquidbounce.render.drawBoxSide
29
import net.ccbluex.liquidbounce.render.drawGradientSides
30
import net.ccbluex.liquidbounce.render.engine.type.Color4b
31
import net.ccbluex.liquidbounce.render.renderEnvironment
32
import net.ccbluex.liquidbounce.render.withPositionRelativeToCamera
33
import net.ccbluex.liquidbounce.utils.block.hole.Hole
34
import net.ccbluex.liquidbounce.utils.block.hole.HoleManager
35
import net.ccbluex.liquidbounce.utils.block.hole.HoleManagerSubscriber
36
import net.ccbluex.liquidbounce.utils.block.hole.HoleTracker
37
import net.ccbluex.liquidbounce.utils.math.box
38
import net.minecraft.core.BlockPos
39
import net.minecraft.core.Direction
40
import net.minecraft.world.phys.Vec3
41
import kotlin.math.abs
42
import kotlin.math.max
43
44
/**
45
 * HoleESP module
46
 *
47
 * Detects and displays safe spots for Crystal PvP.
48
 */
49
object ModuleHoleESP : ClientModule("HoleESP", ModuleCategories.RENDER), HoleManagerSubscriber {
50
51
    private val modes = choices("Mode", GlowingPlane, arrayOf(BoxMode, GlowingPlane))
52
53
    private val horizontalDistance by int("HorizontalScanDistance", 32, 4..128)
54
    private val verticalDistance by int("VerticalScanDistance", 8, 4..128)
55
56
    private val distanceFade by float("DistanceFade", 0.3f, 0f..1f)
57
58
    private val colorBedrock by color("1x1Bedrock", Color4b.fullAlpha(0x19c15c))
59
    private val color1by1 by color("1x1", Color4b.fullAlpha(0xf7381b))
60
    private val color1by2 by color("1x2", Color4b.fullAlpha(0x35bacc))
61
    private val color2by2 by color("2x2", Color4b.fullAlpha(0xf7cf1b))
62
63
    override fun horizontalDistance(): Int = horizontalDistance
64
    override fun verticalDistance(): Int = verticalDistance
65
66
    override fun onEnabled() {
67
        HoleManager.subscribe(this)
68
    }
69
70
    override fun onDisabled() {
71
        HoleManager.unsubscribe(this)
72
    }
73
74
    private object BoxMode : Mode("Box") {
75
76
        override val parent: ModeValueGroup<Mode>
77
            get() = modes
78
79
        private val outline by boolean("Outline", true)
80
81
        @Suppress("unused")
82
        val renderHandler = handler<WorldRenderEvent> { event ->
83
            val pos = player.blockPosition()
84
            val vDistance = verticalDistance
85
            val hDistance = horizontalDistance
86
87
            event.renderEnvironment {
88
                HoleTracker.holes.forEach {
89
                    val positions = it.positions
90
91
                    val valOutOfRange = abs(pos.y - it.pos.y) > vDistance
92
                    val xzOutOfRange = abs(pos.x - it.pos.x) > hDistance ||
93
                        abs(pos.z - it.pos.z) > hDistance
94
                    if (valOutOfRange || xzOutOfRange) {
95
                        return@forEach
96
                    }
97
98
                    val fade = calculateFade(it.pos)
99
                    val baseColor = it.color().with(a = 50).fade(fade)
100
                    withPositionRelativeToCamera(it.pos) {
101
                        drawBox(
102
                            positions.box,
103
                            baseColor,
104
                            if (outline) baseColor.with(a = 100).fade(fade) else null,
105
                        )
106
                    }
107
                }
108
            }
109
        }
110
    }
111
112
    private object GlowingPlane : Mode("GlowingPlane") {
113
114
        override val parent: ModeValueGroup<Mode>
115
            get() = modes
116
117
        private val outline by boolean("Outline", true)
118
119
        private val glowHeightSetting by float("GlowHeight", 0.7f, 0f..1f)
120
121
        @Suppress("unused")
122
        val renderHandler = handler<WorldRenderEvent> { event ->
123
            val glowHeight = glowHeightSetting.toDouble()
124
            val pos = player.blockPosition()
125
            val vDistance = verticalDistance
126
            val hDistance = horizontalDistance
127
128
            event.renderEnvironment {
129
                HoleTracker.holes.forEach {
130
                    val positions = it.positions
131
132
                    val valOutOfRange = abs(pos.y - it.pos.y) > vDistance
133
                    val xzOutOfRange = abs(pos.x - it.pos.x) > hDistance ||
134
                        abs(pos.z - it.pos.z) > hDistance
135
                    if (valOutOfRange || xzOutOfRange) {
136
                        return@forEach
137
                    }
138
139
                    val fade = calculateFade(it.pos)
140
                    val baseColor = it.color().with(a = 50).fade(fade)
141
                    val transparentColor = baseColor.with(a = 0)
142
                    val box = positions.box
143
                    withPositionRelativeToCamera(it.pos) {
144
                        drawBoxSide(
145
                            box,
146
                            Direction.DOWN,
147
                            baseColor,
148
                            if (outline) baseColor.with(a = 100).fade(fade) else null,
149
                        )
150
                        drawGradientSides(glowHeight, baseColor, transparentColor, box)
151
                    }
152
                }
153
            }
154
        }
155
    }
156
157
    private fun Hole.color() = when (this) {
158
        is Hole.OneByOne -> if (bedrockOnly) colorBedrock else color1by1
159
        is Hole.OneByTwo -> color1by2
160
        is Hole.TwoByTwo -> color2by2
161
    }
162
163
    private fun calculateFade(pos: BlockPos): Float {
164
        if (distanceFade == 0f) {
165
            return 1f
166
        }
167
168
        val verticalDistanceFraction = (player.position().y - pos.y) / verticalDistance
169
        val horizontalDistanceFraction =
170
            Vec3(player.position().x - pos.x, 0.0, player.position().z - pos.z).length() / horizontalDistance
171
172
        val fade = (1 - max(verticalDistanceFraction, horizontalDistanceFraction)) / distanceFade
173
174
        return fade.coerceIn(0.0, 1.0).toFloat()
175
    }
176
177
}
178