BlockTrap module

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

1 implementationWORLD

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)WORLDsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/ModuleBlockTrap.ktKotlin · 210 lines · 7.5 KB

Traps enemies in blocks.

SettingsPlaceAtInstantFilterBlocksPlacePriority
ModuleBlockTrap.ktKotlin · Minecraft 26.2 · 210 lines · 7.5 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.world
20
21
import net.ccbluex.liquidbounce.config.types.list.Tagged
22
import net.ccbluex.liquidbounce.event.events.PacketEvent
23
import net.ccbluex.liquidbounce.event.events.RotationUpdateEvent
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.utils.block.placer.BlockPlacer
28
import net.ccbluex.liquidbounce.utils.block.placer.placeInstantOnBlockUpdate
29
import net.ccbluex.liquidbounce.utils.client.FloatValueProvider
30
import net.ccbluex.liquidbounce.utils.collection.Filter
31
import net.ccbluex.liquidbounce.utils.collection.blockSortedSetOf
32
import net.ccbluex.liquidbounce.utils.collection.getSlot
33
import net.ccbluex.liquidbounce.utils.combat.TargetPriority
34
import net.ccbluex.liquidbounce.utils.combat.TargetTracker
35
import net.ccbluex.liquidbounce.utils.kotlin.Priority
36
import net.ccbluex.liquidbounce.utils.kotlin.range
37
import net.ccbluex.liquidbounce.utils.render.TargetRenderer
38
import net.minecraft.core.BlockPos
39
import net.minecraft.util.Mth
40
import net.minecraft.world.entity.Entity
41
import kotlin.math.max
42
import kotlin.math.min
43
44
/**
45
 * Module BlockTrap
46
 *
47
 * Traps enemies in blocks.
48
 *
49
 * @author ccetl
50
 */
