ProtectionZones module

ProtectionZones: Minecraft 26.3 cheat module, full source for every implementation (1 client: LiquidBounce (Kotlin)).

1 implementationRENDER

Clients with this module

Full module source: 1 implementation

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

LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleProtectionZones.ktKotlin · 254 lines · 9.4 KB

Allows you to see areas protected by protection blocks and suggests optimal placement spots.

SettingsProtectionBlocksRadiusXRadiusZRadiusYRenderLimitHoldBlockToRenderZoneFillZoneOutlineCenterZoneOutlineIndicatorOutlineIndicatorFillSnapToY
ModuleProtectionZones.ktKotlin · Minecraft 26.2 · 254 lines · 9.4 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
20
package net.ccbluex.liquidbounce.features.module.modules.render
21
22
import com.google.common.collect.Ordering
23
import net.ccbluex.fastutil.mapToArray
24
import net.ccbluex.fastutil.synchronized
25
import net.ccbluex.liquidbounce.config.types.group.ValueGroup
26
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
27
import net.ccbluex.liquidbounce.event.handler
28
import net.ccbluex.liquidbounce.features.module.ClientModule
29
import net.ccbluex.liquidbounce.features.module.ModuleCategories
30
import net.ccbluex.liquidbounce.render.WorldRenderEnvironment
31
import net.ccbluex.liquidbounce.render.drawBox
32
import net.ccbluex.liquidbounce.render.engine.type.Color4b
33
import net.ccbluex.liquidbounce.render.renderEnvironment
34
import net.ccbluex.liquidbounce.utils.block.AbstractBlockLocationTracker
35
import net.ccbluex.liquidbounce.utils.block.ChunkScanner
36
import net.ccbluex.liquidbounce.utils.collection.blockSortedSetOf
37
import net.ccbluex.liquidbounce.utils.item.getBlock
38
import net.ccbluex.liquidbounce.utils.math.center
39
import net.minecraft.core.BlockPos
40
import net.minecraft.world.level.Level
41
import net.minecraft.world.level.block.Block
42
import net.minecraft.world.level.block.Blocks
43
import net.minecraft.world.level.block.state.BlockState
44
import net.minecraft.world.phys.AABB
45
import net.minecraft.world.phys.Vec3
46
import kotlin.math.max
47
import kotlin.math.min
48
import kotlin.math.roundToInt
49
50
/**
51
 * ProtectionZones module
52
 *
53
 * Allows you to see areas protected by protection blocks and suggests optimal placement spots.
54
 */
