BlockOutline module

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

2 implementationsRenderRENDER

Full module source: 2 implementations

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

NicotineRendersrc/client/java/nicotine/mod/mods/render/BlockOutline.javaJava · 70 lines · 2.1 KB
SettingsRenderRGB
BlockOutline.javaJava · Minecraft 26.3 · 70 lines · 2.1 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.render;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.world.phys.BlockHitResult;
5
import net.minecraft.world.phys.HitResult;
6
import nicotine.events.RenderEvent;
7
import nicotine.mod.Mod;
8
import nicotine.mod.ModCategory;
9
import nicotine.mod.option.RGBOption;
10
import nicotine.mod.option.DropDownOption;
11
import nicotine.util.EventBus;
12
import nicotine.util.math.BoxUtil;
13
import nicotine.util.math.Boxf;
14
import nicotine.util.render.Render3D;
15
16
import java.util.Arrays;
17
18
import static nicotine.util.Common.mc;
19
20
public class BlockOutline extends Mod {
21
22
    private final DropDownOption render = new DropDownOption(
23
            "Render",
24
            new String[]{"Box", "Filled", "Fade"}
25
    );
26
27
    private final RGBOption rgb = new RGBOption("RGB");
28
29
    public BlockOutline() {
30
        super(ModCategory.Render, "BlockOutline");
31
        this.addOptions(Arrays.asList(render, rgb));
32
    }
33
34
    @Override
35
    public void toggle() {
36
        this.enabled = !this.enabled;
37
        mc.gameRenderer.setRenderBlockOutline(!enabled);
38
    }
39
40
    @Override
41
    protected void init() {
42
        EventBus.register(RenderEvent.class, event -> {
43
            if (!this.enabled)
44
                return true;
45
46
            HitResult crosshairTarget = mc.hitResult;
47
48
            if (crosshairTarget.getType() != HitResult.Type.BLOCK)
49
                return true;
50
51
            BlockPos pos = ((BlockHitResult)crosshairTarget).getBlockPos();
52
            Boxf boundingBox = BoxUtil.getBlockBoundingBoxf(pos);
53
54
            switch (render.value) {
55
                case "Box":
56
                    Render3D.drawBox(event.submitNodeStorage, event.camera, event.matrixStack, boundingBox, rgb.getColor());
57
                    break;
58
                case "Filled":
59
                    Render3D.drawFilledBox(event.submitNodeStorage, event.camera, event.matrixStack, boundingBox, rgb.getColor());
60
                    break;
61
                case "Fade":
62
                    Render3D.drawFilledBox(event.submitNodeStorage, event.camera, event.matrixStack, boundingBox, rgb.getColor(), true);
63
                    break;
64
            }
65
66
            return true;
67
        });
68
    }
69
}
70
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleBlockOutline.ktKotlin · 203 lines · 6.8 KB

Changes the way Minecraft highlights blocks.

SettingsSideOnlyColorOutlineTimeEasing
ModuleBlockOutline.ktKotlin · Minecraft 26.2 · 203 lines · 6.8 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.ToggleableValueGroup
22
import net.ccbluex.liquidbounce.event.events.WorldChangeEvent
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.injection.mixins.minecraft.render.MixinLevelRenderer
28
import net.ccbluex.liquidbounce.render.drawBox
29
import net.ccbluex.liquidbounce.render.drawBoxSide
30
import net.ccbluex.liquidbounce.render.drawShape
31
import net.ccbluex.liquidbounce.render.drawShapeSide
32
import net.ccbluex.liquidbounce.render.engine.type.Color4b
33
import net.ccbluex.liquidbounce.render.renderEnvironment
34
import net.ccbluex.liquidbounce.render.withPositionRelativeToCamera
35
import net.ccbluex.liquidbounce.utils.math.Easing
36
import net.ccbluex.liquidbounce.utils.math.minus
37
import net.minecraft.core.Direction
38
import net.minecraft.util.Mth
39
import net.minecraft.world.phys.AABB
40
import net.minecraft.world.phys.BlockHitResult
41
import net.minecraft.world.phys.HitResult
42
import net.minecraft.world.phys.shapes.CollisionContext
43
44
/**
45
 * Block Outline module
46
 *
47
 * Changes the way Minecraft highlights blocks.
48
 *
49
 * TODO: Implement GUI Information Panel
50
 *
51
 * @see MixinLevelRenderer.cancelBlockOutline
52
 */
