AimBot module

AimBot: Minecraft 26.3 cheat module, full source for every implementation (2 clients: MelaHack (ThunderHack fork), LiquidBounce (Kotlin)).

2 implementationsCOMBAT

Full module source: 2 implementations

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

MelaHack (ThunderHack fork)COMBATsrc/main/java/thunder/hack/features/modules/combat/AimBot.javaJava · 317 lines · 14.6 KB

Smooth legit aiming.

SettingsModeRotationRangeAimStrengthAimSmoothAimTimeIgnoreWallsIgnoreTeamReactionTimeIgnoreInvisYawRandomPitchRandomAimPredictShoot delayFOVPredictTicksBone
AimBot.javaJava · Minecraft 26.2 · 317 lines · 14.6 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.combat;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
5
import net.minecraft.util.Mth;
6
import net.minecraft.world.InteractionHand;
7
import net.minecraft.world.entity.Entity;
8
import net.minecraft.world.entity.LivingEntity;
9
import net.minecraft.world.entity.decoration.ArmorStand;
10
import net.minecraft.world.entity.player.Player;
11
import net.minecraft.world.item.BowItem;
12
import net.minecraft.world.phys.Vec3;
13
import org.jetbrains.annotations.NotNull;
14
import thunder.hack.core.Managers;
15
import thunder.hack.core.manager.client.ModuleManager;
16
import thunder.hack.events.impl.EventSync;
17
import thunder.hack.events.impl.PlayerUpdateEvent;
18
import thunder.hack.features.modules.Module;
19
import thunder.hack.setting.Setting;
20
import thunder.hack.utility.Timer;
21
import thunder.hack.utility.math.MathUtility;
22
import thunder.hack.utility.math.PredictUtility;
23
import thunder.hack.utility.render.Render2DEngine;
24
import thunder.hack.utility.render.Render3DEngine;
25
26
import java.util.List;
27
import java.util.concurrent.CopyOnWriteArrayList;
28
29
import static net.minecraft.world.phys.HitResult.Type.ENTITY;
30
import static net.minecraft.util.Mth.wrapDegrees;
31
32
import com.mojang.blaze3d.vertex.PoseStack;
33
34
public final class AimBot extends Module {
35
    private final Setting<Mode> mode = new Setting<>("Mode", Mode.BowAim);
36
    private final Setting<Rotation> rotation = new Setting<>("Rotation", Rotation.Silent, v -> mode.getValue() != Mode.AimAssist);
37
    private final Setting<Float> aimRange = new Setting<>("Range", 20f, 1f, 30f, v -> mode.getValue() != Mode.AimAssist);
38
    private final Setting<Integer> aimStrength = new Setting<>("AimStrength", 30, 1, 100, v -> mode.getValue() == Mode.AimAssist);
39
    private final Setting<Integer> aimSmooth = new Setting<>("AimSmooth", 45, 1, 180, v -> mode.getValue() == Mode.AimAssist);
40
    private final Setting<Integer> aimtime = new Setting<>("AimTime", 2, 1, 10, v -> mode.getValue() == Mode.AimAssist);
41
    private final Setting<Boolean> ignoreWalls = new Setting<>("IgnoreWalls", true, v -> mode.getValue() == Mode.CSAim || mode.is(Mode.AimAssist));
42
    private final Setting<Boolean> ignoreTeam = new Setting<>("IgnoreTeam", true, v -> mode.getValue() == Mode.CSAim || mode.is(Mode.AimAssist));
43
    private final Setting<Integer> reactionTime = new Setting<>("ReactionTime", 80, 1, 500, v -> mode.getValue() == Mode.AimAssist && !ignoreWalls.getValue());
44
    private final Setting<Boolean> ignoreInvisible = new Setting<>("IgnoreInvis", false, v -> mode.is(Mode.AimAssist));
45
    private final Setting<Float> rotYawRandom = new Setting<>("YawRandom", 0f, 0f, 3f, v -> mode.getValue() == Mode.CSAim);
46
    private final Setting<Float> rotPitchRandom = new Setting<>("PitchRandom", 0f, 0f, 3f, v -> mode.getValue() == Mode.CSAim);
47
    private final Setting<Float> predict = new Setting<>("AimPredict", 0.5f, 0.5f, 8f, v -> mode.getValue() == Mode.CSAim);
48
    private final Setting<Integer> delay = new Setting<>("Shoot delay", 5, 0, 10, v -> mode.getValue() == Mode.CSAim);
49
    private final Setting<Integer> fov = new Setting<>("FOV", 65, 10, 360, v -> mode.getValue() == Mode.CSAim);
50
    private final Setting<Integer> predictTicks = new Setting<>("PredictTicks", 2, 0, 20, v -> mode.getValue() == Mode.BowAim);
51
    private final Setting<Bone> part = new Setting<>("Bone", Bone.Head, v -> mode.getValue() == Mode.CSAim);
52
53
    private Entity target;
54
55
    private float rotationYaw, rotationPitch, assistAcceleration;
56
    private int aimTicks = 0;
57
    private Timer visibleTime = new Timer();
58
59
    public AimBot() {
60
        super("AimBot", Category.COMBAT);
61
    }
62
63
    @EventHandler
64
    public void onPlayerUpdate(PlayerUpdateEvent event) {
65
        if (mode.getValue() == Mode.BowAim) {
66
            if (!(mc.player.getUseItem().getItem() instanceof BowItem)) return;
67
68
            Player nearestTarget = Managers.COMBAT.getTargetByFOV(128);
69
70
            if (nearestTarget == null) return;
71
72
            float currentDuration = (float) (mc.player.getUseItem().getUseDuration(mc.player) - mc.player.getTicksUsingItem()) / 20.0f;
73
74
            currentDuration = (currentDuration * currentDuration + currentDuration * 2.0f) / 3.0f;
75
76
            if (currentDuration >= 1.0f) currentDuration = 1.0f;
77
78
            float pitch = (float) (-Math.toDegrees(calculateArc(nearestTarget, currentDuration * 3.0f)));
79
80
            if (Float.isNaN(pitch)) return;
81
82
            Player predictedEntity = PredictUtility.predictPlayer(nearestTarget, predictTicks.getValue());
83
            double iX = predictedEntity.getX() - predictedEntity.xo;
84
            double iZ = predictedEntity.getZ() - predictedEntity.zo;
85
            double distance = mc.player.distanceTo(predictedEntity);
86
            distance -= distance % 2.0;
87
            iX = distance / 2.0 * iX * (mc.player.isSprinting() ? 1.3 : 1.1);
88
            iZ = distance / 2.0 * iZ * (mc.player.isSprinting() ? 1.3 : 1.1);
89
            rotationYaw = (float) Math.toDegrees(Math.atan2(predictedEntity.getZ() + iZ - mc.player.getZ(), predictedEntity.getX() + iX - mc.player.getX())) - 90.0f;
90
            rotationPitch = pitch;
91
        } else if (mode.getValue() == Mode.CSAim) {
92
            calcThread();
93
        } else {
94
            if (mc.hitResult.getType() == ENTITY)
95
                aimTicks++;
96
            else
97
                aimTicks = 0;
98
99
            if (aimTicks >= aimtime.getValue()) {
100
                assistAcceleration = 0;
101
                return;
102
            }
103
104
            Player nearestTarget = Managers.COMBAT.getNearestTarget(5);
105
            assistAcceleration += aimStrength.getValue() / 10000f;
106
107
            if (nearestTarget != null) {
108
                if (!mc.player.hasLineOfSight(nearestTarget)) {
109
                    if (!ignoreWalls.getValue())
110
                        visibleTime.reset();
111
                }
112
113
                if (!visibleTime.passedMs(reactionTime.getValue())) {
114
                    rotationYaw = Float.NaN;
115
                    return;
116
                }
117
118
                if (Float.isNaN(rotationYaw))
119
                    rotationYaw = mc.player.getYRot();
120
121
                float delta_yaw = wrapDegrees((float) wrapDegrees(Math.toDegrees(Math.atan2(nearestTarget.getEyePosition().z - mc.player.getZ(), (nearestTarget.getEyePosition().x - mc.player.getX()))) - 90) - rotationYaw);
122
                if (delta_yaw > 180)
123
                    delta_yaw = delta_yaw - 180;
124
                float deltaYaw = Mth.clamp(Mth.abs(delta_yaw), -aimSmooth.getValue(), aimSmooth.getValue());
125
                float newYaw = rotationYaw + (delta_yaw > 0 ? deltaYaw : -deltaYaw);
126
                double gcdFix = (Math.pow(mc.options.sensitivity().get() * 0.6 + 0.2, 3.0)) * 1.2;
127
                rotationYaw = (float) (newYaw - (newYaw - rotationYaw) % gcdFix);
128
            } else rotationYaw = Float.NaN;
129
        }
130
131
        if (!Float.isNaN(rotationYaw))
132
            ModuleManager.rotations.fixRotation = rotationYaw;
133
    }
134
135
    @EventHandler
136
    public void onSync(EventSync event) {
137
        if (mode.is(Mode.AimAssist))
138
            return;
139
140
        if (mode.is(Mode.CSAim)) {
141
            if (target != null && (mc.player.hasLineOfSight(target) || ignoreWalls.getValue())) {
142
                if (mc.player.tickCount % delay.getValue() == 0) {
143
                    event.addPostAction(() -> sendSequencedPacket(id -> new ServerboundUseItemPacket(InteractionHand.MAIN_HAND, id, mc.player.getYRot(), mc.player.getXRot())));
144
                }
145
            } else {
146
                rotationYaw = mc.player.getYRot();
147
                rotationPitch = mc.player.getXRot();
148
            }
149
        }
150
151
        if (target != null || (mode.getValue() == Mode.BowAim && mc.player.getUseItem().getItem() instanceof BowItem)) {
152
            if (rotation.getValue() == Rotation.Silent) {
153
                mc.player.setYRot(rotationYaw);
154
                mc.player.setXRot(rotationPitch);
155
            }
156
        }
157
    }
158
159
    @Override
160
    public void onEnable() {
161
        target = null;
162
        rotationYaw = mc.player.getYRot();
163
        rotationPitch = mc.player.getXRot();
164
    }
165
166
    public void onRender3D(PoseStack stack) {
167
        if (mode.getValue() == Mode.AimAssist) {
168
            if (Float.isNaN(rotationYaw)) return;
169
            mc.player.setYRot((float) Render2DEngine.interpolate(mc.player.getYRot(), rotationYaw, assistAcceleration));
170
            return;
171
        }
172
173
        if (target != null && (mc.player.hasLineOfSight(target) || ignoreWalls.getValue())) {
174
            if (rotation.getValue() == Rotation.Client) {
175
                mc.player.setYRot((float) Render2DEngine.interpolate(((thunder.hack.injection.accesors.IEntity) mc.player).getLastYaw(), rotationYaw, Render3DEngine.getTickDelta()));
176
                mc.player.setXRot((float) Render2DEngine.interpolate(((thunder.hack.injection.accesors.IEntity) mc.player).getLastPitch(), rotationPitch, Render3DEngine.getTickDelta()));
177
            }
178
        } else {
179
            if (mode.getValue() == Mode.CSAim) {
180
                rotationYaw = mc.player.getYRot();
181
                rotationPitch = mc.player.getXRot();
182
            }
183
        }
184
185
        if (rotation.getValue() == Rotation.Client && mode.getValue() == Mode.BowAim && mc.player.getUseItem().getItem() instanceof BowItem) {
186
            mc.player.setYRot((float) Render2DEngine.interpolate(((thunder.hack.injection.accesors.IEntity) mc.player).getLastYaw(), rotationYaw, Render3DEngine.getTickDelta()));
187
            mc.player.setXRot((float) Render2DEngine.interpolate(((thunder.hack.injection.accesors.IEntity) mc.player).getLastPitch(), rotationPitch, Render3DEngine.getTickDelta()));
188
        }
189
    }
190
191
    private float calculateArc(@NotNull Player target, double duration) {
192
        double yArc = target.getY() + (double) (target.getEyeHeight(target.getPose())) - (mc.player.getY() + (double) mc.player.getEyeHeight(mc.player.getPose()));
193
        double dX = target.getX() - mc.player.getX();
194
        double dZ = target.getZ() - mc.player.getZ();
195
        double dirRoot = Math.sqrt(dX * dX + dZ * dZ);
196
        return calculateArc(duration, dirRoot, yArc);
197
    }
198
199
    private float calculateArc(double d, double dr, double y) {
200
        y = 2.0 * y * (d * d);
201
        y = 0.05000000074505806 * ((0.05000000074505806 * (dr * dr)) + y);
202
        y = Math.sqrt(d * d * d * d - y);
203
        d = d * d - y;
204
        y = Math.atan2(d * d + y, 0.05000000074505806 * dr);
205
        d = Math.atan2(d, 0.05000000074505806 * dr);
206
        return (float) Math.min(y, d);
207
    }
208
209
    private void calcThread() {
210
        if (target == null) {
211
            findTarget();
212
            return;
213
        }
214
        if (skipEntity(target)) {
215
            target = null;
216
            return;
217
        }
218
219
        Vec3 targetVec = getResolvedPos(target).add(0, part.getValue().getH(), 0);
220
221
        if (targetVec == null)
222
            return;
223
224
        float delta_yaw = wrapDegrees((float) wrapDegrees(Math.toDegrees(Math.atan2(targetVec.z - mc.player.getZ(), (targetVec.x - mc.player.getX()))) - 90) - rotationYaw);
225
        float delta_pitch = ((float) (-Math.toDegrees(Math.atan2(targetVec.y - (mc.player.position().y + mc.player.getEyeHeight(mc.player.getPose())), Math.sqrt(Math.pow((targetVec.x - mc.player.getX()), 2) + Math.pow(targetVec.z - mc.player.getZ(), 2))))) - rotationPitch);
226
227
        if (delta_yaw > 180)
228
            delta_yaw = delta_yaw - 180;
229
230
        float deltaYaw = Mth.clamp(Mth.abs(delta_yaw), MathUtility.random(-40.0F, -60.0F), MathUtility.random(40.0F, 60.0F));
231
232
        float newYaw = rotationYaw + (delta_yaw > 0 ? deltaYaw : -deltaYaw) + MathUtility.random(-rotYawRandom.getValue(), rotYawRandom.getValue());
233
        float newPitch = Mth.clamp(rotationPitch + Mth.clamp(delta_pitch, MathUtility.random(-10.0F, -20.0F), MathUtility.random(10, 20)), -90.0F, 90.0F) + MathUtility.random(-rotPitchRandom.getValue(), rotPitchRandom.getValue());
234
235
        double gcdFix = (Math.pow(mc.options.sensitivity().get() * 0.6 + 0.2, 3.0) * 8.0) * 0.15000000596046448;
236
        rotationYaw = (float) (newYaw - (newYaw - rotationYaw) % gcdFix);
237
        rotationPitch = (float) (newPitch - (newPitch - rotationPitch) % gcdFix);
238
    }
239
240
    public void findTarget() {
241
        List<Entity> first_stage = new CopyOnWriteArrayList<>();
242
        for (Entity entity : mc.level.entitiesForRendering()) {
243
            if (skipEntity(entity)) continue;
244
            first_stage.add(entity);
245
        }
246
247
        float best_fov = fov.getValue();
248
        Entity best_entity = null;
249
250
        for (Entity ent : first_stage) {
251
            float temp_fov = Math.abs(((float) Mth.wrapDegrees(Math.toDegrees(Math.atan2(ent.getZ() - mc.player.getZ(), ent.getX() - mc.player.getX())) - 90.0)) - Mth.wrapDegrees(mc.player.getYRot()));
252
            if (temp_fov < best_fov) {
253
                best_entity = ent;
254
                best_fov = temp_fov;
255
            }
256
        }
257
        target = best_entity;
258
    }
259
260
    private boolean skipEntity(Entity entity) {
261
        if (!(entity instanceof LivingEntity ent)) return true;
262
        if (ent.isDeadOrDying()) return true;
263
        if (!entity.isAlive()) return true;
264
        if (entity instanceof ArmorStand) return true;
265
        if (ModuleManager.antiBot.isEnabled() && AntiBot.bots.contains(entity)) return true;
266
        if (!(entity instanceof Player pl)) return true;
267
        if (entity == mc.player) return true;
268
        if (entity.isInvisible() && ignoreInvisible.getValue()) return true;
269
        if (Managers.FRIEND.isFriend(pl)) return true;
270
        if (Math.abs(getYawToEntityNew(entity)) > fov.getValue()) return true;
271
        if (pl.getTeamColor() == mc.player.getTeamColor() && ignoreTeam.getValue() && mc.player.getTeamColor() != 16777215)
272
            return true;
273
        return mc.player.distanceToSqr(getResolvedPos(entity)) > aimRange.getPow2Value();
274
    }
275
276
    public float getYawToEntityNew(@NotNull Entity entity) {
277
        return getYawBetween(mc.player.getYRot(), mc.player.getX(), mc.player.getZ(), entity.getX(), entity.getZ());
278
    }
279
280
    public float getYawBetween(float yaw, double srcX, double srcZ, double destX, double destZ) {
281
        double xDist = destX - srcX;
282
        double zDist = destZ - srcZ;
283
        float yaw1 = (float) (StrictMath.atan2(zDist, xDist) * 180.0 / 3.141592653589793) - 90.0f;
284
        return yaw + wrapDegrees(yaw1 - yaw);
285
    }
286
287
    private Vec3 getResolvedPos(@NotNull Entity pl) {
288
        return new Vec3(pl.getX() + (pl.getX() - pl.xo) * predict.getValue(), pl.getY(), pl.getZ() + (pl.getZ() - pl.zo) * predict.getValue());
289
    }
290
291
    private enum Bone {
292
        Head(1.7f),
293
        Neck(1.5f),
294
        Torso(1.f),
295
        Tights(0.8f),
296
        Feet(0.25f);
297
298
        private final float h;
299
300
        Bone(float h) {
301
            this.h = h;
302
        }
303
304
        public float getH() {
305
            return h;
306
        }
307
    }
308
309
    private enum Rotation {
310
        Client, Silent
311
    }
312
313
    private enum Mode {
314
        CSAim, AimAssist, BowAim
315
    }
316
}
317
LiquidBounce (Kotlin)COMBATsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleAimbot.ktKotlin · 226 lines · 8.6 KB