55
object ModuleProtectionZones : ClientModule("ProtectionZones", ModuleCategories.RENDER) {
56
57
    private val DEFAULT_ZONE_FILL = Color4b(0, 255, 0, 51)
58
    private val DEFAULT_ZONE_OUTLINE = Color4b(0, 255, 0, 255)
59
    private val DEFAULT_CENTER_OUTLINE = Color4b(0, 255, 207, 255)
60
    private val DEFAULT_INDICATOR_OUTLINE = Color4b(255, 240, 0, 255)
61
    private val DEFAULT_INDICATOR_FILL = Color4b(255, 240, 0, 51)
62
    private const val HIGHLIGHT_RADIUS: Float = 5.0f
63
64
    private val protBlocks by blocks(
65
        "ProtectionBlocks",
66
        blockSortedSetOf(Blocks.EMERALD_BLOCK).synchronized(),
67
    ).onChange {
68
        if (running) {
69
            onDisabled()
70
            onEnabled()
71
        }
72
        it
73
    }
74
75
    private object Radius : ValueGroup("ProtectionRadius") {
76
        val x by int("RadiusX", 20, 1..256, "blocks")
77
        val z by int("RadiusZ", 20, 1..256, "blocks")
78
        val y by int("RadiusY", 383, 1..383, "blocks")
79
    }
80
81
    private object Renderer : ValueGroup("Renderer") {
82
        val renderLimit by int("RenderLimit", 16, 3..50, "zones")
83
        val holdBlockToRender by boolean("HoldBlockToRender", false)
84
85
        object ProtectionColors : ValueGroup("ProtectionColors") {
86
            val zoneFill by color("ZoneFill", DEFAULT_ZONE_FILL)
87
            val zoneOutline by color("ZoneOutline", DEFAULT_ZONE_OUTLINE)
88
            val centerZoneOutline by color("CenterZoneOutline", DEFAULT_CENTER_OUTLINE)
89
        }
90
91
        object IndicatorColors : ValueGroup("IndicatorColors") {
92
            val indicatorOutline by color("IndicatorOutline", DEFAULT_INDICATOR_OUTLINE)
93
            val indicatorFill by color("IndicatorFill", DEFAULT_INDICATOR_FILL)
94
        }
95
96
        init {
97
            treeAll(ProtectionColors, IndicatorColors)
98
        }
99
    }
100
101
    private object Indicator : ValueGroup("PlacementIndicator") {
102
        val snapY by boolean("SnapToY", false)
103
    }
104
105
    init {
106
        treeAll(Radius, Indicator, Renderer)
107
    }
108
109
    private object BlockTracker : AbstractBlockLocationTracker.BlockPos2State<Block>() {
110
        override fun getStateFor(pos: BlockPos, state: BlockState): Block? =
111
            state.block?.takeIf { it in protBlocks }
112
    }
113
114
    override fun onEnabled() {
115
        ChunkScanner.subscribe(BlockTracker)
116
    }
117
118
    override fun onDisabled() {
119
        ChunkScanner.unsubscribe(BlockTracker)
120
    }
121
122
    private fun isHoldingProtBlock(): Boolean {
123
        val player = mc.player ?: return false
124
        val main = player.mainHandItem.getBlock()
125
        val off = player.offhandItem.getBlock()
126
        return (main != null && main in protBlocks)
127
            || (off != null && off in protBlocks)
128
    }
129
130
    private fun snapToGrid(value: Int, origin: Int, step: Int): Int {
131
        val stepsFromOrigin = ((value - origin).toDouble() / step).roundToInt()
132
        return origin + stepsFromOrigin * step
133
    }
134
135
    private fun nearestCenters(
136
        centers: Sequence<BlockPos>, limit: Int, playerPos: Vec3
137
    ): List<BlockPos> {
138
        if (limit <= 0) return emptyList()
139
140
        return Ordering.from<BlockPos> { a, b ->
141
            fun squaredDist(p: BlockPos): Double {
142
                val dx = (p.x + 0.5) - playerPos.x
143
                val dz = (p.z + 0.5) - playerPos.z
144
                return dx * dx + dz * dz
145
            }
146
            squaredDist(a).compareTo(squaredDist(b))
147
        }.leastOf(centers.iterator(), limit)
148
    }
149
150
    private fun computeZones(centers: List<BlockPos>, world: Level): Array<AABB> {
151
        return centers.mapToArray { c ->
152
            val minY = max(c.y - Radius.y, world.minY)
153
            val maxY = min(c.y + Radius.y, world.maxY)
154
            AABB(
155
                (c.x - Radius.x).toDouble(),
156
                minY.toDouble(),
157
                (c.z - Radius.z).toDouble(),
158
                (c.x + Radius.x + 1).toDouble(),
159
                (maxY + 1).toDouble(),
160
                (c.z + Radius.z + 1).toDouble()
161
            )
162
        }
163
    }
164
165
    private fun findHighlightIndex(zones: Array<AABB>, playerPos: Vec3): Int? {
166
        val r2 = (HIGHLIGHT_RADIUS * HIGHLIGHT_RADIUS).toDouble()
167
        for ((i, b) in zones.withIndex()) {
168
            if (b.contains(playerPos)) return null
169
            if (b.distanceToSqr(playerPos) <= r2) return i
170
        }
171
        return null
172
    }
173
174
    private fun WorldRenderEnvironment.drawZones(
175
        zones: Array<AABB>, centers: List<BlockPos>, highlightIndex: Int?, camOffset: Vec3
176
    ) {
177
        val colors = Renderer.ProtectionColors
178
        val viewZones = ArrayList<AABB>(zones.size)
179
        val centerBoxes = ArrayList<AABB>(centers.size)
180
        for (i in zones.indices) {
181
            viewZones += zones[i].move(camOffset)
182
            centerBoxes += AABB(centers[i]).move(camOffset)
183
        }
184
185
        for (b in viewZones) drawBox(b, outlineColor = colors.zoneOutline)
186
        for (c in centerBoxes) drawBox(c, outlineColor = colors.centerZoneOutline)
187
188
        if (highlightIndex != null && highlightIndex in viewZones.indices) {
189
            val highlighted = viewZones[highlightIndex]
190
            drawBox(highlighted, faceColor = colors.zoneFill)
191
        }
192
    }
193
194
    private fun WorldRenderEnvironment.drawIndicator(
195
        centers: List<BlockPos>, zones: Array<AABB>, camOffset: Vec3
196
    ) {
197
        if (centers.isEmpty()) return
198
        val player = mc.player ?: return
199
        val world = mc.level ?: return
200
201
        val playerBlockPos = player.blockPosition()
202
        val refCenter = centers.first()
203
204
        val stepX = 2 * Radius.x + 1
205
        val stepZ = 2 * Radius.z + 1
206
207
        val snappedX = snapToGrid(value = playerBlockPos.x, origin = refCenter.x, step = stepX)
208
        val snappedZ = snapToGrid(value = playerBlockPos.z, origin = refCenter.z, step = stepZ)
209
        val snappedY = (if (Indicator.snapY) refCenter.y else playerBlockPos.y).coerceIn(
210
            world.minY,
211
            world.maxY
212
        )
213
214
        val indicatorPos = BlockPos(snappedX, snappedY, snappedZ)
215
        val indicatorCenter = indicatorPos.center
216
        if (zones.any { it.contains(indicatorCenter) }) return
217
        val indicatorBox = AABB(indicatorPos).move(camOffset)
218
219
        drawBox(
220
            indicatorBox,
221
            faceColor = Renderer.IndicatorColors.indicatorFill,
222
            outlineColor = Renderer.IndicatorColors.indicatorOutline,
223
        )
224
    }
225
226
    @Suppress("unused")
227
    private val renderHandler = handler<WorldRenderEvent> { e ->
228
        if (BlockTracker.isEmpty()) return@handler
229
        val holdingProt = isHoldingProtBlock()
230
        if (Renderer.holdBlockToRender && !holdingProt) return@handler
231
232
        val world = mc.level ?: return@handler
233
        val player = mc.player ?: return@handler
234
235
        val centers = nearestCenters(
236
            centers = BlockTracker.allPositions(),
237
            limit = Renderer.renderLimit,
238
            playerPos = player.position(),
239
        )
240
        if (centers.isEmpty()) return@handler
241
242
        val zones = computeZones(centers, world)
243
        val highlightIndex = findHighlightIndex(zones, playerPos = player.position())
244
245
        e.renderEnvironment {
246
            val camOffset = mc.entityRenderDispatcher.camera?.position()?.reverse() ?: return@handler
247
            drawZones(zones, centers, highlightIndex, camOffset)
248
            if (holdingProt) {
249
                drawIndicator(centers, zones, camOffset)
250
            }
251
        }
252
    }
253
}
254