51
@Suppress("MagicNumber")
52
object ModuleBlockTrap : ClientModule("BlockTrap", ModuleCategories.WORLD) {
53
54
    private val doublePlace by multiEnumChoice<DoublePlace>("DoublePlace")
55
56
    private val placeAt by multiEnumChoice("PlaceAt", PlaceAt.entries)
57
58
    /**
59
     * Replaces broken blocks instantly.
60
     *
61
     * Requires the rotation mode "None" in the block placer.
62
     */
63
    private val instant by boolean("Instant", true)
64
65
    private val filter by enumChoice("Filter", Filter.BLACKLIST)
66
    private val blocks by blocks("Blocks", blockSortedSetOf())
67
    private val placePriority by enumChoice("PlacePriority", PlacePriority.FURTHEST)
68
    private val placer = tree(BlockPlacer("Place", this, Priority.NORMAL, { filter.getSlot(blocks) }))
69
    private val targetTracker = tree(TargetTracker(
70
        TargetPriority.DIRECTION,
71
        FloatValueProvider("Range", 4f, 1f..6f)
72
    ))
73
74
    init {
75
        tree(TargetRenderer(this, targetTracker))
76
    }
77
78
    override fun onDisabled() {
79
        placer.disable()
80
    }
81
82
    @Suppress("unused")
83
    private val rotationUpdateHandler = handler<RotationUpdateEvent> {
84
        targetTracker.selectFirst()
85
        val target = targetTracker.target ?: run {
86
            if (!placer.isDone()) {
87
                placer.clear()
88
            }
89
90
            return@handler
91
        }
92
93
        val plan = findTrapPlan(target)
94
        placer.update(plan.sortedWith(placePriority.comparator).toSet())
95
    }
96
97
    @Suppress("unused")
98
    private val blockUpdateHandler = handler<PacketEvent> {
99
        if (!instant) {
100
            return@handler
101
        }
102
103
        placer.placeInstantOnBlockUpdate(it)
104
    }
105
106
    @Suppress("ComplexCondition")
107
    private fun findTrapPlan(target: Entity): Set<BlockPos> {
108
        var highestY = Int.MIN_VALUE
109
        var lowestY = Int.MAX_VALUE
110
111
        // step one: find all block positions to around the bounding box
112
        val boundingBox = target.boundingBox
113
        val result = mutableSetOf<BlockPos>()
114
        val xRange = Mth.floor(boundingBox.minX - 1.0)..Mth.floor(boundingBox.maxX + 1.0)
115
        val yRange = Mth.floor(boundingBox.minY - 1.0)..Mth.floor(boundingBox.maxY + 1.0)
116
        val zRange = Mth.floor(boundingBox.minZ - 1.0)..Mth.floor(boundingBox.maxZ + 1.0)
117
118
        // ranges used to check if a position is in the bounding box
119
        val bbXRange = Mth.floor(boundingBox.minX)..Mth.floor(boundingBox.maxX)
120
        val bbYRange = Mth.floor(boundingBox.minY)..Mth.floor(boundingBox.maxY)
121
        val bbZRange = Mth.floor(boundingBox.minZ)..Mth.floor(boundingBox.maxZ)
122
123
        range(xRange step 1, yRange step 1, zRange step 1) { x, y, z ->
124
            // continue if the position is in the box or outside on two or more axes
125
            val inBb = x in bbXRange && y in bbYRange && z in bbZRange
126
            val onlyZIn = x !in bbXRange && y !in bbYRange
127
            val onlyXIn = y !in bbYRange && z !in bbZRange
128
            val onlyYIn = z !in bbZRange && x !in bbXRange
129
            if (inBb || onlyZIn || onlyXIn || onlyYIn) {
130
                return@range
131
            }
132
133
            val blockPos = BlockPos(x, y, z)
134
            result += blockPos
135
            highestY = max(highestY, blockPos.y)
136
            lowestY = min(lowestY, blockPos.y)
137
        }
138
139
        return tweakPlan(result, lowestY, highestY)
140
    }
141
142
    private fun tweakPlan(currentPlan: Set<BlockPos>, lowestY: Int, highestY: Int): Set<BlockPos> {
143
        // step two tweaking with options
144
        val shouldFilterLegsOut = PlaceAt.LEGS !in placeAt // && highestY - lowestY > 3
145
        val shouldFilterFloorOut = PlaceAt.FLOOR !in placeAt
146
        val filteredList = currentPlan.filterNot {
147
            shouldFilterLegsOut && it.y == lowestY + 1 || shouldFilterFloorOut && it.y == lowestY
148
        }
149
150
        val additions = mutableListOf<BlockPos>()
151
        filteredList.forEach { pos ->
152
            when {
153
                DoublePlace.BELOW in doublePlace
154
                    && PlaceAt.FLOOR in placeAt
155
                    && pos.y == lowestY -> additions.add(pos.below())
156
157
                DoublePlace.ABOVE in doublePlace
158
                    && pos.y == highestY -> additions.add(pos.above())
159
            }
160
        }
161
162
        return (filteredList + additions).toSet()
163
    }
164
165
    /**
166
     * Determines how the blocks are added to the placement queue.
167
     */
168
    @Suppress("unused")
169
    private enum class PlacePriority(
170
        override val tag: String,
171
        val comparator: Comparator<BlockPos>
172
    ) : Tagged {
173
        CLOSEST("Closest", compareBy { it.distToCenterSqr(player.position()) }),
174
        FURTHEST("Furthest", compareByDescending { it.distToCenterSqr(player.position()) }),
175
        HIGHEST("Highest", compareByDescending { it.y }),
176
        LOWEST("Lowest", compareBy { it.y })
177
    }
178
179
    private enum class PlaceAt(
180
        override val tag: String
181
    ) : Tagged {
182
        /**
183
         * Allows placing crystals next to their legs and keep them at the spot when disabled.
184
         */
185
        LEGS("Legs"),
186
187
        /**
188
         * Allows placing crystals next to floor and keep them at the spot when disabled.
189
         */
190
        FLOOR("Floor")
191
    }
192
193
    private enum class DoublePlace(
194
        override val tag: String
195
    ) : Tagged {
196
        /**
197
         * Places two blocks above the target's head so that they can't mine the block and at the same time tower up to
198
         * escape.
199
         */
200
        ABOVE("Above"),
201
202
        /**
203
         * Places two layers below the target so they can't mine the block below them and possible fall down.
204
         *
205
         * Requires [PlaceAt.FLOOR] to be enabled.
206
         */
207
        BELOW("Below")
208
    }
209
}
210