Automatically faces targets nearby.

SettingsLazyRotation
ModuleAimbot.ktKotlin · Minecraft 26.2 · 226 lines · 8.6 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.combat
20
21
import net.ccbluex.liquidbounce.config.types.list.Tagged
22
import net.ccbluex.liquidbounce.event.events.MouseRotationEvent
23
import net.ccbluex.liquidbounce.event.events.RotationUpdateEvent
24
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
25
import net.ccbluex.liquidbounce.event.handler
26
import net.ccbluex.liquidbounce.features.module.ClientModule
27
import net.ccbluex.liquidbounce.features.module.ModuleCategories
28
import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.KillAuraRequirements
29
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug
30
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug.debugGeometry
31
import net.ccbluex.liquidbounce.render.engine.type.Color4b
32
import net.ccbluex.liquidbounce.utils.aiming.RotationTarget
33
import net.ccbluex.liquidbounce.utils.aiming.data.Rotation
34
import net.ccbluex.liquidbounce.utils.aiming.data.RotationWithVector
35
import net.ccbluex.liquidbounce.utils.aiming.features.MovementCorrection
36
import net.ccbluex.liquidbounce.utils.aiming.features.processors.anglesmooth.impl.InterpolationAngleSmooth
37
import net.ccbluex.liquidbounce.utils.aiming.features.processors.anglesmooth.impl.LinearAngleSmooth
38
import net.ccbluex.liquidbounce.utils.aiming.features.processors.anglesmooth.impl.SigmoidAngleSmooth
39
import net.ccbluex.liquidbounce.utils.aiming.point.PointTracker
40
import net.ccbluex.liquidbounce.utils.aiming.preference.LeastDifferencePreference
41
import net.ccbluex.liquidbounce.utils.aiming.utils.RotationUtil
42
import net.ccbluex.liquidbounce.utils.aiming.utils.raytraceBox
43
import net.ccbluex.liquidbounce.utils.aiming.utils.setRotation
44
import net.ccbluex.liquidbounce.utils.client.Timer
45
import net.ccbluex.liquidbounce.utils.combat.TargetPriority
46
import net.ccbluex.liquidbounce.utils.combat.TargetTracker
47
import net.ccbluex.liquidbounce.utils.entity.rotation
48
import net.ccbluex.liquidbounce.utils.inventory.InventoryManager
49
import net.ccbluex.liquidbounce.utils.raytracing.isLookingAtEntity
50
import net.ccbluex.liquidbounce.utils.render.TargetRenderer
51
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
52
import net.minecraft.world.entity.Entity
53
54
/**
55
 * Aimbot module
56
 *
57
 * Automatically faces selected entities around you.
58
 */
