EasyPearl module

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

1 implementationMISC

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)MISCsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleEasyPearl.ktKotlin · 265 lines · 10.0 KB

Throws pearl to where you looking at.

SettingsAimOffThresholdReachableCheckShowDistance
ModuleEasyPearl.ktKotlin · Minecraft 26.2 · 265 lines · 10.0 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.misc
20
21
import net.ccbluex.liquidbounce.event.events.GameTickEvent
22
import net.ccbluex.liquidbounce.event.events.OverlayRenderEvent
23
import net.ccbluex.liquidbounce.event.events.PlayerInteractItemEvent
24
import net.ccbluex.liquidbounce.event.events.RotationUpdateEvent
25
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
26
import net.ccbluex.liquidbounce.event.handler
27
import net.ccbluex.liquidbounce.features.module.ClientModule
28
import net.ccbluex.liquidbounce.features.module.ModuleCategories
29
import net.ccbluex.liquidbounce.render.FontManager
30
import net.ccbluex.liquidbounce.render.FULL_BOX
31
import net.ccbluex.liquidbounce.render.drawBox
32
import net.ccbluex.liquidbounce.render.drawBoxSide
33
import net.ccbluex.liquidbounce.render.drawGradientSides
34
import net.ccbluex.liquidbounce.render.engine.font.HorizontalAnchor
35
import net.ccbluex.liquidbounce.render.engine.font.VerticalAnchor
36
import net.ccbluex.liquidbounce.render.engine.type.Color4b
37
import net.ccbluex.liquidbounce.render.renderEnvironment
38
import net.ccbluex.liquidbounce.render.withPositionRelativeToCamera
39
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
40
import net.ccbluex.liquidbounce.utils.aiming.RotationsValueGroup
41
import net.ccbluex.liquidbounce.utils.aiming.data.Rotation
42
import net.ccbluex.liquidbounce.utils.aiming.projectiles.SituationalProjectileAngleCalculator
43
import net.ccbluex.liquidbounce.utils.block.state
44
import net.ccbluex.liquidbounce.utils.client.chat
45
import net.ccbluex.liquidbounce.utils.client.markAsError
46
import net.ccbluex.liquidbounce.utils.entity.PositionExtrapolation
47
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
48
import net.ccbluex.liquidbounce.utils.inventory.Slots
49
import net.ccbluex.liquidbounce.utils.inventory.useHotbarSlotOrOffhand
50
import net.ccbluex.liquidbounce.utils.kotlin.Priority
51
import net.ccbluex.liquidbounce.utils.math.toFixed
52
import net.ccbluex.liquidbounce.utils.math.toBlockPos
53
import net.ccbluex.liquidbounce.utils.render.WorldToScreen
54
import net.ccbluex.liquidbounce.utils.text.asPlainText
55
import net.ccbluex.liquidbounce.utils.render.trajectory.TrajectoryInfo
56
import net.minecraft.core.Direction
57
import net.minecraft.world.entity.EntityDimensions
58
import net.minecraft.world.item.Items
59
import net.minecraft.world.level.block.RenderShape
60
import net.minecraft.world.phys.HitResult
61
import net.minecraft.world.phys.Vec3
62
63
/**
64
 * EasyPearl module
65
 *
66
 * Throw pearl to where you are looking at.
67
 */