53
object ModuleBlockOutline : ClientModule("BlockOutline", ModuleCategories.RENDER, aliases = listOf("BlockOverlay")) {
54
55
    private val sideOnly by boolean("SideOnly", true)
56
    private val color by color("Color", Color4b(68, 117, 255, 70))
57
    private val outlineColor by color("Outline", Color4b(68, 117, 255, 150))
58
59
    private object Slide : ToggleableValueGroup(this, "Slide", true) {
60
        val time by int("Time", 150, 1..1000, "ms")
61
        val easing by easing("Easing", Easing.LINEAR)
62
    }
63
64
    init {
65
        tree(Slide)
66
    }
67
68
    private var currentPosition: AABB? = null
69
    private var previousPosition: AABB? = null
70
    private var lastChange = 0L
71
72
    @Suppress("unused")
73
    private val renderHandler = handler<WorldRenderEvent> { event ->
74
        val target = mc.hitResult
75
        if (target !is BlockHitResult || target.type == HitResult.Type.MISS) {
76
            resetPositions()
77
            return@handler
78
        }
79
80
        val blockPos = target.blockPos
81
        val blockState = world.getBlockState(blockPos)
82
        if (blockState.isAir || !world.worldBorder.isWithinBounds(blockPos)) {
83
            resetPositions()
84
            return@handler
85
        }
86
87
        val side = target.direction
88
        val shape = blockState.getShape(this.world, blockPos, CollisionContext.of(mc.cameraEntity!!))
89
        if (shape.isEmpty) {
90
            resetPositions()
91
            return@handler
92
        }
93
94
        val singleBox = shape.toAabbs().singleOrNull()
95
        if (singleBox == null) {
96
            resetPositions()
97
98
            val localHitPos = target.location - blockPos
99
100
            event.renderEnvironment {
101
                withPositionRelativeToCamera(blockPos) {
102
                    if (sideOnly) {
103
                        drawShapeSide(shape, side, localHitPos, color, outlineColor)
104
                    } else {
105
                        drawShape(shape, color, outlineColor)
106
                    }
107
                }
108
            }
109
            return@handler
110
        }
111
112
        val finalPosition = (if (sideOnly) flatBox(singleBox, side) else singleBox).move(blockPos)
113
        if (currentPosition != finalPosition) {
114
            previousPosition = currentPosition
115
            currentPosition = finalPosition
116
            lastChange = System.currentTimeMillis()
117
        }
118
119
        val renderPosition = if (previousPosition != null && Slide.running) {
120
            val factor = Slide.easing.getFactor(lastChange, System.currentTimeMillis(), Slide.time.toFloat()).toDouble()
121
122
            val previousPosition = previousPosition!!
123
            AABB(
124
                Mth.lerp(factor, previousPosition.minX, finalPosition.minX),
125
                Mth.lerp(factor, previousPosition.minY, finalPosition.minY),
126
                Mth.lerp(factor, previousPosition.minZ, finalPosition.minZ),
127
                Mth.lerp(factor, previousPosition.maxX, finalPosition.maxX),
128
                Mth.lerp(factor, previousPosition.maxY, finalPosition.maxY),
129
                Mth.lerp(factor, previousPosition.maxZ, finalPosition.maxZ)
130
            )
131
        } else {
132
            finalPosition
133
        }
134
135
        val translatedPosition = renderPosition - event.camera.position()
136
137
        event.renderEnvironment {
138
            if (sideOnly) {
139
                drawBoxSide(
140
                    translatedPosition,
141
                    side,
142
                    color,
143
                    outlineColor,
144
                )
145
            } else {
146
                drawBox(
147
                    translatedPosition,
148
                    color,
149
                    outlineColor,
150
                )
151
            }
152
        }
153
    }
154
155
    private fun flatBox(box: AABB, side: Direction) = when (side) {
156
        Direction.UP -> boxWithBoundsY(box, box.maxY)
157
        Direction.DOWN -> boxWithBoundsY(box, box.minY)
158
        Direction.NORTH -> boxWithBoundsZ(box, box.minZ)
159
        Direction.SOUTH -> boxWithBoundsZ(box, box.maxZ)
160
        Direction.WEST -> boxWithBoundsX(box, box.minX)
161
        Direction.EAST -> boxWithBoundsX(box, box.maxX)
162
    }
163
164
    private fun boxWithBoundsX(box: AABB, x: Double) = AABB(
165
        x,
166
        box.minY,
167
        box.minZ,
168
        x,
169
        box.maxY,
170
        box.maxZ
171
    )
172
173
    private fun boxWithBoundsY(box: AABB, y: Double) = AABB(
174
        box.minX,
175
        y,
176
        box.minZ,
177
        box.maxX,
178
        y,
179
        box.maxZ
180
    )
181
182
    private fun boxWithBoundsZ(box: AABB, z: Double) = AABB(
183
        box.minX,
184
        box.minY,
185
        z,
186
        box.maxX,
187
        box.maxY,
188
        z
189
    )
190
191
    @Suppress("unused")
192
    private val worldChangeHandler = handler<WorldChangeEvent> {
193
        resetPositions()
194
        lastChange = System.currentTimeMillis()
195
    }
196
197
    private fun resetPositions() {
198
        currentPosition = null
199
        previousPosition = null
200
    }
201
202
}
203