AvoidHazards module

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

1 implementationMOVEMENT

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)MOVEMENTsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleAvoidHazards.ktKotlin · 264 lines · 9.9 KB

Prevents you from walking into blocks that might affect you negatively.

SettingsModeAvoid
ModuleAvoidHazards.ktKotlin · Minecraft 26.2 · 264 lines · 9.9 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.movement
20
21
import net.ccbluex.liquidbounce.config.types.list.Tagged
22
import net.ccbluex.liquidbounce.event.events.BlockShapeEvent
23
import net.ccbluex.liquidbounce.event.events.MovementInputEvent
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.features.module.modules.movement.avoidhazards.AvoidHazardInputPlanner
28
import net.ccbluex.liquidbounce.features.module.modules.movement.avoidhazards.isLadderClimbState
29
import net.ccbluex.liquidbounce.utils.block.getBlock
30
import net.ccbluex.liquidbounce.utils.block.state
31
import net.ccbluex.liquidbounce.utils.entity.SimulatedPlayer
32
import net.ccbluex.liquidbounce.utils.entity.isOnMagmaBlock
33
import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention.SAFETY_FEATURE
34
import net.ccbluex.liquidbounce.utils.math.iterateBlockPos
35
import net.ccbluex.liquidbounce.utils.math.toBlockPos
36
import net.ccbluex.liquidbounce.utils.movement.DirectionalInput
37
import net.minecraft.client.multiplayer.ClientLevel
38
import net.minecraft.core.BlockPos
39
import net.minecraft.world.level.block.BasePressurePlateBlock
40
import net.minecraft.world.level.block.Block
41
import net.minecraft.world.level.block.CactusBlock
42
import net.minecraft.world.level.block.FireBlock
43
import net.minecraft.world.level.block.MagmaBlock
44
import net.minecraft.world.level.block.PowderSnowBlock
45
import net.minecraft.world.level.block.SweetBerryBushBlock
46
import net.minecraft.world.level.block.WebBlock
47
import net.minecraft.world.level.block.WitherRoseBlock
48
import net.minecraft.world.level.material.FluidState
49
import net.minecraft.world.level.material.Fluids
50
import net.minecraft.world.phys.AABB
51
import net.minecraft.world.phys.shapes.Shapes
52
53
/**
54
 * Anti hazards module
55
 *
56
 * Prevents you walking into blocks that might be malicious for you.
57
 */