68
object ModuleEasyPearl :
69
    ClientModule("EasyPearl", ModuleCategories.MISC, aliases = listOf("PearlHelper", "PearlAssist", "PearlTP")) {
70
    private val aimOffThreshold by float("AimOffThreshold", 2f, 0.5f..10f)
71
    private val reachableCheck by boolean("ReachableCheck", true)
72
    private val rotation = tree(RotationsValueGroup(this))
73
74
    private val showDistance by boolean("ShowDistance", true)
75
76
    private var targetPosition: Vec3? = null
77
78
    private val fontRenderer get() = FontManager.FONT_RENDERER
79
80
    var currentTargetRotation : Rotation? = null
81
        private set
82
83
    private val enderPearlSlot: HotbarItemSlot?
84
        get() = Slots.OffhandWithHotbar.findSlot(Items.ENDER_PEARL)
85
86
    override fun onDisabled() {
87
        currentTargetRotation = null
88
        super.onDisabled()
89
    }
90
91
    /**
92
     * Handler throw pearl by player self.
93
     */
94
    @Suppress("unused")
95
    private val interactItemHandler = handler<PlayerInteractItemEvent> { event ->
96
        if (!isHoldingPearl() || !mc.options.keyUse.isDown) {
97
            return@handler
98
        }
99
100
        val hitResult = getPositionPlayerLookAt()
101
        // While reachable check is enabled, we will check if the player
102
        // is looking at a block father than pearl can reach
103
        if (reachableCheck && getTargetRotation(hitResult.location) == null
104
            && hitResult.type != HitResult.Type.MISS) {
105
            chat(markAsError(message("noInReachWarning")))
106
            event.cancelEvent()
107
            targetPosition = null
108
            return@handler
109
        }
110
        targetPosition = hitResult.location
111
112
        // check if we are rotating to the target position correctly
113
        if (isRotationDone(targetPosition!!)) {
114
            targetPosition = null
115
        } else {
116
            event.cancelEvent()
117
        }
118
    }
119
120
    @Suppress("unused")
121
    private val rotationHandler = handler<RotationUpdateEvent> {
122
        /**
123
         * handler for rotation update event,and rotate to the target rotation
124
         */
125
        val finalTargetRotation = getTargetRotation(targetPosition ?: return@handler) ?: return@handler
126
127
        RotationManager.setRotationTarget(
128
            rotation.toRotationTarget(finalTargetRotation),
129
            Priority.IMPORTANT_FOR_PLAYER_LIFE,
130
            this@ModuleEasyPearl,
131
        )
132
    }
133
134
    @Suppress("unused")
135
    private val tickHandler = handler<GameTickEvent> {
136
        /**
137
         * handler for tick event,and check if we are rotating to the target rotation correctly,if yes,throw the pearl
138
         */
139
        currentTargetRotation = targetPosition?.let(::getTargetRotation) ?: return@handler
140
141
        if (isRotationDone(targetPosition ?: return@handler)) {
142
            useHotbarSlotOrOffhand(
143
                enderPearlSlot ?: return@handler,
144
                0,
145
                currentTargetRotation!!.yaw,
146
                currentTargetRotation!!.pitch,
147
            )
148
            targetPosition = null
149
            currentTargetRotation = null
150
        }
151
    }
152
153
    /**
154
     * handler for world render event,and render the target position
155
     */
156
    @Suppress("unused")
157
    private val worldRenderHandler = handler<WorldRenderEvent> { event ->
158
        if (!isHoldingPearl()) {
159
            return@handler
160
        }
161
162
        val pos = getPositionPlayerLookAt(event.partialTicks)?.location ?: return@handler
163
        val blockPos = pos.toBlockPos()
164
        val state = blockPos.state ?: return@handler
165
166
        event.renderEnvironment {
167
            val color = targetColor(pos)
168
169
            val baseColor = color.with(a = 50)
170
            val transparentColor = baseColor.with(a = 0)
171
            val outlineColor = color.with(a = 200)
172
173
            withPositionRelativeToCamera(blockPos) {
174
                if (state.renderShape != RenderShape.MODEL && state.isAir) {
175
                    drawBoxSide(
176
                        FULL_BOX,
177
                        Direction.DOWN,
178
                        baseColor,
179
                        outlineColor,
180
                    )
181
                    drawGradientSides(0.7, baseColor, transparentColor, FULL_BOX)
182
                } else {
183
                    drawBox(
184
                        FULL_BOX,
185
                        baseColor,
186
                        outlineColor,
187
                    )
188
                }
189
            }
190
        }
191
    }
192
193
    @Suppress("unused")
194
    private val overlayRenderHandler = handler<OverlayRenderEvent> { event ->
195
        if (!isHoldingPearl() || !showDistance) {
196
            return@handler
197
        }
198
199
        val pos = getPositionPlayerLookAt(event.tickDelta)?.location ?: return@handler
200
        pos.toBlockPos().state ?: return@handler
201
202
        val screenPos = WorldToScreen.calculateScreenPos(
203
            pos.add(0.0, player.eyeHeight.toDouble(), 0.0)
204
        ) ?: return@handler
205
        val distanceText = "${player.position().distanceTo(pos).toFixed(1)}m".asPlainText()
206
        val fontRenderer = fontRenderer
207
208
        with(event.context) {
209
            pose().pushMatrix()
210
            pose().translate(screenPos.x, screenPos.y)
211
            pose().scale(fontRenderer.scaleToVanillaFont)
212
213
            fontRenderer.draw(fontRenderer.process(distanceText, targetColor(pos))) {
214
                horizontalAnchor = HorizontalAnchor.CENTER
215
                verticalAnchor = VerticalAnchor.MIDDLE
216
                shadow = true
217
            }
218
219
            pose().popMatrix()
220
        }
221
    }
222
223
    private fun isHoldingPearl() =
224
        player.mainHandItem.item == Items.ENDER_PEARL || player.offhandItem.item == Items.ENDER_PEARL
225
226
    private fun targetColor(pos: Vec3) =
227
        if (getTargetRotation(pos) != null) {
228
            Color4b(0x20, 0xC2, 0x06)
229
        } else {
230
            Color4b(0xD7, 0x09, 0x09)
231
        }
232
233
    /**
234
     * check if we are rotating to the target rotation correctly
235
     * @param targetPosition the target position
236
     * @return true if we are rotating to the target rotation correctly, false otherwise
237
     */
238
    @Suppress("ReturnCount")
239
    private fun isRotationDone(targetPosition: Vec3): Boolean {
240
        return RotationManager.serverRotation.directionAngleTo(
241
            getTargetRotation(targetPosition) ?: return true,
242
        ) <= aimOffThreshold
243
    }
244
245
    /**
246
     * get the position player look at
247
     * @return the position player look at
248
     */
249
    private fun getPositionPlayerLookAt(partialTicks: Float = 0f) =
250
        player.pick(1000.0, partialTicks, false)
251
252
    /**
253
     * get the target rotation for the target position
254
     * @param targetPosition the target position
255
     * @return the target rotation for the target position
256
     */
257
    private fun getTargetRotation(targetPosition: Vec3): Rotation? =
258
        SituationalProjectileAngleCalculator.calculateAngleFor(
259
            TrajectoryInfo.GENERIC,
260
            sourcePos = player.position(),
261
            targetPosFunction = PositionExtrapolation.constant(targetPosition),
262
            targetShape = EntityDimensions.fixed(1.0F, 0.0F),
263
        )
264
}
265