59
object ModuleAimbot : ClientModule("Aimbot", ModuleCategories.COMBAT, aliases = listOf("AimAssist", "AutoAim")) {
60
61
    private val range = float("Range", 4.2f, 1f..8f)
62
63
    val targetTracker = tree(TargetTracker(TargetPriority.DIRECTION, range = range))
64
65
    init {
66
        tree(TargetRenderer(this, targetTracker))
67
    }
68
    private val pointTracker = tree(PointTracker(this))
69
    private val lazyRotation by boolean("LazyRotation", false)
70
71
    private val requires by multiEnumChoice<KillAuraRequirements>("Requires")
72
73
    private val requirementsMet
74
        get() = mc.gui.screen() == null && requires.all { it.asBoolean }
75
76
    private var angleSmooth = modes(this, "AngleSmooth") {
77
        arrayOf(
78
            InterpolationAngleSmooth(it),
79
            SigmoidAngleSmooth(it),
80
            LinearAngleSmooth(it)
81
        )
82
    }
83
84
    private val axis by multiEnumChoice<Axis>("Axis", Axis.HORIZONTAL, Axis.VERTICAL)
85
86
    private val ignores by multiEnumChoice<IgnoreOpened>("Ignore")
87
88
    private var targetRotation: Rotation? = null
89
    private var playerRotation: Rotation? = null
90
91
    @Suppress("unused", "ComplexCondition")
92
    private val tickHandler = handler<RotationUpdateEvent> { _ ->
93
        playerRotation = player.rotation
94
95
        if (!requirementsMet) {
96
            targetTracker.reset()
97
            targetRotation = null
98
            return@handler
99
        }
100
101
        targetRotation = findNextTargetRotation()?.let { (target, rotation) ->
102
            angleSmooth.activeMode.process(
103
                RotationTarget(
104
                    rotation = rotation.rotation,
105
                    entity = target,
106
                    processors = listOf(angleSmooth.activeMode),
107
                    ticksUntilReset = 1,
108
                    resetThreshold = 1f,
109
                    considerInventory = true,
110
                    movementCorrection = MovementCorrection.CHANGE_LOOK
111
                ),
112
                player.rotation,
113
                rotation.rotation
114
            )
115
        }
116
117
        // Update Auto Weapon
118
        ModuleAutoWeapon.onTarget(targetTracker.target)
119
    }
120
121
    override fun onDisabled() {
122
        targetTracker.reset()
123
    }
124
125
    @Suppress("unused")
126
    private val renderHandler = handler<WorldRenderEvent> { event ->
127
        val partialTicks = event.partialTicks
128
        val target = targetTracker.target ?: return@handler
129
130
        if (IgnoreOpened.SCREEN !in ignores && mc.gui.screen() != null) {
131
            return@handler
132
        }
133
134
        if (IgnoreOpened.CONTAINER !in ignores && (InventoryManager.isInventoryOpen ||
135
                mc.gui.screen() is AbstractContainerScreen<*>)) {
136
            return@handler
137
        }
138
139
        lookAt(partialTicks)
140
    }
141
142
    @Suppress("unused")
143
    private val mouseMovement = handler<MouseRotationEvent> { event ->
144
        fun updateRotation(rotation: Rotation): Rotation =
145
            RotationUtil.applyMouseTurnDelta(rotation, event.cursorDeltaX, event.cursorDeltaY)
146
147
        playerRotation?.let { rotation ->
148
            playerRotation = updateRotation(rotation)
149
        }
150
151
        targetRotation?.let { rotation ->
152
            targetRotation = updateRotation(rotation)
153
        }
154
    }
155
156
    /**
157
     * Looks at the target rotation, with interpolation based on the timer speed and partial ticks to make it smooth.
158
     */
159
    private fun lookAt(partialTicks: Float) {
160
        val playerRotation = playerRotation ?: return
161
        val targetRotation = targetRotation ?: return
162
        val timerSpeed = Timer.timerSpeed
163
        val interpolatedRotation = playerRotation.interpolateTo(targetRotation, timerSpeed * partialTicks)
164
165
        player.setRotation(
166
            Rotation(
167
                yaw = if (Axis.HORIZONTAL in axis) interpolatedRotation.yaw else playerRotation.yaw,
168
                pitch = if (Axis.VERTICAL in axis) interpolatedRotation.pitch else playerRotation.pitch,
169
            )
170
        )
171
    }
172
173
    private fun findNextTargetRotation(): Pair<Entity, RotationWithVector>? {
174
        for (entity in targetTracker.targets()) {
175
            if (lazyRotation) {
176
                val currentRotation = player.rotation
177
                val currentHit = isLookingAtEntity(
178
                    fromEntity = player,
179
                    toEntity = entity,
180
                    rotation = currentRotation,
181
                    range = targetTracker.maxRange.toDouble(),
182
                    throughWallsRange = 0.0,
183
                )
184
185
                if (currentHit != null) {
186
                    targetTracker.target = entity
187
                    return entity to RotationWithVector(currentRotation, currentHit.location)
188
                }
189
            }
190
191
            val eyes = player.eyePosition
192
            val point = pointTracker.findPoint(eyes, entity)
193
194
            debugGeometry("Box") { ModuleDebug.DebuggedBox(point.box, Color4b.ORANGE.with(a = 90)) }
195
            debugGeometry("Point") { ModuleDebug.DebuggedPoint(point.pos, Color4b.WHITE, size = 0.1) }
196
197
            val rotationPreference = LeastDifferencePreference.leastDifferenceToLastPoint(eyes, point.pos)
198
            val rotation = raytraceBox(
199
                eyes = eyes,
200
                box = point.box,
201
                range = targetTracker.maxRange.toDouble(),
202
                wallsRange = 0.0,
203
                rotationPreference = rotationPreference
204
            ) ?: continue
205
206
            targetTracker.target = entity
207
            return entity to rotation
208
        }
209
210
        targetTracker.reset()
211
        return null
212
    }
213
214
    private enum class IgnoreOpened(
215
        override val tag: String
216
    ) : Tagged {
217
        SCREEN("Screen"),
218
        CONTAINER("Container")
219
    }
220
221
    private enum class Axis(override val tag: String) : Tagged {
222
        HORIZONTAL("Horizontal"),
223
        VERTICAL("Vertical")
224
    }
225
}
226