ElytraTarget module

ElytraTarget: Minecraft 26.3 cheat module, full source for every implementation (2 clients: Combatant, 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.

CombatantCOMBATsrc/main/java/combatant/client/features/module/modules/combat/ElytraTarget.javaJava · 1,712 lines · 64.5 KB
SettingselytratargetSpeedThresholdelytratargetSwapBackelytratargetSilentSwapelytratargetTargetModeelytratargetPrepareRotationselytratargetPursuitModeelytratargetIdealChaseDistanceelytratargetOvertakeHeightelytratargetOvertakeForwardelytratargetDiveHorizontalDistanceelytratargetAttackSetupSpeedelytratargetRecastModeelytratargetAutoTakeoffelytratargetTargetRangeelytratargetTargetFovelytratargetPursuitPredictionTickselytratargetSolidBlockDodgeelytratargetBlockDodgePredictionTickselytratargetBlockDodgeMinDamageelytratargetBlockDodgeHealthBufferelytratargetCrystalFearelytratargetCrystalFearRangeelytratargetCrystalFearPredictionTickselytratargetCrystalFearMinDamageelytratargetCrystalFearHealthBuffer
ElytraTarget.javaJava · Minecraft 26.2 · 1,712 lines · 64.5 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.combat;
9
10
import combatant.client.events.impl.*;
11
import combatant.client.features.module.*;
12
import combatant.client.features.module.Module;
13
import net.minecraft.client.Minecraft;
14
import net.minecraft.client.player.LocalPlayer;
15
import net.minecraft.core.Direction;
16
import net.minecraft.core.Holder;
17
import net.minecraft.core.registries.Registries;
18
import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
19
import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket;
20
import net.minecraft.util.Mth;
21
import net.minecraft.world.entity.EquipmentSlot;
22
import net.minecraft.world.entity.LivingEntity;
23
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
24
import net.minecraft.world.entity.player.Player;
25
import net.minecraft.world.item.ItemStack;
26
import net.minecraft.world.item.Items;
27
import net.minecraft.world.item.enchantment.Enchantment;
28
import net.minecraft.world.item.enchantment.EnchantmentHelper;
29
import net.minecraft.world.item.enchantment.Enchantments;
30
import net.minecraft.world.level.ClipContext;
31
import net.minecraft.world.phys.AABB;
32
import net.minecraft.world.phys.HitResult;
33
import net.minecraft.world.phys.Vec3;
34
import combatant.client.config.common.CommonSettingSchemas;
35
import combatant.client.config.values.BooleanValue;
36
import combatant.client.config.values.ModeValue;
37
import combatant.client.config.values.NumberValue;
38
import combatant.client.events.EventHandler;
39
import combatant.client.events.impl.*;
40
import combatant.client.features.module.*;
41
import combatant.client.util.aiming.RotationManager;
42
import combatant.client.util.aiming.RotationTarget;
43
import combatant.client.util.aiming.data.Rotation;
44
import combatant.client.util.aiming.features.MovementCorrection;
45
import combatant.client.util.player.ElytraRecastUtil;
46
import combatant.client.util.player.inventory.FireworkUseController;
47
import combatant.client.util.player.simulation.PlayerSimulationCache;
48
import combatant.client.util.target.TargetManager;
49
import combatant.client.util.world.ExplosionDamageUtil;
50
51
import java.util.List;
52
53
//todo Description
54
@ModuleInfo(
55
        id = "elytratarget",
56
        displayName = "ElytraTarget",
57
        category = ModuleCategory.COMBAT
58
)
59
public final class ElytraTarget extends Module {
60
61
    private static final int PURSUIT_ROTATION_PRIORITY = 80;
62
    private static final int CRYSTAL_FEAR_ROTATION_PRIORITY = 130;
63
    private static final int BLOCK_DODGE_ROTATION_PRIORITY = 140;
64
    private static final int FIREWORK_SYNC_PRIORITY = -1000;
65
    private static final int FIREWORK_SPEED_FACTOR = 72;
66
    private static final int FALL_FLYING_RESTART_DELAY_TICKS = 5;
67
    private static final int HIT_STATUS_READY_TICKS = 5;
68
    private static final int AUTO_TAKEOFF_COOLDOWN_TICKS = 12;
69
    private static final double SIDE_RAYCAST_DISTANCE = 14.0;
70
    private static final double BLOCK_DODGE_SWEEP_MARGIN = 0.08;
71
    private static final double COLLISION_CLEARANCE_MARGIN = 1.25;
72
    private static final double GROUND_TARGET_STILL_SPEED = 0.08;
73
    private static final double ORBIT_MIN_RADIUS = 1.15;
74
    private static final double ORBIT_MAX_RADIUS = 3.35;
75
    private static final double ORBIT_ATTACK_RANGE_MARGIN = 0.22;
76
    private static final double CRYSTAL_FEAR_SWEEP_MARGIN = 0.35;
77
    private static final double CRYSTAL_FEAR_SAFE_DISTANCE = 7.25;
78
    private static final double ORBIT_SIDE_SWITCH_DOT = 0.18;
79
    private static final int TARGET_FOCUS_HOLD_TICKS = 45;
80
    private static final double TARGET_FOCUS_RANGE_MULTIPLIER = 1.35;
81
    private static final double[] BLOCK_DODGE_CANDIDATE_ANGLES = {
82
            -65.0, 65.0, -105.0, 105.0, -35.0, 35.0, 180.0
83
    };
84
    private final Minecraft mc = Minecraft.getInstance();
85
    private final NumberValue<Integer> speedThreshold =
86
            numCommon(
87
                    "elytratargetSpeedThreshold",
88
                    "firework_speed",
89
                    CommonSettingSchemas.ELYTRA_FIREWORK_SPEED,
90
                    30,
91
                    0,
92
                    100
93
            );
94
    private final BooleanValue swapBack =
95
            boolCommon(
96
                    "elytratargetSwapBack",
97
                    "swap_back",
98
                    CommonSettingSchemas.INVENTORY_RESTORE_ITEM,
99
                    true
100
            );
101
    private final BooleanValue silentSwap =
102
            visibleWhen(boolCommon(
103
                    "elytratargetSilentSwap",
104
                    "silent_swap",
105
                    CommonSettingSchemas.ELYTRA_FIREWORK_SILENT_SWAP,
106
                    true
107
            ), swapBack::get);
108
    private final ModeValue targetMode =
109
            modeSetting(
110
                    "elytratargetTargetMode",
111
                    "target_mode",
112
                    "both",
113
                    "both",
114
                    "flying",
115
                    "grounded"
116
            );
117
    private final BooleanValue prepareRotations =
118
            boolCommon(
119
                    "elytratargetPrepareRotations",
120
                    "prepare_rotations",
121
                    CommonSettingSchemas.ELYTRA_PREPARE_ROTATIONS,
122
                    true
123
            );
124
    private final ModeValue pursuitMode =
125
            modeSetting(
126
                    "elytratargetPursuitMode",
127
                    "pursuit_mode",
128
                    "auto",
129
                    "off",
130
                    "chase",
131
                    "high_pass",
132
                    "auto"
133
            );
134
    private final NumberValue<Float> idealChaseDistance =
135
            visibleWhen(num(
136
                    "elytratargetIdealChaseDistance",
137
                    "ideal_chase_distance",
138
                    7.0f,
139
                    2.0f,
140
                    18.0f
141
            ), this::isPursuitEnabled);
142
    private final NumberValue<Float> overtakeHeight =
143
            visibleWhen(num(
144
                    "elytratargetOvertakeHeight",
145
                    "overtake_height",
146
                    7.0f,
147
                    2.0f,
148
                    18.0f
149
            ), this::usesHighPassSettings);
150
    private final NumberValue<Float> overtakeForward =
151
            visibleWhen(num(
152
                    "elytratargetOvertakeForward",
153
                    "overtake_forward",
154
                    4.0f,
155
                    0.0f,
156
                    16.0f
157
            ), this::usesHighPassSettings);
158
    private final NumberValue<Float> diveHorizontalDistance =
159
            visibleWhen(num(
160
                    "elytratargetDiveHorizontalDistance",
161
                    "dive_horizontal_distance",
162
                    5.0f,
163
                    1.0f,
164
                    12.0f
165
            ), this::usesHighPassSettings);
166
    private final NumberValue<Float> attackSetupSpeed =
167
            visibleWhen(num(
168
                    "elytratargetAttackSetupSpeed",
169
                    "attack_setup_speed",
170
                    0.75f,
171
                    0.15f,
172
                    3.0f
173
            ), this::usesHighPassSettings);
174
    private final ModeValue recastMode =
175
            modeSetting(
176
                    "elytratargetRecastMode",
177
                    "recast_mode",
178
                    "grim",
179
                    "normal",
180
                    "grim"
181
            );
182
    private final BooleanValue autoTakeoff =
183
            bool(
184
                    "elytratargetAutoTakeoff",
185
                    "auto_takeoff",
186
                    false
187
            );
188
    private final NumberValue<Float> targetRange =
189
            visibleWhen(num(
190
                    "elytratargetTargetRange",
191
                    "target_range",
192
                    42.0f,
193
                    6.0f,
194
                    96.0f
195
            ), this::hasTargetingPurpose);
196
    private final NumberValue<Float> targetFov =
197
            visibleWhen(num(
198
                    "elytratargetTargetFov",
199
                    "target_fov",
200
                    120.0f,
201
                    10.0f,
202
                    180.0f
203
            ), this::hasTargetingPurpose);
204
    private final NumberValue<Integer> pursuitPredictionTicks =
205
            visibleWhen(num(
206
                    "elytratargetPursuitPredictionTicks",
207
                    "pursuit_prediction_ticks",
208
                    6,
209
                    0,
210
                    20
211
            ), this::hasTargetingPurpose);
212
    private final BooleanValue solidBlockDodge =
213
            bool(
214
                    "elytratargetSolidBlockDodge",
215
                    "solid_block_dodge",
216
                    false
217
            );
218
    private final NumberValue<Integer> blockDodgePredictionTicks =
219
            visibleWhen(num(
220
                    "elytratargetBlockDodgePredictionTicks",
221
                    "block_dodge_prediction_ticks",
222
                    10,
223
                    3,
224
                    30
225
            ), solidBlockDodge::get);
226
    private final NumberValue<Float> blockDodgeMinDamage =
227
            visibleWhen(num(
228
                    "elytratargetBlockDodgeMinDamage",
229
                    "block_dodge_min_damage",
230
                    5.0f,
231
                    1.0f,
232
                    20.0f
233
            ), solidBlockDodge::get);
234
    private final NumberValue<Float> blockDodgeHealthBuffer =
235
            visibleWhen(num(
236
                    "elytratargetBlockDodgeHealthBuffer",
237
                    "block_dodge_health_buffer",
238
                    8.0f,
239
                    0.0f,
240
                    20.0f
241
            ), solidBlockDodge::get);
242
    private final BooleanValue crystalFear =
243
            bool(
244
                    "elytratargetCrystalFear",
245
                    "crystal_fear",
246
                    true
247
            );
248
    private final NumberValue<Float> crystalFearRange =
249
            visibleWhen(num(
250
                    "elytratargetCrystalFearRange",
251
                    "crystal_fear_range",
252
                    7.0f,
253
                    3.0f,
254
                    12.0f
255
            ), crystalFear::get);
256
    private final NumberValue<Integer> crystalFearPredictionTicks =
257
            visibleWhen(num(
258
                    "elytratargetCrystalFearPredictionTicks",
259
                    "crystal_fear_prediction_ticks",
260
                    3,
261
                    0,
262
                    12
263
            ), crystalFear::get);
264
    private final NumberValue<Float> crystalFearMinDamage =
265
            visibleWhen(num(
266
                    "elytratargetCrystalFearMinDamage",
267
                    "crystal_fear_min_damage",
268
                    6.0f,
269
                    1.0f,
270
                    20.0f
271
            ), crystalFear::get);
272
    private final NumberValue<Float> crystalFearHealthBuffer =
273
            visibleWhen(num(
274
                    "elytratargetCrystalFearHealthBuffer",
275
                    "crystal_fear_health_buffer",
276
                    7.0f,
277
                    0.0f,
278
                    20.0f
279
            ), crystalFear::get);
280
    private LivingEntity target;
281
    private boolean preparingRotation;
282
    private Rotation pendingRotation;
283
    private Direction lastDirection;
284
    private boolean attackWindowActive;
285
    private PursuitPhase pursuitPhase = PursuitPhase.NONE;
286
    private boolean pursuitRotationActive;
287
    private int restartFallFlyingTicks;
288
    private int hitStatusTicks = HIT_STATUS_READY_TICKS;
289
    private boolean queuedFireworkUse;
290
    private int orbitSide = 1;
291
    private int focusedTargetId = -1;
292
    private int targetFocusTicks;
293
    private boolean autoTakeoffPending;
294
    private boolean queuedAutoTakeoffJump;
295
    private boolean queuedAutoTakeoffRelease;
296
    private boolean queuedAutoTakeoffStartGlide;
297
    private int autoTakeoffGlideDelayTicks;
298
    private int autoTakeoffCooldownTicks;
299
300
    private static Vec3 horizontal(Vec3 vector) {
301
        return new Vec3(vector.x, 0.0, vector.z);
302
    }
303
304
    private static double horizontalDistance(Vec3 a, Vec3 b) {
305
        return Math.hypot(a.x - b.x, a.z - b.z);
306
    }
307
308
    private static Vec3 rotateHorizontal(Vec3 vector, double degrees) {
309
        double radians = Math.toRadians(degrees);
310
        double sin = Math.sin(radians);
311
        double cos = Math.cos(radians);
312
        return new Vec3(
313
                vector.x * cos - vector.z * sin,
314
                0.0,
315
                vector.x * sin + vector.z * cos
316
        );
317
    }
318
319
    private static AABB union(AABB a, AABB b) {
320
        return new AABB(
321
                Math.min(a.minX, b.minX),
322
                Math.min(a.minY, b.minY),
323
                Math.min(a.minZ, b.minZ),
324
                Math.max(a.maxX, b.maxX),
325
                Math.max(a.maxY, b.maxY),
326
                Math.max(a.maxZ, b.maxZ)
327
        );
328
    }
329
330
    @Override
331
    public void onEnable() {
332
        resetState();
333
    }
334
335
    @Override
336
    public void onDisable() {
337
        RotationManager.INSTANCE.clear(this);
338
        ElytraRecastUtil.INSTANCE.reset(this);
339
        closeAttackWindow();
340
        resetState();
341
    }
342
343
    @Override
344
    public WorldPhase getWorldPhase() {
345
        return WorldPhase.END_MAIN;
346
    }
347
348
    @EventHandler
349
    private void onPostSync(EventPostSync event) {
350
        if (!isEnabled()) return;
351
        if (mc.player == null || mc.level == null) {
352
            resetState();
353
            return;
354
        }
355
356
        LocalPlayer player = mc.player;
357
        if (isAttributeSwapElytraCycleActive()) {
358
            target = null;
359
            TargetManager.setElytraTarget(null);
360
            clearPursuitState();
361
            clearAutoTakeoffState();
362
            queuedFireworkUse = false;
363
            ElytraRecastUtil.INSTANCE.reset(this);
364
            releaseRotationState();
365
            return;
366
        }
367
368
        LivingEntity combatTarget = resolveCombatTarget(player);
369
        boolean validSelf = isValidSelf(player);
370
        boolean validTarget = isValidTarget(combatTarget);
371
372
        target = validSelf && validTarget ? combatTarget : null;
373
        updateTargetFocus(target);
374
        TargetManager.setElytraTarget(target);
375
        boolean emergencyAvoidQueued = queueEmergencyAvoidanceRotation(player);
376
377
        if (!validSelf || !validTarget) {
378
            clearPursuitState();
379
            queuedFireworkUse = false;
380
            if (!emergencyAvoidQueued) {
381
                releaseRotationState();
382
            }
383
        } else {
384
            updatePursuitPhase(player, target);
385
            tickRestartFallFlying(player);
386
        }
387
388
        if (emergencyAvoidQueued) {
389
            clearPursuitState();
390
            queuedFireworkUse = false;
391
        }
392
    }
393
394
    @EventHandler(priority = -10)
395
    private void onGameTick(GameTickEvent event) {
396
        if (!isEnabled()) return;
397
        LocalPlayer player = mc.player;
398
        if (player == null || mc.level == null) {
399
            resetState();
400
            return;
401
        }
402
403
        if (hitStatusTicks < HIT_STATUS_READY_TICKS) {
404
            hitStatusTicks++;
405
        }
406
        ElytraRecastUtil.INSTANCE.tick(this, player);
407
408
        if (isAttributeSwapElytraCycleActive()) {
409
            queuedFireworkUse = false;
410
            clearPursuitState();
411
            clearAutoTakeoffState();
412
            ElytraRecastUtil.INSTANCE.reset(this);
413
            releaseRotationState();
414
            return;
415
        }
416
417
        tickAutoTakeoff(player);
418
419
        boolean emergencyAvoidQueued = queueEmergencyAvoidanceRotation(player);
420
421
        if (!isRunning()) {
422
            queuedFireworkUse = false;
423
            clearPursuitState();
424
            if (!ElytraRecastUtil.INSTANCE.isActive(this)) {
425
                ElytraRecastUtil.INSTANCE.reset(this);
426
            }
427
            if (!emergencyAvoidQueued) {
428
                releaseRotationState();
429
            }
430
            return;
431
        }
432
433
        if (emergencyAvoidQueued) {
434
            queuedFireworkUse = false;
435
            clearPursuitState();
436
            return;
437
        }
438
439
        updatePursuitPhase(player, target);
440
        if (shouldUseFirework(player)) {
441
            queuedFireworkUse = true;
442
        }
443
    }
444
445
    @EventHandler(priority = FIREWORK_SYNC_PRIORITY)
446
    private void onSyncFirework(EventSync event) {
447
        if (!queuedFireworkUse || !isEnabled()) return;
448
        queuedFireworkUse = false;
449
450
        LocalPlayer player = mc.player;
451
        if (player == null || !isRunning()) return;
452
        if (!shouldUseFirework(player)) return;
453
454
        FireworkUseController.INSTANCE.use(
455
                event.getYaw(),
456
                event.getPitch(),
457
                true,
458
                swapBack.get(),
459
                silentSwap.get(),
460
                speedThreshold.get(),
461
                true
462
        );
463
    }
464
465
    @EventHandler(priority = FIREWORK_SYNC_PRIORITY - 20)
466
    private void onMovementInput(MovementInputEvent event) {
467
        if (!isEnabled()) return;
468
        if (handleAutoTakeoffMovementInput(event)) return;
469
        ElytraRecastUtil.INSTANCE.handleMovementInput(this, event);
470
    }
471
472
    @EventHandler(priority = FIREWORK_SYNC_PRIORITY - 20)
473
    private void onSyncRecast(EventSync event) {
474
        if (!isEnabled()) return;
475
        if (handleAutoTakeoffSync(event)) return;
476
        ElytraRecastUtil.INSTANCE.handleSync(this, event);
477
    }
478
479
    @EventHandler(priority = 0)
480
    private void onRotationUpdate(RotationUpdateEvent event) {
481
        if (!isEnabled() || event.getType() != RotationUpdateEvent.Type.PRE) return;
482
        LocalPlayer player = mc.player;
483
        if (player == null || mc.level == null) {
484
            clearPursuitState();
485
            return;
486
        }
487
488
        if (queueEmergencyAvoidanceRotation(player)) {
489
            pursuitRotationActive = false;
490
            return;
491
        }
492
493
        if (!isRunning()) {
494
            pursuitRotationActive = false;
495
            return;
496
        }
497
498
        updatePursuitPhase(player, target);
499
        Rotation pursuitRotation = calculatePursuitRotation(player, target);
500
        if (pursuitRotation == null) {
501
            pursuitRotationActive = false;
502
            return;
503
        }
504
505
        pendingRotation = pursuitRotation;
506
        pursuitRotationActive = true;
507
        RotationTarget plan = new RotationTarget(
508
                pursuitRotation.normalize(),
509
                target,
510
                List.of(),
511
                2,
512
                2.0f,
513
                true,
514
                MovementCorrection.SILENT,
515
                true,
516
                null
517
        );
518
        RotationManager.INSTANCE.setRotationTarget(plan, PURSUIT_ROTATION_PRIORITY, this);
519
    }
520
521
    @EventHandler
522
    private void onPacketReceive(PacketEvent.Receive event) {
523
        if (!isEnabled()) return;
524
        if (!(event.getPacket() instanceof ClientboundEntityEventPacket packet)) return;
525
        LivingEntity currentTarget = target;
526
        if (currentTarget == null || mc.level == null) return;
527
528
        if (packet.getEntity(mc.level) == currentTarget
529
                && (packet.getEventId() == 0 || packet.getEventId() == 3)) {
530
            hitStatusTicks = 0;
531
        }
532
    }
533
534
    public LivingEntity getTarget() {
535
        return target;
536
    }
537
538
    public boolean isRunning() {
539
        return isEnabled()
540
                && mc.player != null
541
                && mc.player.isFallFlying()
542
                && target != null
543
                && hasKillAuraGate()
544
                && !isAttributeSwapElytraCycleActive();
545
    }
546
547
    public boolean canIgnoreKillAuraRotations() {
548
        return isRunning() && (pursuitRotationActive || preparingRotation || attackWindowActive || pendingRotation != null);
549
    }
550
551
    public boolean isManagingFireworks() {
552
        return isRunning();
553
    }
554
555
    private void resetState() {
556
        ElytraRecastUtil.INSTANCE.reset(this);
557
        target = null;
558
        TargetManager.setElytraTarget(null);
559
        preparingRotation = false;
560
        pendingRotation = null;
561
        lastDirection = null;
562
        attackWindowActive = false;
563
        pursuitPhase = PursuitPhase.NONE;
564
        pursuitRotationActive = false;
565
        restartFallFlyingTicks = 0;
566
        hitStatusTicks = HIT_STATUS_READY_TICKS;
567
        queuedFireworkUse = false;
568
        orbitSide = 1;
569
        focusedTargetId = -1;
570
        targetFocusTicks = 0;
571
        autoTakeoffPending = false;
572
        queuedAutoTakeoffJump = false;
573
        queuedAutoTakeoffRelease = false;
574
        queuedAutoTakeoffStartGlide = false;
575
        autoTakeoffGlideDelayTicks = 0;
576
        autoTakeoffCooldownTicks = 0;
577
    }
578
579
    private LivingEntity resolveCombatTarget(LocalPlayer player) {
580
        if (player == null || !hasKillAuraGate() || !hasTargetingPurpose()) {
581
            return null;
582
        }
583
584
        KillAura killAura = Modules.get(KillAura.class);
585
586
        TargetCandidate focused = evaluateFocusedTargetCandidate(player, target);
587
        if (focused != null) {
588
            return focused.entity();
589
        }
590
591
        TargetCandidate recentlyAttacked = evaluateFocusedTargetCandidate(player, resolveRecentAttackTarget());
592
        if (recentlyAttacked != null) {
593
            return recentlyAttacked.entity();
594
        }
595
596
        LivingEntity auraTarget = killAura.getCurrentTarget();
597
        TargetCandidate current = evaluateTargetCandidate(player, auraTarget, true, false);
598
        if (current != null) {
599
            return current.entity();
600
        }
601
602
        LivingEntity best = null;
603
        double bestScore = Double.POSITIVE_INFINITY;
604
        for (LivingEntity candidate : killAura.findElytraTargetCandidates(targetRange.get(), targetFov.get())) {
605
            TargetCandidate evaluated = evaluateTargetCandidate(player, candidate, false, false);
606
            if (evaluated == null) continue;
607
            if (evaluated.score() < bestScore) {
608
                bestScore = evaluated.score();
609
                best = evaluated.entity();
610
            }
611
        }
612
        return best;
613
    }
614
615
    private boolean hasKillAuraGate() {
616
        KillAura killAura = Modules.get(KillAura.class);
617
        return killAura != null && killAura.isEnabled();
618
    }
619
620
    private void updateTargetFocus(LivingEntity currentTarget) {
621
        if (currentTarget != null) {
622
            focusedTargetId = currentTarget.getId();
623
            targetFocusTicks = TARGET_FOCUS_HOLD_TICKS;
624
            return;
625
        }
626
627
        if (targetFocusTicks > 0) {
628
            targetFocusTicks--;
629
            if (targetFocusTicks <= 0) {
630
                focusedTargetId = -1;
631
            }
632
        } else {
633
            focusedTargetId = -1;
634
        }
635
    }
636
637
    private boolean isFocusedCandidate(LivingEntity candidate) {
638
        return candidate != null
639
                && targetFocusTicks > 0
640
                && focusedTargetId >= 0
641
                && candidate.getId() == focusedTargetId;
642
    }
643
644
    private LivingEntity resolveRecentAttackTarget() {
645
        if (TargetManager.getTargetSource() != TargetManager.Source.ATTACK) {
646
            return null;
647
        }
648
        return TargetManager.getTarget();
649
    }
650
651
    private boolean isRecentAttackTarget(LivingEntity candidate) {
652
        LivingEntity attacked = resolveRecentAttackTarget();
653
        return candidate != null && attacked != null && candidate.getId() == attacked.getId();
654
    }
655
656
    private TargetCandidate evaluateFocusedTargetCandidate(LocalPlayer player, LivingEntity candidate) {
657
        if (candidate == null) return null;
658
        if (!isFocusedCandidate(candidate) && !isRecentAttackTarget(candidate)) return null;
659
        return evaluateTargetCandidate(player, candidate, true, true);
660
    }
661
662
    private TargetCandidate evaluateTargetCandidate(LocalPlayer player, LivingEntity candidate, boolean currentAuraTarget, boolean focusBypass) {
663
        if (player == null || !isValidTarget(candidate)) return null;
664
665
        boolean focused = focusBypass && (isFocusedCandidate(candidate) || isRecentAttackTarget(candidate));
666
        Vec3 predictedCenter = predictTargetCenter(candidate, pursuitPredictionTicks.get());
667
        double maxRange = Math.max(1.0, targetRange.get());
668
        if (focused) {
669
            maxRange *= TARGET_FOCUS_RANGE_MULTIPLIER;
670
        }
671
        double distanceSq = player.getEyePosition().distanceToSqr(predictedCenter);
672
        if (distanceSq > maxRange * maxRange) return null;
673
674
        float angle = angleToPredictedPoint(player, predictedCenter);
675
        float maxFov = Mth.clamp(targetFov.get(), 1.0f, 180.0f);
676
        if (!focused && maxFov < 180.0f && angle > maxFov * 0.5f) return null;
677
678
        Reachability reachability = evaluateReachability(player, candidate, predictedCenter);
679
        if (reachability == null) return null;
680
681
        double score = distanceSq
682
                + (focused ? 0.0 : angle * angle * 0.18)
683
                + (reachability.raised() ? 36.0 : 0.0)
684
                + (currentAuraTarget ? -64.0 : 0.0)
685
                + (focused ? -192.0 : 0.0)
686
                + (candidate == target ? -48.0 : 0.0);
687
        return new TargetCandidate(candidate, predictedCenter, reachability.point(), score);
688
    }
689
690
    private float angleToPredictedPoint(LocalPlayer player, Vec3 point) {
691
        Rotation rotation = Rotation.lookingAt(point, player.getEyePosition()).normalize();
692
        return Math.abs(Mth.wrapDegrees(rotation.yaw() - player.getYRot()));
693
    }
694
695
    private Reachability evaluateReachability(LocalPlayer player, LivingEntity candidate, Vec3 predictedCenter) {
696
        if (player == null || candidate == null || mc.level == null) return null;
697
698
        if (isApproachCorridorClear(player, predictedCenter)) {
699
            return new Reachability(predictedCenter, false);
700
        }
701
702
        Vec3 playerPos = player.position();
703
        Vec3 horizontalToTarget = horizontal(predictedCenter.subtract(playerPos));
704
        Vec3 direction = horizontalToTarget.lengthSqr() > 1.0E-5
705
                ? horizontalToTarget.normalize()
706
                : horizontal(player.getViewVector(1.0f)).normalize();
707
        if (direction.lengthSqr() < 1.0E-5) {
708
            direction = new Vec3(0.0, 0.0, 1.0);
709
        }
710
711
        double highPassHeight = usesHighPassSettings()
712
                ? Math.max(2.0, overtakeHeight.get())
713
                : Math.max(3.0, candidate.getBoundingBox().getYsize() + 2.0);
714
        double forward = usesHighPassSettings()
715
                ? Math.max(0.0, overtakeForward.get())
716
                : 3.0;
717
        Vec3 highApproach = predictedCenter
718
                .add(direction.scale(forward))
719
                .add(0.0, highPassHeight, 0.0);
720
721
        if (isApproachCorridorClear(player, highApproach) && isRayClear(player, highApproach, predictedCenter)) {
722
            return new Reachability(highApproach, true);
723
        }
724
725
        return null;
726
    }
727
728
    private boolean isAttributeSwapElytraCycleActive() {
729
        AttributeSwap attributeSwap = Modules.get(AttributeSwap.class);
730
        return attributeSwap != null && attributeSwap.isElytraCycleActive();
731
    }
732
733
    private boolean isValidSelf(LocalPlayer player) {
734
        return player != null
735
                && player.getItemBySlot(EquipmentSlot.CHEST).is(Items.ELYTRA)
736
                && player.isFallFlying();
737
    }
738
739
    private boolean isValidTarget(LivingEntity entity) {
740
        if (!(entity instanceof Player playerTarget)) return false;
741
        if (!entity.isAlive() || entity.isRemoved()) return false;
742
743
        String mode = String.valueOf(targetMode.get());
744
        if ("flying".equals(mode)) {
745
            return playerTarget.isFallFlying();
746
        }
747
        if ("grounded".equals(mode)) {
748
            return !playerTarget.isFallFlying();
749
        }
750
        return true;
751
    }
752
753
    private boolean isPursuitEnabled() {
754
        return !"off".equals(pursuitMode.get());
755
    }
756
757
    private boolean isAutoTakeoffEnabled() {
758
        return autoTakeoff.get();
759
    }
760
761
    private boolean hasTargetingPurpose() {
762
        return isPursuitEnabled() || isAutoTakeoffEnabled();
763
    }
764
765
    private boolean usesHighPassSettings() {
766
        String mode = pursuitMode.get();
767
        return "high_pass".equals(mode) || "auto".equals(mode);
768
    }
769
770
    private void updatePursuitPhase(LocalPlayer player, LivingEntity currentTarget) {
771
        if (!isPursuitEnabled() || player == null || currentTarget == null) {
772
            clearPursuitState();
773
            return;
774
        }
775
776
        boolean wantsHighPass = wantsHighPass(player, currentTarget);
777
        if (!wantsHighPass) {
778
            pursuitPhase = PursuitPhase.CHASE;
779
            preparingRotation = false;
780
            attackWindowActive = false;
781
            return;
782
        }
783
784
        Vec3 targetPoint = predictTargetCenter(currentTarget, pursuitPredictionTicks.get());
785
        Vec3 playerPos = player.position();
786
        double horizontalDistance = horizontalDistance(playerPos, targetPoint);
787
        double heightAboveTarget = playerPos.y - targetPoint.y;
788
        double horizontalSpeed = player.getDeltaMovement().horizontalDistance();
789
        double wantedHeight = Math.max(1.0, overtakeHeight.get());
790
        double diveDistance = Math.max(1.0, diveHorizontalDistance.get());
791
792
        boolean highEnough = heightAboveTarget >= wantedHeight * 0.55;
793
        boolean closeEnough = horizontalDistance <= diveDistance;
794
        boolean fastEnough = horizontalSpeed >= attackSetupSpeed.get() || player.fallDistance >= 1.4f;
795
        boolean descending = player.getDeltaMovement().y <= -0.03 || player.fallDistance >= 1.2f;
796
797
        if (highEnough && closeEnough && (fastEnough || descending)) {
798
            pursuitPhase = PursuitPhase.DIVE;
799
            preparingRotation = false;
800
            attackWindowActive = true;
801
            return;
802
        }
803
804
        if (heightAboveTarget < wantedHeight * 0.35 || player.getDeltaMovement().y < -0.18) {
805
            pursuitPhase = PursuitPhase.CLIMB;
806
        } else {
807
            pursuitPhase = PursuitPhase.OVERPASS;
808
        }
809
        preparingRotation = prepareRotations.get();
810
        attackWindowActive = false;
811
    }
812
813
    private void clearPursuitState() {
814
        preparingRotation = false;
815
        pendingRotation = null;
816
        attackWindowActive = false;
817
        pursuitPhase = PursuitPhase.NONE;
818
        pursuitRotationActive = false;
819
    }
820
821
    private void closeAttackWindow() {
822
        attackWindowActive = false;
823
    }
824
825
    private Rotation calculatePursuitRotation(LocalPlayer player, LivingEntity currentTarget) {
826
        if (!isPursuitEnabled() || player == null || currentTarget == null || pursuitPhase == PursuitPhase.NONE) {
827
            return null;
828
        }
829
830
        Vec3 point = calculatePursuitPoint(player, currentTarget);
831
        if (point == null) return null;
832
833
        point = adjustPursuitPointForCrystalFear(player, point);
834
        if (solidBlockDodge.get()) {
835
            point = adjustPursuitPointForCollision(player, point);
836
        }
837
838
        return Rotation.lookingAt(point, player.getEyePosition()).normalize();
839
    }
840
841
    private Vec3 calculatePursuitPoint(LocalPlayer player, LivingEntity currentTarget) {
842
        Vec3 targetCenter = predictTargetCenter(currentTarget, pursuitPredictionTicks.get());
843
        Vec3 playerPos = player.position();
844
        Vec3 horizontalToTarget = horizontal(targetCenter.subtract(playerPos));
845
        double horizontalDistance = horizontalToTarget.length();
846
        Vec3 direction = horizontalDistance > 1.0E-4
847
                ? horizontalToTarget.scale(1.0 / horizontalDistance)
848
                : horizontal(player.getViewVector(1.0f));
849
        if (direction.lengthSqr() < 1.0E-5) {
850
            direction = new Vec3(0.0, 0.0, 1.0);
851
        } else {
852
            direction = direction.normalize();
853
        }
854
855
        return switch (pursuitPhase) {
856
            case CLIMB -> targetCenter
857
                    .add(direction.scale(Math.max(1.0, overtakeForward.get() * 0.65)))
858
                    .add(0.0, Math.max(2.0, overtakeHeight.get()), 0.0);
859
            case OVERPASS -> targetCenter
860
                    .add(direction.scale(Math.max(0.0, overtakeForward.get())))
861
                    .add(0.0, Math.max(1.5, overtakeHeight.get() * 0.75), 0.0);
862
            case DIVE -> targetCenter.add(0.0, currentTarget.getBoundingBox().getYsize() * -0.15, 0.0);
863
            case CHASE -> calculateDirectChasePoint(player, currentTarget, targetCenter, direction, horizontalDistance);
864
            case NONE -> null;
865
        };
866
    }
867
868
    private Vec3 calculateDirectChasePoint(LocalPlayer player,
869
                                           LivingEntity currentTarget,
870
                                           Vec3 targetCenter,
871
                                           Vec3 direction,
872
                                           double horizontalDistance) {
873
        if (shouldUseNoRotationOrbit(player, currentTarget, horizontalDistance)) {
874
            return calculateNoRotationOrbitPoint(player, currentTarget, targetCenter, direction, horizontalDistance);
875
        }
876
877
        double attackBand = getAuraAttackBand(currentTarget);
878
        double configuredDistance = Math.max(2.0, idealChaseDistance.get());
879
        double idealDistance = Mth.clamp(configuredDistance, attackBand * 0.85, Math.max(attackBand * 1.55, attackBand + 1.0));
880
        double passThrough = horizontalDistance < idealDistance
881
                ? Mth.clamp(idealDistance - horizontalDistance, 0.45, Math.max(1.2, attackBand * 0.7))
882
                : Math.min(Math.max(1.15, attackBand * 0.55), horizontalDistance * 0.16);
883
        double lift = player.getDeltaMovement().y < -0.22 ? 1.5 : 0.0;
884
        return targetCenter.add(direction.scale(passThrough)).add(0.0, lift, 0.0);
885
    }
886
887
    private boolean shouldUseNoRotationOrbit(LocalPlayer player, LivingEntity currentTarget, double horizontalDistance) {
888
        if (!shouldOwnAuraNoRotation()) return false;
889
        if (player == null || currentTarget == null) return false;
890
        if (currentTarget.isFallFlying()) return false;
891
892
        double attackBand = getAuraAttackBand(currentTarget);
893
        boolean targetIsStill = currentTarget.getDeltaMovement().horizontalDistance() <= GROUND_TARGET_STILL_SPEED;
894
        boolean targetIsGrounded = currentTarget.onGround() || currentTarget.fallDistance < 0.15f;
895
        boolean alreadyInCombatBand = horizontalDistance <= attackBand * 2.35;
896
        return (targetIsStill || targetIsGrounded) && alreadyInCombatBand;
897
    }
898
899
    private Vec3 calculateNoRotationOrbitPoint(LocalPlayer player,
900
                                               LivingEntity currentTarget,
901
                                               Vec3 targetCenter,
902
                                               Vec3 direction,
903
                                               double horizontalDistance) {
904
        updateOrbitSide(player, direction);
905
906
        double attackBand = getAuraAttackBand(currentTarget);
907
        double attackRange = getAuraAttackRange(currentTarget);
908
        double maxOrbitRadius = Math.max(ORBIT_MIN_RADIUS, Math.min(ORBIT_MAX_RADIUS, attackRange - ORBIT_ATTACK_RANGE_MARGIN));
909
        double orbitRadius = Mth.clamp(attackBand * 0.38, ORBIT_MIN_RADIUS, maxOrbitRadius);
910
        if (horizontalDistance < attackBand * 0.78) {
911
            orbitRadius = Math.min(maxOrbitRadius, orbitRadius + (attackBand * 0.78 - horizontalDistance) * 0.22);
912
        }
913
        if (horizontalDistance > attackBand * 1.45) {
914
            orbitRadius *= 0.55;
915
        }
916
917
        double forwardLead = Mth.clamp(horizontalDistance - attackBand * 0.72, 0.35, Math.max(1.15, attackBand * 0.78));
918
        if (currentTarget.getDeltaMovement().horizontalDistance() <= GROUND_TARGET_STILL_SPEED) {
919
            forwardLead = Math.min(forwardLead, Math.max(0.75, attackRange * 0.55));
920
        }
921
922
        Vec3 tangent = new Vec3(-direction.z, 0.0, direction.x).normalize().scale(orbitSide * orbitRadius);
923
        double targetHeight = currentTarget.getBoundingBox().getYsize();
924
        double verticalLead = Mth.clamp((targetCenter.y - player.getEyeY()) * 0.35, -0.65, 1.15);
925
        if (player.getDeltaMovement().y < -0.18) {
926
            verticalLead += 0.65;
927
        }
928
929
        return targetCenter
930
                .add(direction.scale(forwardLead))
931
                .add(tangent)
932
                .add(0.0, Math.max(-0.35, targetHeight * 0.18 + verticalLead), 0.0);
933
    }
934
935
    private void updateOrbitSide(LocalPlayer player, Vec3 direction) {
936
        if (player == null || direction == null || direction.lengthSqr() < 1.0E-5) return;
937
938
        Vec3 tangent = new Vec3(-direction.z, 0.0, direction.x).normalize();
939
        Vec3 velocity = horizontal(player.getDeltaMovement());
940
        if (velocity.lengthSqr() > 0.015 * 0.015) {
941
            double dot = velocity.normalize().dot(tangent);
942
            if (Math.abs(dot) > ORBIT_SIDE_SWITCH_DOT) {
943
                orbitSide = dot >= 0.0 ? 1 : -1;
944
                return;
945
            }
946
        }
947
948
        Vec3 look = horizontal(player.getViewVector(1.0f));
949
        if (look.lengthSqr() > 1.0E-5) {
950
            double dot = look.normalize().dot(tangent);
951
            if (Math.abs(dot) > ORBIT_SIDE_SWITCH_DOT * 1.35) {
952
                orbitSide = dot >= 0.0 ? 1 : -1;
953
            }
954
        }
955
    }
956
957
    private boolean shouldOwnAuraNoRotation() {
958
        KillAura killAura = Modules.get(KillAura.class);
959
        return killAura != null && killAura.isNoRotationMode();
960
    }
961
962
    private double getAuraAttackRange(LivingEntity currentTarget) {
963
        KillAura killAura = Modules.get(KillAura.class);
964
        if (killAura == null || currentTarget == null) {
965
            return 3.0;
966
        }
967
        return Mth.clamp(killAura.getEffectiveRange(currentTarget), 1.0, 6.0);
968
    }
969
970
    private double getAuraAttackBand(LivingEntity currentTarget) {
971
        double targetRadius = currentTarget == null
972
                ? 0.3
973
                : Math.max(currentTarget.getBoundingBox().getXsize(), currentTarget.getBoundingBox().getZsize()) * 0.5;
974
        return Math.max(1.4, getAuraAttackRange(currentTarget) + targetRadius - 0.18);
975
    }
976
977
    private Vec3 adjustPursuitPointForCrystalFear(LocalPlayer player, Vec3 point) {
978
        if (player == null || point == null || !crystalFear.get()) return point;
979
        CrystalThreat threat = findCrystalThreat(player, point);
980
        if (threat == null) return point;
981
982
        Vec3 away = horizontal(point.subtract(threat.pos()));
983
        if (away.lengthSqr() < 1.0E-5) {
984
            away = horizontal(player.getEyePosition().subtract(threat.pos()));
985
        }
986
        if (away.lengthSqr() < 1.0E-5) {
987
            away = horizontal(player.getDeltaMovement());
988
        }
989
        if (away.lengthSqr() < 1.0E-5) {
990
            away = horizontal(player.getViewVector(1.0f));
991
        }
992
        if (away.lengthSqr() < 1.0E-5) {
993
            return point.add(0.0, 3.0, 0.0);
994
        }
995
996
        Vec3 safeDirection = away.normalize();
997
        double lift = threat.damage() >= player.getHealth() + player.getAbsorptionAmount() * 0.5f ? 4.0 : 2.25;
998
        return point
999
                .add(safeDirection.scale(Math.max(2.0, CRYSTAL_FEAR_SAFE_DISTANCE - threat.distance())))
1000
                .add(0.0, lift, 0.0);
1001
    }
1002
1003
    private Vec3 adjustPursuitPointForCollision(LocalPlayer player, Vec3 point) {
1004
        if (mc.level == null) return point;
1005
        if (isRayPathClear(player, point)) return point;
1006
1007
        double[] lifts = {2.0, 4.0, 7.0, 10.0};
1008
        for (double lift : lifts) {
1009
            Vec3 lifted = point.add(0.0, lift, 0.0);
1010
            if (isRayPathClear(player, lifted)) {
1011
                return lifted;
1012
            }
1013
        }
1014
1015
        Rotation side = findFreeSideRotation(player);
1016
        Vec3 sideDirection = side.directionVector();
1017
        return player.getEyePosition()
1018
                .add(sideDirection.scale(SIDE_RAYCAST_DISTANCE))
1019
                .add(0.0, Math.max(2.0, overtakeHeight.get() * 0.5), 0.0);
1020
    }
1021
1022
    private boolean isRayPathClear(LocalPlayer player, Vec3 point) {
1023
        return isApproachCorridorClear(player, point);
1024
    }
1025
1026
    private boolean isApproachCorridorClear(LocalPlayer player, Vec3 point) {
1027
        if (player == null || mc.level == null || point == null) return false;
1028
1029
        Vec3 eye = player.getEyePosition();
1030
        if (!isRayClear(player, eye, point)) return false;
1031
1032
        Vec3 direction = horizontal(point.subtract(eye));
1033
        if (direction.lengthSqr() < 1.0E-5) return true;
1034
        direction = direction.normalize();
1035
        Vec3 side = new Vec3(-direction.z, 0.0, direction.x).scale(0.42);
1036
        Vec3 body = player.getBoundingBox().getCenter();
1037
        Vec3 low = new Vec3(body.x, player.getBoundingBox().minY + 0.35, body.z);
1038
        Vec3 high = new Vec3(body.x, player.getBoundingBox().minY + player.getBoundingBox().getYsize() * 0.85, body.z);
1039
1040
        return isRayClear(player, low.add(side), point.add(side))
1041
                && isRayClear(player, low.subtract(side), point.subtract(side))
1042
                && isRayClear(player, high, point.add(0.0, 0.35, 0.0));
1043
    }
1044
1045
    private boolean isRayClear(LocalPlayer player, Vec3 from, Vec3 to) {
1046
        if (player == null || mc.level == null || from == null || to == null) return false;
1047
        HitResult hit = mc.level.clip(new ClipContext(
1048
                from,
1049
                to,
1050
                ClipContext.Block.COLLIDER,
1051
                ClipContext.Fluid.NONE,
1052
                player
1053
        ));
1054
        if (hit.getType() == HitResult.Type.MISS) {
1055
            return true;
1056
        }
1057
        return hit.getLocation().distanceToSqr(from) + COLLISION_CLEARANCE_MARGIN * COLLISION_CLEARANCE_MARGIN
1058
                >= to.distanceToSqr(from);
1059
    }
1060
1061
    private boolean wantsHighPass(LocalPlayer player, LivingEntity currentTarget) {
1062
        String mode = pursuitMode.get();
1063
        if ("high_pass".equals(mode)) return prepareRotations.get();
1064
        if (!"auto".equals(mode) || !prepareRotations.get()) return false;
1065
        if (currentTarget instanceof Player targetPlayer && targetPlayer.isFallFlying()) {
1066
            return false;
1067
        }
1068
        return canSetupMaceDive(player);
1069
    }
1070
1071
    private boolean canSetupMaceDive(LocalPlayer player) {
1072
        AttributeSwap attributeSwap = Modules.get(AttributeSwap.class);
1073
        if (attributeSwap == null || !attributeSwap.isEnabled()) return false;
1074
        if (player == null || player.isUsingItem()) return false;
1075
        for (int i = 0; i < 36; i++) {
1076
            if (player.getInventory().getItem(i).is(Items.MACE)) {
1077
                return true;
1078
            }
1079
        }
1080
        return player.getMainHandItem().is(Items.MACE) || player.getOffhandItem().is(Items.MACE);
1081
    }
1082
1083
    private Vec3 predictTargetCenter(LivingEntity currentTarget, int ticks) {
1084
        int safeTicks = Mth.clamp(ticks, 0, 20);
1085
        Vec3 base = currentTarget.getBoundingBox().getCenter();
1086
        if (safeTicks <= 0) {
1087
            return base;
1088
        }
1089
1090
        if (currentTarget instanceof Player playerTarget) {
1091
            PlayerSimulationCache.SimulatedPlayerCache simulation = PlayerSimulationCache.getSimulationForOtherPlayers(playerTarget);
1092
            PlayerSimulationCache.SimulatedPlayerSnapshot snapshot = simulation.getSnapshotAt(safeTicks);
1093
            Vec3 delta = snapshot.pos().subtract(playerTarget.position());
1094
            return base.add(delta);
1095
        }
1096
1097
        return base.add(currentTarget.getDeltaMovement().scale(safeTicks));
1098
    }
1099
1100
    private void tickAutoTakeoff(LocalPlayer player) {
1101
        if (autoTakeoffCooldownTicks > 0) {
1102
            autoTakeoffCooldownTicks--;
1103
        }
1104
        if (autoTakeoffGlideDelayTicks > 0) {
1105
            autoTakeoffGlideDelayTicks--;
1106
        }
1107
1108
        if (!isAutoTakeoffEnabled()) {
1109
            clearAutoTakeoffState();
1110
            return;
1111
        }
1112
1113
        if (player == null || mc.level == null || isAttributeSwapElytraCycleActive()) {
1114
            clearAutoTakeoffState();
1115
            return;
1116
        }
1117
1118
        if (player.isFallFlying()) {
1119
            if (autoTakeoffPending) {
1120
                autoTakeoffCooldownTicks = AUTO_TAKEOFF_COOLDOWN_TICKS;
1121
            }
1122
            clearAutoTakeoffState();
1123
            return;
1124
        }
1125
1126
        if (!canAutoTakeoffSelf(player) || !hasAutoTakeoffTarget(player)) {
1127
            clearAutoTakeoffState();
1128
            return;
1129
        }
1130
1131
        if (!autoTakeoffPending) {
1132
            if (autoTakeoffCooldownTicks > 0) return;
1133
            autoTakeoffPending = true;
1134
            if (canAutoTakeoffJumpNow(player)) {
1135
                queueAutoTakeoffJump();
1136
                autoTakeoffGlideDelayTicks = player.onGround() ? 1 : 0;
1137
            }
1138
        }
1139
1140
        if (player.onGround() || player.isInWater() || player.isInLava()) {
1141
            queueAutoTakeoffJump();
1142
            queuedAutoTakeoffStartGlide = false;
1143
            queuedAutoTakeoffRelease = false;
1144
            if (autoTakeoffGlideDelayTicks <= 0) {
1145
                autoTakeoffGlideDelayTicks = 1;
1146
            }
1147
            return;
1148
        }
1149
1150
        if (autoTakeoffGlideDelayTicks > 0) return;
1151
        if (player.getDeltaMovement().y > 0.0 && player.fallDistance <= 0.0f) return;
1152
        if (queuedAutoTakeoffStartGlide || queuedAutoTakeoffRelease) return;
1153
1154
        queuedAutoTakeoffRelease = true;
1155
        queuedAutoTakeoffStartGlide = true;
1156
    }
1157
1158
    private boolean canAutoTakeoffSelf(LocalPlayer player) {
1159
        if (player == null) return false;
1160
        if (player.isFallFlying()) return false;
1161
        if (player.isPassenger()) return false;
1162
        if (player.getAbilities().flying) return false;
1163
        if (player.onClimbable()) return false;
1164
        return player.getItemBySlot(EquipmentSlot.CHEST).is(Items.ELYTRA);
1165
    }
1166
1167
    private boolean hasAutoTakeoffTarget(LocalPlayer player) {
1168
        if (player == null || !hasKillAuraGate()) return false;
1169
        LivingEntity candidate = resolveCombatTarget(player);
1170
        return isValidTarget(candidate);
1171
    }
1172
1173
    private boolean canAutoTakeoffJumpNow(LocalPlayer player) {
1174
        return player != null
1175
                && !player.isPassenger()
1176
                && !player.getAbilities().flying
1177
                && (player.onGround() || player.isInWater() || player.isInLava());
1178
    }
1179
1180
    private void queueAutoTakeoffJump() {
1181
        queuedAutoTakeoffJump = true;
1182
    }
1183
1184
    private void clearAutoTakeoffState() {
1185
        autoTakeoffPending = false;
1186
        queuedAutoTakeoffJump = false;
1187
        queuedAutoTakeoffRelease = false;
1188
        queuedAutoTakeoffStartGlide = false;
1189
        autoTakeoffGlideDelayTicks = 0;
1190
    }
1191
1192
    private boolean handleAutoTakeoffMovementInput(MovementInputEvent event) {
1193
        if (queuedAutoTakeoffRelease) {
1194
            event.setJump(false);
1195
            queuedAutoTakeoffRelease = false;
1196
            return true;
1197
        }
1198
1199
        if (queuedAutoTakeoffJump) {
1200
            event.setJump(true);
1201
            queuedAutoTakeoffJump = false;
1202
            return true;
1203
        }
1204
1205
        return false;
1206
    }
1207
1208
    private boolean handleAutoTakeoffSync(EventSync event) {
1209
        if (!queuedAutoTakeoffStartGlide) return false;
1210
1211
        LocalPlayer player = mc.player;
1212
        if (player == null) {
1213
            clearAutoTakeoffState();
1214
            return false;
1215
        }
1216
1217
        if (player.isFallFlying()) {
1218
            clearAutoTakeoffState();
1219
            autoTakeoffCooldownTicks = AUTO_TAKEOFF_COOLDOWN_TICKS;
1220
            return true;
1221
        }
1222
1223
        if (!canAutoTakeoffSelf(player)) {
1224
            clearAutoTakeoffState();
1225
            return false;
1226
        }
1227
1228
        if (!player.onGround()
1229
                && !player.isInWater()
1230
                && !player.isInLava()
1231
                && player.getDeltaMovement().y <= 0.0) {
1232
            queuedAutoTakeoffStartGlide = false;
1233
1234
            if (player.tryToStartFallFlying()) {
1235
                queuedAutoTakeoffJump = true;
1236
            }
1237
1238
            if (player.isFallFlying() && mc.getConnection() != null) {
1239
                mc.getConnection().send(
1240
                        new ServerboundPlayerCommandPacket(player, ServerboundPlayerCommandPacket.Action.START_FALL_FLYING)
1241
                );
1242
                clearAutoTakeoffState();
1243
                autoTakeoffCooldownTicks = AUTO_TAKEOFF_COOLDOWN_TICKS;
1244
            } else {
1245
                autoTakeoffGlideDelayTicks = 1;
1246
            }
1247
            return true;
1248
        }
1249
1250
        if (player.onGround() || player.isInWater() || player.isInLava()) {
1251
            queuedAutoTakeoffStartGlide = false;
1252
            queuedAutoTakeoffRelease = false;
1253
        }
1254
1255
        return false;
1256
    }
1257
1258
    private void releaseRotationState() {
1259
        RotationManager.INSTANCE.release(this, true);
1260
    }
1261
1262
    private void tickRestartFallFlying(LocalPlayer player) {
1263
        if (restartFallFlyingTicks > 0) {
1264
            restartFallFlyingTicks--;
1265
            return;
1266
        }
1267
1268
        if (player == null || player.onGround() || player.isFallFlying()) return;
1269
        if (!player.getItemBySlot(EquipmentSlot.CHEST).is(Items.ELYTRA)) return;
1270
        if (!hasFireworkRocket(player)) return;
1271
        if (ElytraRecastUtil.INSTANCE.isActive(this)) return;
1272
1273
        ElytraRecastUtil.INSTANCE.request(
1274
                this,
1275
                player,
1276
                ElytraRecastUtil.Mode.from(recastMode.get()),
1277
                false,
1278
                false,
1279
                false,
1280
                0
1281
        );
1282
        ElytraRecastUtil.INSTANCE.tick(this, player);
1283
        restartFallFlyingTicks = FALL_FLYING_RESTART_DELAY_TICKS;
1284
    }
1285
1286
    private boolean shouldUseFirework(LocalPlayer player) {
1287
        if (player == null || !player.isFallFlying()) return false;
1288
        if (player.isUsingItem()) return false;
1289
        if (!hasFireworkRocket(player)) return false;
1290
        int threshold = speedThreshold.get();
1291
        if (threshold <= 0) return false;
1292
        if (FireworkUseController.INSTANCE.isCooling(threshold)) return false;
1293
1294
        double currentSpeed = player.getDeltaMovement().horizontalDistance() * FIREWORK_SPEED_FACTOR;
1295
        if (currentSpeed < threshold) return true;
1296
1297
        if (pursuitPhase == PursuitPhase.CLIMB || pursuitPhase == PursuitPhase.OVERPASS) {
1298
            return currentSpeed < threshold * 1.25;
1299
        }
1300
        return false;
1301
    }
1302
1303
    private boolean hasFireworkRocket(LocalPlayer player) {
1304
        if (player == null) return false;
1305
        if (player.getOffhandItem().is(Items.FIREWORK_ROCKET)) return true;
1306
        for (int i = 0; i < 36; i++) {
1307
            if (player.getInventory().getItem(i).is(Items.FIREWORK_ROCKET)) return true;
1308
        }
1309
        return false;
1310
    }
1311
1312
    private Rotation findFreeSideRotation(LocalPlayer player) {
1313
        if (player == null || mc.level == null) {
1314
            return new Rotation(0.0f, -88.0f);
1315
        }
1316
1317
        Vec3 eye = player.getEyePosition();
1318
        for (Direction direction : Direction.values()) {
1319
            if (direction == lastDirection) continue;
1320
1321
            Vec3 offset = Vec3.atLowerCornerOf(direction.getUnitVec3i()).scale(SIDE_RAYCAST_DISTANCE);
1322
            Vec3 lowEnd = eye.add(offset);
1323
            Vec3 highStart = eye.add(0.0, player.getBoundingBox().getYsize(), 0.0);
1324
            Vec3 highEnd = highStart.add(offset);
1325
1326
            HitResult lowRay = mc.level.clip(new ClipContext(
1327
                    eye,
1328
                    lowEnd,
1329
                    ClipContext.Block.COLLIDER,
1330
                    ClipContext.Fluid.NONE,
1331
                    player
1332
            ));
1333
            HitResult highRay = mc.level.clip(new ClipContext(
1334
                    highStart,
1335
                    highEnd,
1336
                    ClipContext.Block.COLLIDER,
1337
                    ClipContext.Fluid.NONE,
1338
                    player
1339
            ));
1340
1341
            if (lowRay.getType() == HitResult.Type.MISS && highRay.getType() == HitResult.Type.MISS) {
1342
                lastDirection = direction;
1343
                return Rotation.lookingAt(lowEnd, eye).normalize();
1344
            }
1345
        }
1346
1347
        Rotation server = RotationManager.INSTANCE.getServerRotation();
1348
        float yaw = server != null ? server.yaw() : player.getYRot();
1349
        return new Rotation(yaw, -88.0f).normalize();
1350
    }
1351
1352
    private boolean queueEmergencyAvoidanceRotation(LocalPlayer player) {
1353
        if (queueBlockDodgeRotation(player)) {
1354
            return true;
1355
        }
1356
        return queueCrystalFearRotation(player);
1357
    }
1358
1359
    private boolean queueCrystalFearRotation(LocalPlayer player) {
1360
        if (!crystalFear.get()) return false;
1361
        if (!isValidCrystalFearSelf(player)) return false;
1362
1363
        CrystalThreat threat = findCrystalThreat(player, null);
1364
        if (threat == null) return false;
1365
1366
        Rotation crystalFearRotation = findCrystalFearRotation(player, threat);
1367
        if (crystalFearRotation == null) return false;
1368
1369
        RotationTarget plan = new RotationTarget(
1370
                crystalFearRotation.normalize(),
1371
                null,
1372
                List.of(),
1373
                2,
1374
                2.0f,
1375
                true,
1376
                MovementCorrection.SILENT,
1377
                false,
1378
                null
1379
        );
1380
        RotationManager.INSTANCE.setRotationTarget(plan, CRYSTAL_FEAR_ROTATION_PRIORITY, this);
1381
        return true;
1382
    }
1383
1384
    private boolean isValidCrystalFearSelf(LocalPlayer player) {
1385
        return player != null
1386
                && mc.level != null
1387
                && player.isFallFlying()
1388
                && !player.isPassenger()
1389
                && player.getItemBySlot(EquipmentSlot.CHEST).is(Items.ELYTRA);
1390
    }
1391
1392
    private CrystalThreat findCrystalThreat(LocalPlayer player, Vec3 plannedPoint) {
1393
        if (player == null || mc.level == null) return null;
1394
1395
        double range = Math.max(1.0, crystalFearRange.get());
1396
        double rangeSq = range * range;
1397
        Vec3 eye = player.getEyePosition();
1398
        Vec3 predictedSelf = predictSelfCrystalPosition(player);
1399
        Vec3 planned = plannedPoint != null ? plannedPoint : predictedSelf;
1400
        CrystalThreat best = null;
1401
        double bestScore = Double.NEGATIVE_INFINITY;
1402
1403
        for (var entity : mc.level.entitiesForRendering()) {
1404
            if (!(entity instanceof EndCrystal crystal)) continue;
1405
            if (!crystal.isAlive() || crystal.isRemoved()) continue;
1406
1407
            Vec3 crystalPos = crystal.position();
1408
            double distanceSq = crystalPos.distanceToSqr(eye);
1409
            double plannedDistanceSq = crystalPos.distanceToSqr(planned);
1410
            if (distanceSq > rangeSq && plannedDistanceSq > rangeSq) continue;
1411
1412
            float damage = ExplosionDamageUtil.getCrystalDamage(
1413
                    player,
1414
                    crystalPos,
1415
                    Mth.clamp(crystalFearPredictionTicks.get(), 0, 12),
1416
                    true
1417
            );
1418
            if (!isDangerousCrystalDamage(player, damage)) continue;
1419
1420
            double distance = Math.sqrt(Math.min(distanceSq, plannedDistanceSq));
1421
            double score = damage * 100.0 + Math.max(0.0, range - distance) * 5.0;
1422
            if (plannedDistanceSq < distanceSq) {
1423
                score += 24.0;
1424
            }
1425
            if (score > bestScore) {
1426
                bestScore = score;
1427
                best = new CrystalThreat(crystal, crystalPos, damage, distance);
1428
            }
1429
        }
1430
1431
        return best;
1432
    }
1433
1434
    private Vec3 predictSelfCrystalPosition(LocalPlayer player) {
1435
        Vec3 predicted = player.getEyePosition();
1436
        Vec3 velocity = player.getDeltaMovement();
1437
        int ticks = Mth.clamp(crystalFearPredictionTicks.get(), 0, 12);
1438
        for (int i = 0; i < ticks; i++) {
1439
            predicted = predicted.add(velocity);
1440
            velocity = approximateNextElytraVelocity(velocity);
1441
        }
1442
        return predicted;
1443
    }
1444
1445
    private boolean isDangerousCrystalDamage(LocalPlayer player, float damage) {
1446
        if (damage < crystalFearMinDamage.get()) return false;
1447
1448
        float health = player.getHealth() + player.getAbsorptionAmount();
1449
        double healthThreat = Math.max(crystalFearMinDamage.get(), health * 0.30);
1450
        return damage >= healthThreat || health - damage <= crystalFearHealthBuffer.get();
1451
    }
1452
1453
    private Rotation findCrystalFearRotation(LocalPlayer player, CrystalThreat threat) {
1454
        Vec3 velocity = player.getDeltaMovement();
1455
        Vec3 away = horizontal(player.getEyePosition().subtract(threat.pos()));
1456
        if (away.lengthSqr() < 1.0E-5) {
1457
            away = horizontal(velocity);
1458
        }
1459
        if (away.lengthSqr() < 1.0E-5) {
1460
            away = horizontal(player.getViewVector(1.0f));
1461
        }
1462
        if (away.lengthSqr() < 1.0E-5) {
1463
            return findFreeSideRotation(player);
1464
        }
1465
1466
        Vec3 baseDirection = away.normalize();
1467
        double horizontalSpeed = Math.max(0.24, horizontal(velocity).length());
1468
        Vec3 bestDirection = null;
1469
        double bestScore = Double.NEGATIVE_INFINITY;
1470
        double[] candidateAngles = {0.0, -35.0, 35.0, -70.0, 70.0, -115.0, 115.0, 180.0};
1471
1472
        for (double angle : candidateAngles) {
1473
            Vec3 candidateDirection = rotateHorizontal(baseDirection, angle).normalize();
1474
            Vec3 candidateVelocity = new Vec3(
1475
                    candidateDirection.x * horizontalSpeed,
1476
                    Math.max(velocity.y, 0.02),
1477
                    candidateDirection.z * horizontalSpeed
1478
            );
1479
            double score = scoreCrystalFearDirection(player, threat, candidateVelocity, angle);
1480
            if (score > bestScore) {
1481
                bestScore = score;
1482
                bestDirection = candidateDirection;
1483
            }
1484
        }
1485
1486
        if (bestDirection == null) {
1487
            return findFreeSideRotation(player);
1488
        }
1489
1490
        Vec3 eye = player.getEyePosition();
1491
        double lift = threat.damage() >= player.getHealth() + player.getAbsorptionAmount() * 0.5f ? 4.5 : 2.8;
1492
        Rotation rotation = Rotation.lookingAt(
1493
                eye.add(bestDirection.scale(20.0)).add(0.0, lift, 0.0),
1494
                eye
1495
        ).normalize();
1496
        float pitch = Mth.clamp(rotation.pitch(), -48.0f, -4.0f);
1497
        return new Rotation(rotation.yaw(), pitch).normalize();
1498
    }
1499
1500
    private double scoreCrystalFearDirection(LocalPlayer player, CrystalThreat threat, Vec3 initialVelocity, double angle) {
1501
        AABB baseBox = player.getBoundingBox();
1502
        Vec3 offset = Vec3.ZERO;
1503
        Vec3 velocity = initialVelocity;
1504
        double minDistanceSq = Double.POSITIVE_INFINITY;
1505
        int ticks = Math.max(3, Mth.clamp(crystalFearPredictionTicks.get() + 3, 3, 14));
1506
1507
        for (int tick = 1; tick <= ticks; tick++) {
1508
            Vec3 previousOffset = offset;
1509
            offset = offset.add(velocity);
1510
            Vec3 center = baseBox.move(offset).getCenter();
1511
            minDistanceSq = Math.min(minDistanceSq, center.distanceToSqr(threat.pos()));
1512
1513
            AABB previousBox = baseBox.move(previousOffset);
1514
            AABB nextBox = baseBox.move(offset);
1515
            AABB swept = union(previousBox, nextBox).inflate(CRYSTAL_FEAR_SWEEP_MARGIN);
1516
            if (solidBlockDodge.get() && hasSolidCollision(player, swept)) {
1517
                return -10_000.0 - Math.abs(angle);
1518
            }
1519
1520
            velocity = approximateNextElytraVelocity(velocity);
1521
        }
1522
1523
        double minDistance = Math.sqrt(minDistanceSq);
1524
        double safeBonus = minDistance >= CRYSTAL_FEAR_SAFE_DISTANCE ? 120.0 : minDistance * 12.0;
1525
        return safeBonus - Math.abs(angle) * 0.35;
1526
    }
1527
1528
    private boolean queueBlockDodgeRotation(LocalPlayer player) {
1529
        if (!solidBlockDodge.get()) return false;
1530
        if (!isValidBlockDodgeSelf(player)) return false;
1531
1532
        Vec3 velocity = player.getDeltaMovement();
1533
        if (velocity.horizontalDistance() < 0.18) return false;
1534
1535
        PredictedBlockImpact impact = predictBlockImpact(player, velocity, blockDodgePredictionTicks.get());
1536
        if (impact == null) return false;
1537
1538
        double damage = estimateBlockImpactDamage(player, impact.velocity());
1539
        if (!isDangerousBlockImpact(player, damage)) return false;
1540
1541
        Rotation dodgeRotation = findBlockDodgeRotation(player, impact);
1542
        if (dodgeRotation == null) return false;
1543
1544
        RotationTarget plan = new RotationTarget(
1545
                dodgeRotation.normalize(),
1546
                null,
1547
                List.of(),
1548
                2,
1549
                2.0f,
1550
                true,
1551
                MovementCorrection.SILENT,
1552
                false,
1553
                null
1554
        );
1555
        RotationManager.INSTANCE.setRotationTarget(plan, BLOCK_DODGE_ROTATION_PRIORITY, this);
1556
        return true;
1557
    }
1558
1559
    private boolean isValidBlockDodgeSelf(LocalPlayer player) {
1560
        return player != null
1561
                && mc.level != null
1562
                && player.isFallFlying()
1563
                && !player.onGround()
1564
                && !player.isPassenger()
1565
                && player.getItemBySlot(EquipmentSlot.CHEST).is(Items.ELYTRA);
1566
    }
1567
1568
    private PredictedBlockImpact predictBlockImpact(LocalPlayer player, Vec3 initialVelocity, int ticks) {
1569
        if (player == null || mc.level == null) return null;
1570
1571
        AABB baseBox = player.getBoundingBox();
1572
        Vec3 offset = Vec3.ZERO;
1573
        Vec3 velocity = initialVelocity;
1574
        int safeTicks = Math.max(1, ticks);
1575
1576
        for (int tick = 1; tick <= safeTicks; tick++) {
1577
            Vec3 previousOffset = offset;
1578
            offset = offset.add(velocity);
1579
1580
            AABB previousBox = baseBox.move(previousOffset);
1581
            AABB nextBox = baseBox.move(offset);
1582
            AABB swept = union(previousBox, nextBox).inflate(BLOCK_DODGE_SWEEP_MARGIN);
1583
            if (hasSolidCollision(player, swept)) {
1584
                return new PredictedBlockImpact(tick, velocity);
1585
            }
1586
1587
            velocity = approximateNextElytraVelocity(velocity);
1588
        }
1589
1590
        return null;
1591
    }
1592
1593
    private Vec3 approximateNextElytraVelocity(Vec3 velocity) {
1594
        return new Vec3(
1595
                velocity.x * 0.99,
1596
                velocity.y * 0.98,
1597
                velocity.z * 0.99
1598
        );
1599
    }
1600
1601
    private boolean hasSolidCollision(LocalPlayer player, AABB box) {
1602
        for (var shape : mc.level.getBlockCollisions(player, box)) {
1603
            if (!shape.isEmpty()) {
1604
                return true;
1605
            }
1606
        }
1607
        return false;
1608
    }
1609
1610
    private Rotation findBlockDodgeRotation(LocalPlayer player, PredictedBlockImpact impact) {
1611
        Vec3 velocity = player.getDeltaMovement();
1612
        Vec3 horizontal = new Vec3(velocity.x, 0.0, velocity.z);
1613
        if (horizontal.lengthSqr() < 1.0E-5) {
1614
            Rotation movement = RotationManager.INSTANCE.getMovementRotation();
1615
            Vec3 direction = movement != null ? movement.directionVector() : player.getViewVector(1.0f);
1616
            horizontal = new Vec3(direction.x, 0.0, direction.z);
1617
        }
1618
        if (horizontal.lengthSqr() < 1.0E-5) {
1619
            return findFreeSideRotation(player);
1620
        }
1621
1622
        Vec3 baseDirection = horizontal.normalize();
1623
        double horizontalSpeed = Math.max(0.18, horizontal.length());
1624
        Vec3 bestDirection = null;
1625
        double bestScore = Double.NEGATIVE_INFINITY;
1626
1627
        for (double angle : BLOCK_DODGE_CANDIDATE_ANGLES) {
1628
            Vec3 candidateDirection = rotateHorizontal(baseDirection, angle).normalize();
1629
            Vec3 candidateVelocity = new Vec3(
1630
                    candidateDirection.x * horizontalSpeed,
1631
                    velocity.y,
1632
                    candidateDirection.z * horizontalSpeed
1633
            );
1634
            PredictedBlockImpact candidateImpact = predictBlockImpact(player, candidateVelocity, blockDodgePredictionTicks.get());
1635
            double score = candidateImpact == null
1636
                    ? 10_000.0 - Math.abs(angle)
1637
                    : candidateImpact.ticks() * 100.0 - Math.abs(angle);
1638
            if (score > bestScore) {
1639
                bestScore = score;
1640
                bestDirection = candidateDirection;
1641
            }
1642
        }
1643
1644
        if (bestDirection == null) {
1645
            return findFreeSideRotation(player);
1646
        }
1647
1648
        Vec3 eye = player.getEyePosition();
1649
        double lift = impact.ticks() <= 3 || velocity.y < -0.04 ? 4.0 : 2.0;
1650
        Rotation rotation = Rotation.lookingAt(
1651
                eye.add(bestDirection.scale(20.0)).add(0.0, lift, 0.0),
1652
                eye
1653
        ).normalize();
1654
        float maxPitch = impact.ticks() <= 3 || velocity.y < -0.04 ? -28.0f : -10.0f;
1655
        float pitch = Mth.clamp(Math.min(rotation.pitch(), maxPitch), -55.0f, 5.0f);
1656
        return new Rotation(rotation.yaw(), pitch).normalize();
1657
    }
1658
1659
    private double estimateBlockImpactDamage(LocalPlayer player, Vec3 impactVelocity) {
1660
        double raw = Math.max(0.0, impactVelocity.horizontalDistance() * 10.0 - 3.0);
1661
        if (raw <= 0.0) return 0.0;
1662
1663
        int featherLevel = getFeatherFallingLevel(player);
1664
        double reduction = Math.min(20.0, featherLevel * 3.0) / 25.0;
1665
        return raw * (1.0 - reduction);
1666
    }
1667
1668
    private boolean isDangerousBlockImpact(LocalPlayer player, double damage) {
1669
        if (damage < blockDodgeMinDamage.get()) return false;
1670
1671
        float health = player.getHealth() + player.getAbsorptionAmount();
1672
        double healthThreat = Math.max(blockDodgeMinDamage.get(), health * 0.32);
1673
        return damage >= healthThreat || health - damage <= blockDodgeHealthBuffer.get();
1674
    }
1675
1676
    private int getFeatherFallingLevel(LocalPlayer player) {
1677
        if (player == null || mc.level == null) return 0;
1678
        ItemStack boots = player.getItemBySlot(EquipmentSlot.FEET);
1679
        Holder<Enchantment> feather = getFeatherFallingEnchant();
1680
        return feather == null || boots == null || boots.isEmpty()
1681
                ? 0
1682
                : EnchantmentHelper.getItemEnchantmentLevel(feather, boots);
1683
    }
1684
1685
    private Holder<Enchantment> getFeatherFallingEnchant() {
1686
        if (mc.level == null) return null;
1687
        var registry = mc.level.registryAccess().lookupOrThrow(Registries.ENCHANTMENT);
1688
        Enchantment enchantment = registry.getValue(Enchantments.FEATHER_FALLING);
1689
        return enchantment != null ? registry.wrapAsHolder(enchantment) : null;
1690
    }
1691
1692
    private enum PursuitPhase {
1693
        NONE,
1694
        CHASE,
1695
        CLIMB,
1696
        OVERPASS,
1697
        DIVE
1698
    }
1699
1700
    private record TargetCandidate(LivingEntity entity, Vec3 predictedCenter, Vec3 approachPoint, double score) {
1701
    }
1702
1703
    private record Reachability(Vec3 point, boolean raised) {
1704
    }
1705
1706
    private record CrystalThreat(EndCrystal crystal, Vec3 pos, float damage, double distance) {
1707
    }
1708
1709
    private record PredictedBlockImpact(int ticks, Vec3 velocity) {
1710
    }
1711
}
1712
LiquidBounce (Kotlin)COMBATsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/elytratarget/ModuleElytraTarget.ktKotlin · 90 lines · 2.9 KB

Following the target on elytra.

SettingsSafeAlwaysGlide
ModuleElytraTarget.ktKotlin · Minecraft 26.2 · 90 lines · 2.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
20
package net.ccbluex.liquidbounce.features.module.modules.combat.elytratarget
21
22
import net.ccbluex.liquidbounce.event.tickHandler
23
import net.ccbluex.liquidbounce.features.module.ClientModule
24
import net.ccbluex.liquidbounce.features.module.ModuleCategories
25
import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura
26
import net.ccbluex.liquidbounce.utils.combat.TargetTracker
27
import net.ccbluex.liquidbounce.utils.render.TargetRenderer
28
import net.minecraft.world.entity.LivingEntity
29
30
/**
31
 * Following the target on elytra.
32
 * Works with [ModuleKillAura] together
33
 *
34
 * https://youtu.be/1wa8uKH_apY
35
 *
36
 * @author sqlerrorthing
37
 */
38
@Suppress("MagicNumber")
39
object ModuleElytraTarget : ClientModule("ElytraTarget", ModuleCategories.COMBAT) {
40
    private val targetTracker = tree(TargetTracker())
41
42
    init {
43
        tree(ElytraRotationProcessor)
44
        tree(AutoFirework)
45
    }
46
47
    private val targetRenderer = tree(TargetRenderer(this, targetTracker))
48
    private val safe by boolean("Safe", true)
49
    private val alwaysGlide by boolean("AlwaysGlide", false)
50
51
    @JvmStatic
52
    @get:JvmName("canAlwaysGlide")
53
    val canAlwaysGlide get() =
54
        alwaysGlide
55
        && target != null
56
        && super.running
57
        && !player.abilities.flying
58
59
    val canIgnoreKillAuraRotations get() =
60
        running
61
        && ElytraRotationProcessor.ignoreKillAura
62
63
    fun isSameTargetRendering(target: LivingEntity) =
64
        running
65
        && targetRenderer.enabled
66
        && targetTracker.target
67
            ?.takeIf { it == target } != null
68
69
    override val running: Boolean
70
        get() = super.running && player.isFallFlying
71
72
    internal val target get() = targetTracker.target
73
74
    @Suppress("unused")
75
    private val targetUpdateHandler = tickHandler {
76
        targetTracker.reset()
77
        targetTracker.selectFirst { potentialTarget ->
78
            player.hasLineOfSight(potentialTarget)
79
        }
80
81
        if (safe && !world.noCollision(player.boundingBox.move(player.deltaMovement))) {
82
            player.push(0.0, 0.1, 0.0)
83
        }
84
    }
85
86
    override fun onDisabled() {
87
        targetTracker.reset()
88
    }
89
}
90