58
object ModuleAvoidHazards : ClientModule("AvoidHazards", ModuleCategories.MOVEMENT) {
59
    private var mode by enumChoice("Mode", AvoidMode.SHAPE)
60
    private val avoid by multiEnumChoice("Avoid", Avoid.entries)
61
62
    // Conflicts with AvoidHazards
63
    val cobWebs get() = Avoid.COBWEB in avoid
64
65
    private const val MOVEMENT_PREDICTION_TICKS = 2
66
    private const val CACTUS_BLOCK_MARGIN = 0.001
67
68
    @Suppress("MagicNumber")
69
    private val UNSAFE_BLOCK_CAP = Block.box(
70
        0.0,
71
        0.0,
72
        0.0,
73
        16.0,
74
        4.0,
75
        16.0
76
    )
77
78
    @Suppress("unused")
79
    val shapeHandler = handler<BlockShapeEvent> { event ->
80
        if (mode != AvoidMode.SHAPE) {
81
            return@handler
82
        }
83
84
        avoid.find { it.test(event.state.block, event.state.fluidState, event.pos) }?.let {
85
            event.shape = if (it.fullCube) Shapes.block() else UNSAFE_BLOCK_CAP
86
        }
87
    }
88
89
    @Suppress("unused")
90
    private val movementInputHandler = handler<MovementInputEvent>(priority = SAFETY_FEATURE) { event ->
91
        if (mode != AvoidMode.INPUT || !event.directionalInput.isMoving) {
92
            return@handler
93
        }
94
95
        val activeAvoidModes = avoid
96
        if (activeAvoidModes.isEmpty()) {
97
            return@handler
98
        }
99
100
        event.directionalInput = AvoidHazardInputPlanner.chooseSafeInput(event.directionalInput) { candidate ->
101
            isSafeInput(
102
                directionalInput = candidate,
103
                jump = event.jump,
104
                sneak = event.sneak,
105
                avoidModes = activeAvoidModes
106
            )
107
        }
108
    }
109
110
    private fun isSafeInput(
111
        directionalInput: DirectionalInput,
112
        jump: Boolean,
113
        sneak: Boolean,
114
        avoidModes: Collection<Avoid>
115
    ): Boolean {
116
        val level = mc.level ?: return true
117
118
        val simulatedInput = SimulatedPlayer.SimulatedPlayerInput.fromClientPlayer(
119
            directionalInput = directionalInput,
120
            jump = jump,
121
            sprinting = player.isSprinting,
122
            sneaking = sneak
123
        )
124
125
        val simulatedPlayer = SimulatedPlayer.fromClientPlayer(simulatedInput)
126
        simulatedPlayer.pos = player.position()
127
        var previousBoundingBox = simulatedPlayer.boundingBox
128
        // Do not reject every candidate while already on a ladder. We only block
129
        // transitions that newly enter climb-state.
130
        val startedOnLadder = Avoid.LADDERS in avoidModes && wouldEnterLadderClimbState(simulatedPlayer)
131
132
        repeat(MOVEMENT_PREDICTION_TICKS) {
133
            simulatedPlayer.tick()
134
            val currentBoundingBox = simulatedPlayer.boundingBox
135
            val sweptBoundingBox = previousBoundingBox.minmax(currentBoundingBox)
136
            val enteredLadder =
137
                Avoid.LADDERS in avoidModes &&
138
                    !startedOnLadder &&
139
                    wouldEnterLadderClimbState(simulatedPlayer)
140
141
            if (enteredLadder ||
142
                isHazardCollision(currentBoundingBox, level, avoidModes) ||
143
                isHazardCollision(sweptBoundingBox, level, avoidModes)
144
            ) {
145
                return false
146
            }
147
148
            previousBoundingBox = currentBoundingBox
149
        }
150
151
        return true
152
    }
153
154
    /**
155
     * Predict whether the simulated player would be in a vanilla climb-state
156
     * after this movement step.
157
     *
158
     * @see net.minecraft.world.entity.LivingEntity.onClimbable
159
     * @see isLadderClimbState
160
     */
161
    private fun wouldEnterLadderClimbState(simulatedPlayer: SimulatedPlayer): Boolean {
162
        return isLadderClimbStateAt(simulatedPlayer.pos.toBlockPos())
163
    }
164
165
    private fun isLadderClimbStateAt(pos: BlockPos): Boolean {
166
        val currentState = pos.state ?: return false
167
        return isLadderClimbState(currentState, pos.below().state)
168
    }
169
170
    @Suppress("CognitiveComplexMethod")
171
    private fun isHazardCollision(
172
        boundingBox: AABB,
173
        level: ClientLevel,
174
        avoidModes: Collection<Avoid>
175
    ): Boolean {
176
        if (Avoid.MAGMA in avoidModes && boundingBox.isOnMagmaBlock()) {
177
            return true
178
        }
179
180
        return boundingBox.iterateBlockPos().any { pos ->
181
            val blockState = pos.state ?: return@any false
182
            val fluidState = blockState.fluidState
183
            val block = blockState.block
184
185
            avoidModes.any { avoidMode ->
186
                when (avoidMode) {
187
                    Avoid.MAGMA -> false
188
                    Avoid.LAVA -> {
189
                        if (!avoidMode.test(block, fluidState, pos)) {
190
                            false
191
                        } else {
192
                            val fluidShape = fluidState.getShape(level, pos)
193
                            !fluidShape.isEmpty && boundingBox.intersects(fluidShape.bounds().move(pos))
194
                        }
195
                    }
196
                    Avoid.CACTI -> {
197
                        if (!avoidMode.test(block, fluidState, pos)) {
198
                            false
199
                        } else {
200
                            // Cactus damage is handled by entity-inside logic, which can trigger on block-cell
201
                            // contact. Use the whole block cell for conservative prediction.
202
                            val expandedBox = boundingBox.inflate(CACTUS_BLOCK_MARGIN, 0.0, CACTUS_BLOCK_MARGIN)
203
                            expandedBox.intersects(pos)
204
                        }
205
                    }
206
                    else -> {
207
                        if (!avoidMode.test(block, fluidState, pos)) {
208
                            false
209
                        } else {
210
                            val shape = blockState.getShape(level, pos)
211
                            !shape.isEmpty && boundingBox.intersects(shape.bounds().move(pos))
212
                        }
213
                    }
214
                }
215
            }
216
        }
217
    }
218
219
    private enum class AvoidMode(
220
        override val tag: String,
221
        override val tagAliases: List<String> = emptyList(),
222
    ) : Tagged {
223
        SHAPE("Shape"),
224
        INPUT("Input", listOf("Movement")),
225
    }
226
227
    private enum class Avoid(
228
        override val tag: String,
229
        val fullCube: Boolean = true,
230
        val test: (block: Block, fluidState: FluidState, pos: BlockPos) -> Boolean
231
    ) : Tagged {
232
        CACTI("Cacti", test = { block, _, _ ->
233
            block is CactusBlock
234
        }),
235
        BERRY_BUSH("BerryBush", test = { block, _, _ ->
236
            block is SweetBerryBushBlock
237
        }),
238
        FIRE("Fire", test = { block, _, _ ->
239
            block is FireBlock
240
        }),
241
        COBWEB("Cobwebs", test = { block, _, _ ->
242
            block is WebBlock
243
        }),
244
        LADDERS("Ladders", test = { _, _, pos ->
245
            isLadderClimbStateAt(pos)
246
        }),
247
        PRESSURE_PLATES("PressurePlates", fullCube = false, test = { block, _, _ ->
248
            block is BasePressurePlateBlock
249
        }),
250
        MAGMA("MagmaBlocks", fullCube = false, test = { _, _, pos ->
251
            pos.below().getBlock() is MagmaBlock
252
        }),
253
        LAVA("Lava", test = { _, fluidState, _ ->
254
            fluidState.`is`(Fluids.LAVA) || fluidState.`is`(Fluids.FLOWING_LAVA)
255
        }),
256
        WITHER_ROSE("WitherRose", test = { block, _, _ ->
257
            block is WitherRoseBlock
258
        }),
259
        POWDER_SNOW("PowderSnow", test = { block, _, _ ->
260
            block is PowderSnowBlock
261
        })
262
    }
263
}
264