WindJump module

WindJump: Minecraft 26.3 cheat module, full source for every implementation (1 client: Combatant).

1 implementationMOVEMENT

Clients with this module

Full module source: 1 implementation

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

CombatantMOVEMENTsrc/main/java/combatant/client/features/module/modules/movement/WindJump.javaJava · 676 lines · 26.4 KB
SettingswindThrowMode
WindJump.javaJava · Minecraft 26.2 · 676 lines · 26.4 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.movement;
9
10
import lombok.Getter;
11
import lombok.RequiredArgsConstructor;
12
import net.minecraft.client.Minecraft;
13
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
14
import net.minecraft.client.player.LocalPlayer;
15
import net.minecraft.util.Mth;
16
import net.minecraft.world.InteractionHand;
17
import net.minecraft.world.InteractionResult;
18
import net.minecraft.world.item.ItemStack;
19
import net.minecraft.world.item.Items;
20
import net.minecraft.world.level.ClipContext;
21
import net.minecraft.world.phys.HitResult;
22
import net.minecraft.world.phys.Vec3;
23
import combatant.client.config.values.EnumValue;
24
import combatant.client.events.EventHandler;
25
import combatant.client.events.impl.EventSync;
26
import combatant.client.events.impl.MovementInputEvent;
27
import combatant.client.events.impl.PlayerJumpEvent;
28
import combatant.client.features.module.Module;
29
import combatant.client.features.module.ModuleCategory;
30
import combatant.client.features.module.ModuleInfo;
31
import combatant.client.features.module.Modules;
32
import combatant.client.features.module.modules.combat.TPSSync;
33
import combatant.client.mixins.accessors.PlayerInventoryAccessor;
34
import combatant.client.util.aiming.data.Rotation;
35
import combatant.client.util.player.MovementUtil;
36
import combatant.client.util.player.inventory.InventorySwap;
37
import combatant.client.util.player.simulation.PlayerSimulationCache;
38
39
//todo Description
40
@ModuleInfo(
41
        id = "windjump",
42
        displayName = "WindJump",
43
        category = ModuleCategory.MOVEMENT
44
)
45
public class WindJump extends Module {
46
47
    private static final String SETTING_ITEM_USAGE_MODE = "item_usage_mode";
48
    private static final String ACTION_WINDJUMP = "windjump";
49
    private static final String ACTION_WINDTHROW = "windthrow";
50
51
    private static final float MIN_DOWN_PITCH = 60f;
52
    private static final double MAX_BLOCK_DISTANCE = 1.5;
53
    private static final double MIN_BLOCK_DISTANCE = 0.3;
54
    private static final double FALL_TRIGGER_DISTANCE = 1.0;
55
    private static final double FALL_TRIGGER_VERTICAL_SPEED = -0.05; // must be falling
56
    private static final double WINDTHROW_TRIGGER_VERTICAL_SPEED = -0.12;
57
    private static final double MAX_FALL_RAYCAST = 6.0; // extend ray when falling fast
58
    private static final double WIND_CHARGE_SPEED = 1.5;
59
    private static final double IMPACT_POINT_Y_OFFSET = 0.25;
60
    private static final double MAX_THROW_PREDICTION_TICKS = 3.0;
61
    private static final int USE_EXPIRE_TICKS = 2;
62
    private static final int WIND_CHARGE_COOLDOWN_TICKS = 10;
63
    private static final int HOTBAR_RESET_TICKS = 0;
64
    private static final double MOTION_YAW_EPSILON = 0.08;
65
    private static final int PREDICTION_TICKS = 7;
66
    private static final double HORIZONTAL_LEAD_FACTOR = 0.32;
67
    private static final double VERTICAL_LEAD_FACTOR = 0.85;
68
    private static final double JUMP_VERTICAL_BONUS = 0.16;
69
    private static final double MAX_HORIZONTAL_LEAD = 0.65;
70
    private static final double IMPACT_BACKTRACK_FACTOR = 0.55;
71
    private static final double MAX_IMPACT_BACKTRACK = 0.55;
72
    private static final double JUMP_START_HORIZONTAL_LEAD_FACTOR = 0.08;
73
    private static final double JUMP_START_VERTICAL_LEAD_FACTOR = 0.18;
74
    private static final double JUMP_START_MAX_HORIZONTAL_LEAD = 0.12;
75
    private static final double JUMP_START_IMPACT_BACKTRACK_FACTOR = 0.85;
76
    private static final double JUMP_START_MAX_IMPACT_BACKTRACK = 0.80;
77
    private static final double JUMP_THROW_INPUT_DELAY_TICKS = 0.08;
78
    private static final double JUMP_START_MIN_LEAD_TICKS = 0.08;
79
    private static final double JUMP_START_MAX_LEAD_TICKS = 0.28;
80
81
    private static final float THROW_PITCH = 90.0f; // straight down
82
    private final EnumValue<WindThrowMode> windThrowMode =
83
            enumSetting("windThrowMode", SETTING_ITEM_USAGE_MODE, WindThrowMode.UNLOCKED, WindThrowMode.UNLOCKED, WindThrowMode.LEGIT);
84
    private PendingUse pendingUse = null;
85
    private int nextAllowedUseTick = 0;
86
    private int lastJumpAge = Integer.MIN_VALUE;
87
88
    {
89
        addAction(ACTION_WINDJUMP, "LEFT_ALT");
90
        addAction(ACTION_WINDTHROW, "LEFT_ALT+X");
91
    }
92
93
    @Override
94
    public void onDisable() {
95
        pendingUse = null;
96
        nextAllowedUseTick = 0;
97
        lastJumpAge = Integer.MIN_VALUE;
98
    }
99
100
    @Override
101
    public void onTick() {
102
        if (!isEnabled()) return;
103
104
        Minecraft mc = Minecraft.getInstance();
105
        if (mc.player == null || mc.gameMode == null) return;
106
107
        LocalPlayer player = mc.player;
108
        boolean windthrowHeld = isActionHeld(ACTION_WINDTHROW);
109
110
        if (processHeldWindJump(player)) {
111
            return;
112
        }
113
114
        // WindThrow on press
115
        if (isActionPressedOnce(ACTION_WINDTHROW)) {
116
            performWindThrow(player, false, 0.0);
117
        }
118
119
        // Auto-trigger windthrow when key held and ground is approaching
120
        if (windthrowHeld) {
121
            double vy = player.getDeltaMovement().y;
122
            if (vy <= WINDTHROW_TRIGGER_VERTICAL_SPEED && !player.onGround()) {
123
                double rayDist = fallRayDistance(vy);
124
                double dist = distanceToGround(player, rayDist);
125
126
                boolean withinImmediate = dist >= MIN_BLOCK_DISTANCE && dist <= FALL_TRIGGER_DISTANCE;
127
                boolean willReachNextTick = dist > FALL_TRIGGER_DISTANCE
128
                        && dist <= rayDist
129
                        && (dist + vy) <= FALL_TRIGGER_DISTANCE;
130
131
                if (withinImmediate || willReachNextTick) {
132
                    if (!queueBestWindChargeUse(player, false, false, false)) {
133
                        performWindThrow(player, true, rayDist);
134
                    }
135
                }
136
            }
137
        }
138
    }
139
140
    @Override
141
    public void onFrame(float tickDelta) {
142
        if (!isEnabled()) return;
143
144
        Minecraft mc = Minecraft.getInstance();
145
        if (mc.player == null || mc.gameMode == null) return;
146
147
        LocalPlayer player = mc.player;
148
        if (!player.isFallFlying() || !isActionHeld(ACTION_WINDJUMP)) return;
149
150
        if (getWindChargeHand(player) == null) return;
151
152
        double previewTicks = Math.max(0.0, tickDelta);
153
        Vec3 predictedPos = predictSelfPosition(player, previewTicks, true, false);
154
155
        HitResult hit = player.level().clip(new ClipContext(
156
                predictedPos.add(0.0, 0.2, 0.0),
157
                predictedPos.add(0.0, -MAX_BLOCK_DISTANCE, 0.0),
158
                ClipContext.Block.COLLIDER,
159
                ClipContext.Fluid.NONE,
160
                player
161
        ));
162
163
        if (hit == null || hit.getType() != HitResult.Type.BLOCK) return;
164
165
        double distance = predictedPos.y - hit.getLocation().y();
166
        if (distance < MIN_BLOCK_DISTANCE || distance > MAX_BLOCK_DISTANCE) return;
167
168
        queueBestWindChargeUse(player, false, true, false);
169
    }
170
171
    private boolean performWindThrow(LocalPlayer player, boolean allowNearGround, double nearGroundRange) {
172
        if (player == null) return false;
173
        if (player.inventoryMenu == null) return false;
174
        if (!hasWindCharge(player)) return false;
175
176
        double vy = player.getDeltaMovement().y;
177
        double range = allowNearGround ? Math.max(FALL_TRIGGER_DISTANCE, Math.min(MAX_FALL_RAYCAST, Math.max(FALL_TRIGGER_DISTANCE, nearGroundRange))) : 0.0;
178
        boolean nearGround = allowNearGround && vy <= WINDTHROW_TRIGGER_VERTICAL_SPEED && isNearGround(player, range);
179
        boolean onGround = player.onGround();
180
        boolean groundOk = onGround || nearGround;
181
        if (!groundOk) return false; // only from ground / near-ground
182
183
        return queueBestWindChargeUse(player, onGround, false, false);
184
    }
185
186
    private boolean processHeldWindJump(LocalPlayer player) {
187
        if (player == null || !isActionHeld(ACTION_WINDJUMP)) {
188
            return false;
189
        }
190
191
        if (player.isFallFlying()
192
                || player.isSwimming()
193
                || player.isInWater()
194
                || player.isInLava()) {
195
            return false;
196
        }
197
198
        if (!findCollision(player)) {
199
            return false;
200
        }
201
202
        return queueHeldWindJumpUse(player);
203
    }
204
205
    private boolean canJumpNow(LocalPlayer player) {
206
        return player != null
207
                && !player.isPassenger()
208
                && !player.getAbilities().flying
209
                && (player.onGround() || player.isInWater() || player.isInLava());
210
    }
211
212
    @EventHandler(priority = -1000)
213
    private void onMovementInput(MovementInputEvent event) {
214
        if (!isEnabled() || !isActionHeld(ACTION_WINDJUMP)) return;
215
216
        LocalPlayer player = Minecraft.getInstance().player;
217
        if (canStartHeldWindJump(player)) {
218
            event.setJump(true);
219
        }
220
    }
221
222
    @EventHandler(priority = -1000)
223
    private void onPlayerJump(PlayerJumpEvent event) {
224
        if (!isEnabled()) return;
225
        LocalPlayer player = Minecraft.getInstance().player;
226
        if (player == null) return;
227
        lastJumpAge = player.tickCount;
228
    }
229
230
    @EventHandler(priority = -1000)
231
    private void onSync(EventSync event) {
232
        if (!isEnabled()) return;
233
234
        LocalPlayer player = Minecraft.getInstance().player;
235
        MultiPlayerGameMode manager = Minecraft.getInstance().gameMode;
236
        if (player == null || manager == null || pendingUse == null) return;
237
238
        PendingUse use = pendingUse;
239
        if (player.tickCount > use.expireAge()) {
240
            pendingUse = null;
241
            return;
242
        }
243
        if (player.tickCount < nextAllowedUseTick) {
244
            pendingUse = null;
245
            return;
246
        }
247
        if (player.getCooldowns().isOnCooldown(Items.WIND_CHARGE.getDefaultInstance())) {
248
            pendingUse = null;
249
            return;
250
        }
251
252
        pendingUse = null;
253
254
        event.setRotation(use.yaw(), use.pitch(), true);
255
        executePendingUse(use);
256
    }
257
258
    private void executePendingUse(PendingUse use) {
259
        LocalPlayer player = Minecraft.getInstance().player;
260
        MultiPlayerGameMode manager = Minecraft.getInstance().gameMode;
261
        if (player == null || manager == null || use == null) return;
262
263
        float yaw = use.yaw();
264
        float pitch = use.pitch();
265
        int syncId = player.inventoryMenu != null ? player.inventoryMenu.containerId : -1;
266
        boolean swapped = use.sourceScreenSlot() >= 0 && use.targetScreenSlot() >= 0 && syncId >= 0;
267
268
        float prevYaw = player.getYRot();
269
        float prevPitch = player.getXRot();
270
        try {
271
            if (use.hotbarSlot() >= 0) {
272
                InventorySwap.INSTANCE.leaseHotbar(this, use.hotbarSlot(), HOTBAR_RESET_TICKS);
273
            }
274
            if (swapped) {
275
                InventorySwap.INSTANCE.swapScreenSlots(use.sourceScreenSlot(), use.targetScreenSlot());
276
            }
277
            player.setYRot(yaw);
278
            player.setXRot(pitch);
279
            InteractionResult result = manager.useItem(player, use.hand());
280
            if (!result.consumesAction()) return;
281
            player.swing(use.hand());
282
            nextAllowedUseTick = player.tickCount + WIND_CHARGE_COOLDOWN_TICKS;
283
        } finally {
284
            player.setYRot(prevYaw);
285
            player.setXRot(prevPitch);
286
            if (swapped) {
287
                InventorySwap.INSTANCE.swapScreenSlots(use.sourceScreenSlot(), use.targetScreenSlot());
288
            }
289
        }
290
    }
291
292
    private int findWindChargeSlot(LocalPlayer player, int originalSlot) {
293
        // prefer hotbar (excluding current slot), then rest of inventory
294
        for (int i = 0; i < 9; i++) {
295
            if (i == originalSlot) continue;
296
            if (player.getInventory().getItem(i).is(Items.WIND_CHARGE)) return i;
297
        }
298
        for (int i = 9; i < 36; i++) {
299
            if (player.getInventory().getItem(i).is(Items.WIND_CHARGE)) return i;
300
        }
301
        return -1;
302
    }
303
304
    private InteractionHand getWindChargeHand(LocalPlayer player) {
305
        ItemStack main = player.getMainHandItem();
306
        ItemStack off = player.getOffhandItem();
307
        if (isWindCharge(main)) return InteractionHand.MAIN_HAND;
308
        if (isWindCharge(off)) return InteractionHand.OFF_HAND;
309
        return null;
310
    }
311
312
    private boolean isWindCharge(ItemStack stack) {
313
        return stack != null && stack.getItem() == Items.WIND_CHARGE;
314
    }
315
316
    private boolean hasWindCharge(LocalPlayer player) {
317
        if (isWindCharge(player.getMainHandItem()) || isWindCharge(player.getOffhandItem())) {
318
            return true;
319
        }
320
        return findWindChargeSlot(player, ((PlayerInventoryAccessor) player.getInventory()).combatant$getSelectedSlot()) != -1;
321
    }
322
323
    private int findWindChargeHotbarSlot(LocalPlayer player) {
324
        if (player == null) return -1;
325
        for (int i = 0; i < 9; i++) {
326
            if (player.getInventory().getItem(i).is(Items.WIND_CHARGE)) {
327
                return i;
328
            }
329
        }
330
        return -1;
331
    }
332
333
    private boolean queueHeldWindJumpUse(LocalPlayer player) {
334
        if (player == null || pendingUse != null || player.tickCount < nextAllowedUseTick) {
335
            return false;
336
        }
337
338
        UseSource source = resolveHeldWindJumpSource(player);
339
        if (source == null) {
340
            return false;
341
        }
342
343
        Rotation rotation = buildJumpStartRotation(player);
344
        pendingUse = new PendingUse(
345
                source.hand(),
346
                rotation.yaw(),
347
                rotation.pitch(),
348
                source.sourceScreenSlot(),
349
                source.targetScreenSlot(),
350
                source.hotbarSlot(),
351
                player.tickCount + USE_EXPIRE_TICKS
352
        );
353
        return true;
354
    }
355
356
    private boolean canStartHeldWindJump(LocalPlayer player) {
357
        if (!canJumpNow(player)) {
358
            return false;
359
        }
360
        if (player == null || player.inventoryMenu == null) {
361
            return false;
362
        }
363
        if (player.getCooldowns().isOnCooldown(Items.WIND_CHARGE.getDefaultInstance())) {
364
            return false;
365
        }
366
        return resolveHeldWindJumpSource(player) != null;
367
    }
368
369
    private UseSource resolveHeldWindJumpSource(LocalPlayer player) {
370
        if (player == null) return null;
371
        if (isWindCharge(player.getOffhandItem())) {
372
            return new UseSource(InteractionHand.OFF_HAND, -1, -1, -1);
373
        }
374
        if (isWindCharge(player.getMainHandItem())) {
375
            return new UseSource(InteractionHand.MAIN_HAND, -1, -1, -1);
376
        }
377
378
        int hotbarSlot = findWindChargeHotbarSlot(player);
379
        if (hotbarSlot == -1) {
380
            return null;
381
        }
382
383
        return new UseSource(InteractionHand.MAIN_HAND, -1, -1, hotbarSlot);
384
    }
385
386
    private boolean queueBestWindChargeUse(LocalPlayer player,
387
                                           boolean allowInventorySwap,
388
                                           boolean preferJumpPrediction,
389
                                           boolean jumpStartThrow) {
390
        if (player == null) return false;
391
        if (pendingUse != null) return false;
392
        if (player.tickCount < nextAllowedUseTick) return false;
393
394
        UseSource source = resolveUseSource(player, allowInventorySwap);
395
        if (source == null) return false;
396
397
        Rotation rotation = computeThrowRotation(player, preferJumpPrediction, jumpStartThrow);
398
        if (rotation == null) return false;
399
400
        int expireAge = player.tickCount + USE_EXPIRE_TICKS;
401
        pendingUse = new PendingUse(
402
                source.hand(),
403
                rotation.yaw(),
404
                rotation.pitch(),
405
                source.sourceScreenSlot(),
406
                source.targetScreenSlot(),
407
                source.hotbarSlot(),
408
                expireAge
409
        );
410
        return true;
411
    }
412
413
    private UseSource resolveUseSource(LocalPlayer player, boolean allowInventorySwap) {
414
        if (player == null) return null;
415
        if (isWindCharge(player.getMainHandItem())) {
416
            return new UseSource(InteractionHand.MAIN_HAND, -1, -1, -1);
417
        }
418
        if (isWindCharge(player.getOffhandItem())) {
419
            return new UseSource(InteractionHand.OFF_HAND, -1, -1, -1);
420
        }
421
        if (!allowInventorySwap) {
422
            return null;
423
        }
424
425
        int selectedSlot = ((PlayerInventoryAccessor) player.getInventory()).combatant$getSelectedSlot();
426
        int windSlot = findWindChargeSlot(player, selectedSlot);
427
        if (windSlot == -1) {
428
            return null;
429
        }
430
431
        return new UseSource(
432
                InteractionHand.MAIN_HAND,
433
                InventorySwap.mapInventoryToScreenSlot(windSlot),
434
                InventorySwap.mapHotbarToScreenSlot(selectedSlot),
435
                -1
436
        );
437
    }
438
439
    private Rotation computeThrowRotation(LocalPlayer player,
440
                                          boolean preferJumpPrediction,
441
                                          boolean jumpStartThrow) {
442
        if (player == null) return null;
443
        if (jumpStartThrow) {
444
            return buildJumpStartRotation(player);
445
        }
446
447
        Vec3 eyePos = player.getEyePosition();
448
        double leadTicks = Mth.clamp(
449
                initialLeadTicks(player, preferJumpPrediction, jumpStartThrow),
450
                jumpStartThrow ? 0.02 : 0.15,
451
                MAX_THROW_PREDICTION_TICKS
452
        );
453
        Vec3 impactPoint = null;
454
455
        for (int i = 0; i < 3; i++) {
456
            Vec3 predictedSelf = predictSelfPosition(player, leadTicks, preferJumpPrediction, jumpStartThrow);
457
            impactPoint = findGroundImpactPoint(player, predictedSelf, jumpStartThrow);
458
            if (impactPoint == null) {
459
                break;
460
            }
461
462
            double flightTicks = Mth.clamp(
463
                    eyePos.distanceTo(impactPoint) / effectiveWindChargeSpeed(),
464
                    jumpStartThrow ? 0.02 : 0.15,
465
                    MAX_THROW_PREDICTION_TICKS
466
            );
467
            if (Math.abs(flightTicks - leadTicks) < 0.1) {
468
                break;
469
            }
470
            leadTicks = flightTicks;
471
        }
472
473
        if (impactPoint == null) {
474
            return fallbackRotation(player);
475
        }
476
477
        Vec3 diff = impactPoint.subtract(eyePos);
478
        double horizontalSq = diff.x * diff.x + diff.z * diff.z;
479
        if (horizontalSq < 0.0025) {
480
            return fallbackRotation(player);
481
        }
482
483
        Rotation rotation = Rotation.lookingAt(impactPoint, eyePos);
484
        float yaw = horizontalSq < 0.01 ? resolveMotionYaw(player, rotation.yaw()) : rotation.yaw();
485
        float pitch = Mth.clamp(Math.max(rotation.pitch(), MIN_DOWN_PITCH), MIN_DOWN_PITCH, THROW_PITCH);
486
        return new Rotation(yaw, pitch, false).normalize();
487
    }
488
489
    private Rotation buildJumpStartRotation(LocalPlayer player) {
490
        float directionYaw = MovementUtil.getMovementDirectionYaw(player, player.getYRot()) - 180.0f;
491
        return new Rotation(directionYaw, 80.0f, false).normalize();
492
    }
493
494
    private Vec3 predictSelfPosition(LocalPlayer player,
495
                                     double leadTicks,
496
                                     boolean preferJumpPrediction,
497
                                     boolean jumpStartThrow) {
498
        double totalTicks = leadTicks;
499
        if (jumpStartThrow) {
500
            totalTicks += JUMP_THROW_INPUT_DELAY_TICKS;
501
        } else if (preferJumpPrediction && isRecentJump(player)) {
502
            totalTicks += 0.18;
503
        }
504
        totalTicks = Mth.clamp(totalTicks, 0.0, MAX_THROW_PREDICTION_TICKS);
505
506
        Vec3 position = player.position();
507
        Vec3 velocity = resolvePredictionVelocity(player, jumpStartThrow);
508
        Vec3 horizontalVelocity = new Vec3(velocity.x, 0.0, velocity.z);
509
510
        double horizontalTicks = totalTicks * (jumpStartThrow ? JUMP_START_HORIZONTAL_LEAD_FACTOR : HORIZONTAL_LEAD_FACTOR);
511
        Vec3 horizontalLead = horizontalVelocity.scale(horizontalTicks);
512
        double horizontalLength = horizontalLead.horizontalDistance();
513
        double maxHorizontalLead = jumpStartThrow ? JUMP_START_MAX_HORIZONTAL_LEAD : MAX_HORIZONTAL_LEAD;
514
        if (horizontalLength > maxHorizontalLead && horizontalLength > 1.0E-6) {
515
            horizontalLead = horizontalLead.scale(maxHorizontalLead / horizontalLength);
516
        }
517
518
        double verticalLead = velocity.y * totalTicks * (jumpStartThrow ? JUMP_START_VERTICAL_LEAD_FACTOR : VERTICAL_LEAD_FACTOR);
519
        if (preferJumpPrediction && isRecentJump(player) && velocity.y > 0.0) {
520
            double bonusScale = jumpStartThrow ? 0.12 : 0.35;
521
            double bonusCap = jumpStartThrow ? JUMP_VERTICAL_BONUS * 0.4 : JUMP_VERTICAL_BONUS;
522
            verticalLead += Math.min(bonusCap, velocity.y * bonusScale);
523
        }
524
525
        return position.add(horizontalLead.x, verticalLead, horizontalLead.z);
526
    }
527
528
    private Vec3 findGroundImpactPoint(LocalPlayer player, Vec3 predictedSelf, boolean jumpStartThrow) {
529
        if (player == null || predictedSelf == null || player.level() == null) return null;
530
531
        double verticalRoom = Math.max(0.0, predictedSelf.y - player.getY());
532
        double rayDistance = Mth.clamp(
533
                2.2 + verticalRoom + Math.max(0.0, player.getDeltaMovement().y) * 5.0,
534
                MAX_BLOCK_DISTANCE,
535
                MAX_FALL_RAYCAST
536
        );
537
        Vec3 start = new Vec3(predictedSelf.x, predictedSelf.y + 0.25, predictedSelf.z);
538
        Vec3 end = start.add(0.0, -rayDistance, 0.0);
539
        HitResult hit = player.level().clip(new ClipContext(
540
                start,
541
                end,
542
                ClipContext.Block.COLLIDER,
543
                ClipContext.Fluid.NONE,
544
                player
545
        ));
546
        if (hit != null && hit.getType() == HitResult.Type.BLOCK) {
547
            Vec3 impact = hit.getLocation().add(0.0, IMPACT_POINT_Y_OFFSET, 0.0);
548
            Vec3 horizontalVelocity = new Vec3(player.getDeltaMovement().x, 0.0, player.getDeltaMovement().z);
549
            double speed = horizontalVelocity.horizontalDistance();
550
            if (speed > 1.0E-6) {
551
                double factor = jumpStartThrow ? JUMP_START_IMPACT_BACKTRACK_FACTOR : IMPACT_BACKTRACK_FACTOR;
552
                double maxBacktrack = jumpStartThrow ? JUMP_START_MAX_IMPACT_BACKTRACK : MAX_IMPACT_BACKTRACK;
553
                double backtrack = Math.min(maxBacktrack, speed * factor);
554
                impact = impact.subtract(horizontalVelocity.normalize().scale(backtrack));
555
            }
556
            return impact;
557
        }
558
        return null;
559
    }
560
561
    private Rotation fallbackRotation(LocalPlayer player) {
562
        return new Rotation(resolveMotionYaw(player, player.getYRot()), THROW_PITCH, false).normalize();
563
    }
564
565
    private double initialLeadTicks(LocalPlayer player, boolean preferJumpPrediction, boolean jumpStartThrow) {
566
        Vec3 velocity = resolvePredictionVelocity(player, jumpStartThrow);
567
        if (jumpStartThrow) {
568
            double lead = JUMP_THROW_INPUT_DELAY_TICKS
569
                    + Math.min(0.03, velocity.horizontalDistance() * 0.04)
570
                    + Math.min(0.04, Math.max(0.0, velocity.y) * 0.08);
571
            if (preferJumpPrediction && isRecentJump(player)) {
572
                lead += 0.01;
573
            }
574
            return Mth.clamp(lead, JUMP_START_MIN_LEAD_TICKS, JUMP_START_MAX_LEAD_TICKS);
575
        }
576
577
        double lead = 0.35
578
                + Math.min(0.85, velocity.horizontalDistance() * 1.15)
579
                + Math.min(0.65, Math.max(0.0, velocity.y) * 1.35);
580
        if (preferJumpPrediction && isRecentJump(player)) {
581
            lead += 0.45;
582
        }
583
        return Math.min(MAX_THROW_PREDICTION_TICKS, lead);
584
    }
585
586
    private boolean isRecentJump(LocalPlayer player) {
587
        if (player == null || lastJumpAge == Integer.MIN_VALUE) return false;
588
        return player.tickCount - lastJumpAge <= 2;
589
    }
590
591
    private boolean findCollision(LocalPlayer player) {
592
        if (player == null || player.isFallFlying() || player.isSwimming() || player.isInWater() || player.isInLava()) {
593
            return false;
594
        }
595
596
        PlayerSimulationCache.SimulatedPlayerCache simulation = PlayerSimulationCache.getSimulationForLocalPlayer();
597
        if (simulation == null) {
598
            return false;
599
        }
600
601
        return simulation.getSnapshotAt(PREDICTION_TICKS).onGround();
602
    }
603
604
    private Vec3 resolvePredictionVelocity(LocalPlayer player, boolean jumpStartThrow) {
605
        Vec3 velocity = player.getDeltaMovement();
606
        return velocity;
607
    }
608
609
    private float resolveMotionYaw(LocalPlayer player, float fallbackYaw) {
610
        if (player == null) return fallbackYaw;
611
612
        Vec3 velocity = player.getDeltaMovement();
613
        if (velocity.horizontalDistanceSqr() > MOTION_YAW_EPSILON * MOTION_YAW_EPSILON) {
614
            return Mth.wrapDegrees((float) Math.toDegrees(Math.atan2(velocity.z, velocity.x)) - 90.0f);
615
        }
616
617
        return Mth.wrapDegrees(MovementUtil.getMovementDirectionYaw(player, fallbackYaw));
618
    }
619
620
    private boolean isNearGround(LocalPlayer player, double maxDist) {
621
        if (player == null || player.level() == null) return false;
622
        double dist = distanceToGround(player, maxDist);
623
        return dist >= 0 && dist <= maxDist;
624
    }
625
626
    private double distanceToGround(LocalPlayer player, double maxDist) {
627
        if (player == null || player.level() == null) return Double.POSITIVE_INFINITY;
628
        Vec3 start = player.position();
629
        Vec3 end = start.add(0, -maxDist, 0);
630
        HitResult hit = player.level().clip(new ClipContext(
631
                start,
632
                end,
633
                ClipContext.Block.COLLIDER,
634
                ClipContext.Fluid.NONE,
635
                player
636
        ));
637
        if (hit != null && hit.getType() == HitResult.Type.BLOCK) {
638
            return start.y - hit.getLocation().y();
639
        }
640
        return Double.POSITIVE_INFINITY;
641
    }
642
643
    private double fallRayDistance(double vy) {
644
        return Math.max(FALL_TRIGGER_DISTANCE, Math.min(MAX_FALL_RAYCAST, Math.abs(vy) * 2.0));
645
    }
646
647
    private double serverTickDelta() {
648
        double delta = 1.0;
649
        TPSSync tpsSync = Modules.get(TPSSync.class);
650
        if (tpsSync != null && tpsSync.isEnabled()) {
651
            delta = tpsSync.getServerTickDelta();
652
        }
653
        return Math.max(0.05, delta);
654
    }
655
656
    private double effectiveWindChargeSpeed() {
657
        return WIND_CHARGE_SPEED * serverTickDelta();
658
    }
659
660
    @Getter
661
    @RequiredArgsConstructor
662
    private enum WindThrowMode implements EnumValue.IdProvider {
663
        UNLOCKED("UNLOCKED"),
664
        LEGIT("LEGIT");
665
666
        private final String id;
667
    }
668
669
    private record UseSource(InteractionHand hand, int sourceScreenSlot, int targetScreenSlot, int hotbarSlot) {
670
    }
671
672
    private record PendingUse(InteractionHand hand, float yaw, float pitch, int sourceScreenSlot, int targetScreenSlot,
673
                              int hotbarSlot, int expireAge) {
674
    }
675
}
676