ProjectilePuncher module

ProjectilePuncher: Minecraft 26.3 cheat module, full source for every implementation (2 clients: Combatant, LiquidBounce (Kotlin)).

2 implementationsCOMBATWORLD

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/ProjectilePuncher.javaJava · 717 lines · 26.1 KB
SettingsprojectilePuncherRangeprojectilePuncherWallRangeprojectilePuncherProjectilesprojectilePuncherIgnoreOpenInventoryprojectilePuncherRaycastprojectilePuncherRotationTimingprojectilePuncherMovementCorrectionprojectilePuncherRotationModeprojectilePuncherRotationResetTicksprojectilePuncherRotationResetThresholdprojectilePuncherRotationThroughWallsprojectilePuncherPredictTicksprojectilePuncherCpsMinprojectilePuncherCpsMaxprojectilePuncherLinearHorizontalMinprojectilePuncherLinearHorizontalMaxprojectilePuncherLinearVerticalMinprojectilePuncherLinearVerticalMaxprojectilePuncherSigmoidHorizontalMinprojectilePuncherSigmoidHorizontalMaxprojectilePuncherSigmoidVerticalMinprojectilePuncherSigmoidVerticalMaxprojectilePuncherSigmoidSteepnessprojectilePuncherSigmoidMidpointprojectilePuncherSmartYawMinprojectilePuncherSmartYawMaxprojectilePuncherSmartPitchMinprojectilePuncherSmartPitchMaxprojectilePuncherSmartSnapThresholdprojectilePuncherSmartJitterYawprojectilePuncherSmartJitterPitchprojectilePuncherSmartDecelerateEnabledprojectilePuncherSmartDecelerateAngleprojectilePuncherSmartDecelerateMinFactor
ProjectilePuncher.javaJava · Minecraft 26.2 · 717 lines · 26.1 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.util.aiming.features.processors.RotationProcessor;
11
import net.minecraft.client.Minecraft;
12
import net.minecraft.util.Mth;
13
import net.minecraft.world.InteractionHand;
14
import net.minecraft.world.entity.Entity;
15
import net.minecraft.world.entity.EntityType;
16
import net.minecraft.world.phys.AABB;
17
import net.minecraft.world.phys.Vec3;
18
import combatant.client.config.common.CommonSettingSchemas;
19
import combatant.client.config.values.BooleanMapValue;
20
import combatant.client.config.values.BooleanValue;
21
import combatant.client.config.values.EnumValue;
22
import combatant.client.config.values.NumberValue;
23
import combatant.client.events.EventHandler;
24
import combatant.client.events.impl.RotationUpdateEvent;
25
import combatant.client.features.module.Module;
26
import combatant.client.features.module.ModuleCategory;
27
import combatant.client.features.module.ModuleInfo;
28
import combatant.client.util.aiming.RotationManager;
29
import combatant.client.util.aiming.RotationTarget;
30
import combatant.client.util.aiming.data.Rotation;
31
import combatant.client.util.aiming.data.RotationWithVector;
32
import combatant.client.util.aiming.features.MovementCorrection;
33
import combatant.client.util.aiming.features.processors.anglesmooth.AngleSmooth;
34
import combatant.client.util.aiming.features.processors.anglesmooth.impl.LinearAngleSmooth;
35
import combatant.client.util.aiming.features.processors.anglesmooth.impl.SigmoidAngleSmooth;
36
import combatant.client.util.aiming.features.processors.anglesmooth.impl.SmartAngleSmooth;
37
import combatant.client.util.aiming.features.processors.anglesmooth.impl.SpookyAngleSmooth;
38
import combatant.client.util.aiming.preference.LeastDifferencePreference;
39
import combatant.client.util.aiming.preference.RotationPreference;
40
import combatant.client.util.aiming.raytrace.RotationRaytrace;
41
import combatant.client.util.click.ClickScheduler;
42
import combatant.client.util.raycast.RaycastUtil;
43
import combatant.client.util.target.TargetingUtil;
44
45
import java.util.ArrayList;
46
import java.util.Comparator;
47
import java.util.List;
48
import java.util.Map;
49
50
//todo Description
51
@ModuleInfo(
52
        id = "projectilepuncher",
53
        displayName = "ProjectilePuncher",
54
        category = ModuleCategory.COMBAT
55
)
56
public final class ProjectilePuncher extends Module {
57
58
    private static final String PROJECTILE_FIREBALL = "fireball";
59
    private static final String PROJECTILE_SHULKER_BULLET = "shulker_bullet";
60
    private static final int ROTATION_PRIORITY = 10;
61
    private final Minecraft mc = Minecraft.getInstance();
62
    private final NumberValue<Double> range =
63
            numCommon(
64
                    "projectilePuncherRange",
65
                    "range",
66
                    CommonSettingSchemas.COMBAT_RANGE,
67
                    3.0,
68
                    2.0,
69
                    6.0
70
            );
71
    private final NumberValue<Double> wallRange =
72
            numCommon(
73
                    "projectilePuncherWallRange",
74
                    "wall_range",
75
                    CommonSettingSchemas.COMBAT_WALL_RANGE,
76
                    0.0,
77
                    0.0,
78
                    6.0
79
            );
80
    private final BooleanMapValue projectiles =
81
            common(
82
                    group(
83
                            "projectilePuncherProjectiles",
84
                            "projectiles",
85
                            projectileDefaults()
86
                    ),
87
                    CommonSettingSchemas.ITEMS_PROJECTILES.commonI18nKey()
88
            );
89
    private final BooleanValue ignoreOpenInventory =
90
            boolCommon(
91
                    "projectilePuncherIgnoreOpenInventory",
92
                    "ignore_open_inventory",
93
                    CommonSettingSchemas.INTERACTION_IGNORE_OPEN_INVENTORY,
94
                    true
95
            );
96
    private final EnumValue<KillAura.RaycastMode> raycast =
97
            enumCommon(
98
                    "projectilePuncherRaycast",
99
                    "raycast",
100
                    CommonSettingSchemas.COMBAT_RAYCAST,
101
                    KillAura.RaycastMode.STRICT,
102
                    KillAura.RaycastMode.values()
103
            );
104
    private final EnumValue<KillAura.RotationTiming> rotationTiming =
105
            enumCommon(
106
                    "projectilePuncherRotationTiming",
107
                    "rotation_timing",
108
                    CommonSettingSchemas.ROTATION_TIMING,
109
                    KillAura.RotationTiming.NORMAL,
110
                    KillAura.RotationTiming.values()
111
            );
112
    private final EnumValue<MovementCorrection> movementCorrection =
113
            enumCommon(
114
                    "projectilePuncherMovementCorrection",
115
                    "movement_correction",
116
                    CommonSettingSchemas.ROTATION_MOVEMENT_CORRECTION,
117
                    MovementCorrection.STRICT,
118
                    MovementCorrection.values()
119
            );
120
    private final EnumValue<KillAura.AngleSmoothMode> rotationMode =
121
            enumCommon(
122
                    "projectilePuncherRotationMode",
123
                    "rotation_mode",
124
                    CommonSettingSchemas.ROTATION_MODE,
125
                    KillAura.AngleSmoothMode.SMART,
126
                    KillAura.AngleSmoothMode.values()
127
            );
128
    private final NumberValue<Integer> rotationResetTicks =
129
            numCommon(
130
                    "projectilePuncherRotationResetTicks",
131
                    "rotation_reset_ticks",
132
                    CommonSettingSchemas.ROTATION_RESET_TICKS,
133
                    2,
134
                    1,
135
                    20
136
            );
137
    private final NumberValue<Float> rotationResetThreshold =
138
            numCommon(
139
                    "projectilePuncherRotationResetThreshold",
140
                    "rotation_reset_threshold",
141
                    CommonSettingSchemas.ROTATION_RESET_THRESHOLD,
142
                    2.0f,
143
                    0.1f,
144
                    15.0f
145
            );
146
    private final BooleanValue rotationThroughWalls =
147
            boolCommon(
148
                    "projectilePuncherRotationThroughWalls",
149
                    "rotation_through_walls",
150
                    CommonSettingSchemas.ROTATION_THROUGH_WALLS,
151
                    false
152
            );
153
    private final NumberValue<Integer> predictTicks =
154
            num(
155
                    "projectilePuncherPredictTicks",
156
                    "predict_ticks",
157
                    1,
158
                    0,
159
                    5
160
            );
161
    private final NumberValue<Integer> cpsMin =
162
            numCommon(
163
                    "projectilePuncherCpsMin",
164
                    "cps_min",
165
                    CommonSettingSchemas.COMBAT_CPS_MIN,
166
                    20,
167
                    1,
168
                    20
169
            );
170
    private final NumberValue<Integer> cpsMax =
171
            numCommon(
172
                    "projectilePuncherCpsMax",
173
                    "cps_max",
174
                    CommonSettingSchemas.COMBAT_CPS_MAX,
175
                    20,
176
                    1,
177
                    20
178
            );
179
    private final ClickScheduler clicker = new ClickScheduler(cpsMin.get(), cpsMax.get());
180
    private final NumberValue<Float> linearHorMin =
181
            numCommon(
182
                    "projectilePuncherLinearHorizontalMin",
183
                    "linear_horizontal_min",
184
                    CommonSettingSchemas.ANGLESMOOTH_HORIZONTAL_MIN,
185
                    180f,
186
                    0f,
187
                    180f
188
            );
189
    private final NumberValue<Float> linearHorMax =
190
            numCommon(
191
                    "projectilePuncherLinearHorizontalMax",
192
                    "linear_horizontal_max",
193
                    CommonSettingSchemas.ANGLESMOOTH_HORIZONTAL_MAX,
194
                    180f,
195
                    0f,
196
                    180f
197
            );
198
    private final NumberValue<Float> linearVertMin =
199
            numCommon(
200
                    "projectilePuncherLinearVerticalMin",
201
                    "linear_vertical_min",
202
                    CommonSettingSchemas.ANGLESMOOTH_VERTICAL_MIN,
203
                    180f,
204
                    0f,
205
                    180f
206
            );
207
    private final NumberValue<Float> linearVertMax =
208
            numCommon(
209
                    "projectilePuncherLinearVerticalMax",
210
                    "linear_vertical_max",
211
                    CommonSettingSchemas.ANGLESMOOTH_VERTICAL_MAX,
212
                    180f,
213
                    0f,
214
                    180f
215
            );
216
    private final NumberValue<Float> sigmoidHorMin =
217
            numCommon(
218
                    "projectilePuncherSigmoidHorizontalMin",
219
                    "sigmoid_horizontal_min",
220
                    CommonSettingSchemas.ANGLESMOOTH_HORIZONTAL_MIN,
221
                    180f,
222
                    0f,
223
                    180f
224
            );
225
    private final NumberValue<Float> sigmoidHorMax =
226
            numCommon(
227
                    "projectilePuncherSigmoidHorizontalMax",
228
                    "sigmoid_horizontal_max",
229
                    CommonSettingSchemas.ANGLESMOOTH_HORIZONTAL_MAX,
230
                    180f,
231
                    0f,
232
                    180f
233
            );
234
    private final NumberValue<Float> sigmoidVertMin =
235
            numCommon(
236
                    "projectilePuncherSigmoidVerticalMin",
237
                    "sigmoid_vertical_min",
238
                    CommonSettingSchemas.ANGLESMOOTH_VERTICAL_MIN,
239
                    180f,
240
                    0f,
241
                    180f
242
            );
243
    private final NumberValue<Float> sigmoidVertMax =
244
            numCommon(
245
                    "projectilePuncherSigmoidVerticalMax",
246
                    "sigmoid_vertical_max",
247
                    CommonSettingSchemas.ANGLESMOOTH_VERTICAL_MAX,
248
                    180f,
249
                    0f,
250
                    180f
251
            );
252
    private final NumberValue<Float> sigmoidSteepness =
253
            numCommon(
254
                    "projectilePuncherSigmoidSteepness",
255
                    "sigmoid_steepness",
256
                    CommonSettingSchemas.ANGLESMOOTH_STEEPNESS,
257
                    10f,
258
                    0f,
259
                    20f
260
            );
261
    private final NumberValue<Float> sigmoidMidpoint =
262
            numCommon(
263
                    "projectilePuncherSigmoidMidpoint",
264
                    "sigmoid_midpoint",
265
                    CommonSettingSchemas.ANGLESMOOTH_MIDPOINT,
266
                    0.3f,
267
                    0f,
268
                    1f
269
            );
270
    private final NumberValue<Float> smartYawMin =
271
            numCommon(
272
                    "projectilePuncherSmartYawMin",
273
                    "smart_yaw_min",
274
                    CommonSettingSchemas.ANGLESMOOTH_YAW_MIN,
275
                    70f,
276
                    1f,
277
                    180f
278
            );
279
    private final NumberValue<Float> smartYawMax =
280
            numCommon(
281
                    "projectilePuncherSmartYawMax",
282
                    "smart_yaw_max",
283
                    CommonSettingSchemas.ANGLESMOOTH_YAW_MAX,
284
                    95f,
285
                    1f,
286
                    180f
287
            );
288
    private final NumberValue<Float> smartPitchMin =
289
            numCommon(
290
                    "projectilePuncherSmartPitchMin",
291
                    "smart_pitch_min",
292
                    CommonSettingSchemas.ANGLESMOOTH_PITCH_MIN,
293
                    45f,
294
                    1f,
295
                    180f
296
            );
297
    private final NumberValue<Float> smartPitchMax =
298
            numCommon(
299
                    "projectilePuncherSmartPitchMax",
300
                    "smart_pitch_max",
301
                    CommonSettingSchemas.ANGLESMOOTH_PITCH_MAX,
302
                    70f,
303
                    1f,
304
                    180f
305
            );
306
    private final NumberValue<Float> smartSnapThreshold =
307
            numCommon(
308
                    "projectilePuncherSmartSnapThreshold",
309
                    "smart_snap_threshold",
310
                    CommonSettingSchemas.ANGLESMOOTH_SNAP_THRESHOLD,
311
                    1.2f,
312
                    0.05f,
313
                    10.0f
314
            );
315
    private final NumberValue<Float> smartJitterYaw =
316
            numCommon(
317
                    "projectilePuncherSmartJitterYaw",
318
                    "smart_jitter_yaw",
319
                    CommonSettingSchemas.ANGLESMOOTH_JITTER_YAW,
320
                    0.8f,
321
                    0.0f,
322
                    6.0f
323
            );
324
    private final NumberValue<Float> smartJitterPitch =
325
            numCommon(
326
                    "projectilePuncherSmartJitterPitch",
327
                    "smart_jitter_pitch",
328
                    CommonSettingSchemas.ANGLESMOOTH_JITTER_PITCH,
329
                    0.4f,
330
                    0.0f,
331
                    4.0f
332
            );
333
    private final BooleanValue smartDecelerateEnabled =
334
            boolCommon(
335
                    "projectilePuncherSmartDecelerateEnabled",
336
                    "smart_decelerate_enabled",
337
                    CommonSettingSchemas.ANGLESMOOTH_DECELERATE_ENABLED,
338
                    true
339
            );
340
    private final NumberValue<Float> smartDecelerateAngle =
341
            numCommon(
342
                    "projectilePuncherSmartDecelerateAngle",
343
                    "smart_decelerate_angle",
344
                    CommonSettingSchemas.ANGLESMOOTH_DECELERATE_ANGLE,
345
                    35.0f,
346
                    1.0f,
347
                    120.0f
348
            );
349
    private final NumberValue<Float> smartDecelerateMinFactor =
350
            numCommon(
351
                    "projectilePuncherSmartDecelerateMinFactor",
352
                    "smart_decelerate_min_factor",
353
                    CommonSettingSchemas.ANGLESMOOTH_DECELERATE_MIN_FACTOR,
354
                    0.22f,
355
                    0.05f,
356
                    1.0f
357
            );
358
    private final LinearAngleSmooth linearSmooth = new LinearAngleSmooth(
359
            linearHorMin, linearHorMax, linearVertMin, linearVertMax
360
    );
361
    private final SigmoidAngleSmooth sigmoidSmooth = new SigmoidAngleSmooth(
362
            sigmoidHorMin, sigmoidHorMax, sigmoidVertMin, sigmoidVertMax,
363
            sigmoidSteepness, sigmoidMidpoint
364
    );
365
    private final SmartAngleSmooth smartSmooth = new SmartAngleSmooth(
366
            smartYawMin, smartYawMax, smartPitchMin, smartPitchMax,
367
            smartSnapThreshold, smartJitterYaw, smartJitterPitch,
368
            smartDecelerateEnabled, smartDecelerateAngle, smartDecelerateMinFactor
369
    );
370
    private final SpookyAngleSmooth spookySmooth = new SpookyAngleSmooth();
371
    private Entity currentTarget;
372
    private Vec3 lastAimPoint;
373
    private int lastAimEntityId = -1;
374
    private Rotation lastRotation;
375
    private int lastRotationTick = -1;
376
    private int lastAttackExecutionAge = -1;
377
    private boolean rotationReleased = true;
378
379
    private static Map<String, Boolean> projectileDefaults() {
380
        return Map.of(
381
                PROJECTILE_FIREBALL, true,
382
                PROJECTILE_SHULKER_BULLET, true
383
        );
384
    }
385
386
    private static Vec3 clampToBox(Vec3 point, AABB box) {
387
        return new Vec3(
388
                Mth.clamp(point.x, box.minX, box.maxX),
389
                Mth.clamp(point.y, box.minY, box.maxY),
390
                Mth.clamp(point.z, box.minZ, box.maxZ)
391
        );
392
    }
393
394
    @Override
395
    public void onEnable() {
396
        clicker.reset();
397
        currentTarget = null;
398
        lastRotation = null;
399
        lastRotationTick = -1;
400
        lastAttackExecutionAge = -1;
401
        rotationReleased = true;
402
    }
403
404
    @Override
405
    public void onDisable() {
406
        clearTargetImmediate();
407
    }
408
409
    @Override
410
    public void onTick() {
411
        if (mc.player == null || mc.level == null) {
412
            clearTargetImmediate();
413
        }
414
    }
415
416
    @EventHandler(priority = ROTATION_PRIORITY)
417
    public void onRotationUpdate(RotationUpdateEvent event) {
418
        if (!isEnabled()) return;
419
        if (mc.player == null || mc.level == null) {
420
            clearTargetImmediate();
421
            return;
422
        }
423
424
        if (event.getType() == RotationUpdateEvent.Type.POST) {
425
            tryAttackPost();
426
            return;
427
        }
428
429
        clicker.setCps(cpsMin.get(), cpsMax.get());
430
        clicker.tick();
431
432
        List<Entity> candidates = findCandidates();
433
        for (Entity entity : candidates) {
434
            if (processTarget(entity, range.get().floatValue(), wallRange.get().floatValue())) {
435
                currentTarget = entity;
436
                return;
437
            }
438
        }
439
440
        clearTarget();
441
    }
442
443
    private void tryAttackPost() {
444
        if (mc.player == null || mc.level == null || mc.gameMode == null) return;
445
        if (mc.player.tickCount == lastAttackExecutionAge) {
446
            return;
447
        }
448
449
        Entity target = currentTarget;
450
        if (target == null || target.isRemoved()) return;
451
        if (!isInRange(target)) return;
452
453
        Rotation rotation = resolveAttackRotation(target);
454
        if (rotation == null) {
455
            clearTarget();
456
            return;
457
        }
458
        if (!passesRaycast(target, rotation.yaw(), rotation.pitch())) {
459
            return;
460
        }
461
462
        int clickCount = clicker.getClicksAt(0);
463
        if (clickCount <= 0) return;
464
465
        lastAttackExecutionAge = mc.player.tickCount;
466
        for (int i = 0; i < clickCount; i++) {
467
            if (target.isRemoved()) {
468
                break;
469
            }
470
            mc.gameMode.attack(mc.player, target);
471
            mc.player.swing(InteractionHand.MAIN_HAND);
472
        }
473
    }
474
475
    private List<Entity> findCandidates() {
476
        double searchRange = Math.max(range.get(), wallRange.get()) + 8.0;
477
        List<Entity> candidates = mc.level.getEntities(
478
                mc.player,
479
                mc.player.getBoundingBox().inflate(searchRange),
480
                this::isSupportedProjectile
481
        );
482
483
        candidates.removeIf(entity -> !shouldAttack(entity));
484
        candidates.sort(Comparator.comparingDouble(this::predictedDistanceSq));
485
        return candidates;
486
    }
487
488
    private boolean processTarget(Entity target, float range, float wallsRange) {
489
        RotationWithVector rotation = findRotation(target, range, wallsRange);
490
        if (rotation == null) return false;
491
492
        lastRotation = rotation.rotation();
493
        lastRotationTick = mc.player != null ? mc.player.tickCount : -1;
494
        rotationReleased = false;
495
496
        KillAura.RotationTiming timing = rotationTiming.get();
497
        int rotTicks = calculateTicks(rotation.rotation());
498
499
        if (timing == KillAura.RotationTiming.SNAP && !clicker.willClickAt(Math.max(1, rotTicks))) {
500
            return true;
501
        }
502
503
        RotationTarget plan = buildRotationTarget(rotation.rotation(), target);
504
        RotationManager.INSTANCE.setRotationTarget(plan, ROTATION_PRIORITY, this);
505
        return true;
506
    }
507
508
    private Rotation resolveAttackRotation(Entity target) {
509
        if (mc.player == null) return null;
510
511
        Rotation rotation;
512
        KillAura.RotationTiming timing = rotationTiming.get();
513
        if (timing == KillAura.RotationTiming.ON_TICK) {
514
            rotation = lastRotationTick == mc.player.tickCount ? lastRotation : null;
515
            if (rotation == null) {
516
                RotationWithVector rot = findRotation(target, range.get().floatValue(), wallRange.get().floatValue());
517
                rotation = rot != null ? rot.rotation() : null;
518
                if (rotation == null) {
519
                    return null;
520
                }
521
            }
522
        } else {
523
            Rotation current = RotationManager.INSTANCE.getCurrentRotation();
524
            rotation = current != null ? current : new Rotation(mc.player.getYRot(), mc.player.getXRot(), true);
525
        }
526
527
        return rotation.normalize();
528
    }
529
530
    private boolean passesRaycast(Entity target, float yaw, float pitch) {
531
        KillAura.RaycastMode mode = raycast.get();
532
        if (mode == KillAura.RaycastMode.NONE) return true;
533
534
        double maxRange = range.get();
535
        if (mode == KillAura.RaycastMode.THROUGH_WALLS) {
536
            return RaycastUtil.isLookingAtEntity(mc.player, target, yaw, pitch, maxRange, wallRange.get()) != null;
537
        }
538
539
        return RaycastUtil.isLookingAtEntity(mc.player, target, yaw, pitch, maxRange, 0.0) != null;
540
    }
541
542
    private boolean isInRange(Entity target) {
543
        return TargetingUtil.distanceToEntityBoxSq(mc.player.getEyePosition(), target) <= range.get() * range.get();
544
    }
545
546
    private RotationWithVector findRotation(Entity target, float range, float wallsRange) {
547
        if (mc.player == null) return null;
548
549
        Vec3 eyes = mc.player.getEyePosition();
550
        AABB targetBox = predictBox(target);
551
        RotationPreference preference = lastAimEntityId == target.getId() && lastAimPoint != null
552
                ? LeastDifferencePreference.leastDifferenceToLastPoint(eyes, lastAimPoint)
553
                : LeastDifferencePreference.LEAST_DISTANCE_TO_CURRENT_ROTATION;
554
555
        RotationWithVector rot = RotationRaytrace.raytraceBox(
556
                eyes,
557
                targetBox,
558
                range,
559
                wallsRange,
560
                RotationRaytrace.OUTLINE_VISIBILITY,
561
                preference,
562
                true
563
        );
564
565
        if (rot == null && rotationThroughWalls.get()) {
566
            rot = RotationRaytrace.raytraceBox(
567
                    eyes,
568
                    targetBox,
569
                    range,
570
                    range,
571
                    RotationRaytrace.OUTLINE_VISIBILITY,
572
                    preference,
573
                    true
574
            );
575
        }
576
577
        if (rot != null) {
578
            rot = stabilizeRotationResult(target, eyes, targetBox, rot);
579
            lastAimPoint = rot.vec();
580
            lastAimEntityId = target.getId();
581
        }
582
583
        return rot;
584
    }
585
586
    private RotationWithVector stabilizeRotationResult(Entity target, Vec3 eyes, AABB targetBox, RotationWithVector rotation) {
587
        if (target == null || eyes == null || targetBox == null || rotation == null) {
588
            return rotation;
589
        }
590
591
        Vec3 stablePoint = rotation.vec();
592
        if (lastAimEntityId == target.getId() && lastAimPoint != null) {
593
            Vec3 previousPoint = clampToBox(lastAimPoint, targetBox);
594
            double distance = previousPoint.distanceTo(stablePoint);
595
            double blend = distance > 0.50 ? 0.55 : distance > 0.20 ? 0.35 : 0.20;
596
            stablePoint = new Vec3(
597
                    Mth.lerp(blend, previousPoint.x, stablePoint.x),
598
                    Mth.lerp(blend, previousPoint.y, stablePoint.y),
599
                    Mth.lerp(blend, previousPoint.z, stablePoint.z)
600
            );
601
            stablePoint = clampToBox(stablePoint, targetBox);
602
        }
603
604
        Rotation stableRotation = Rotation.lookingAt(stablePoint, eyes).normalize();
605
        return new RotationWithVector(stableRotation, stablePoint);
606
    }
607
608
    private AABB predictBox(Entity entity) {
609
        int ticks = Math.max(0, predictTicks.get());
610
        if (ticks <= 0) {
611
            return entity.getBoundingBox();
612
        }
613
614
        return entity.getBoundingBox().move(entity.getDeltaMovement().scale(ticks));
615
    }
616
617
    private double predictedDistanceSq(Entity entity) {
618
        return TargetingUtil.distanceToBoxSq(mc.player.getEyePosition(), predictBox(entity));
619
    }
620
621
    private boolean shouldAttack(Entity entity) {
622
        Vec3 velocity = entity.getDeltaMovement();
623
        if (velocity.lengthSqr() < 1.0E-7) {
624
            return false;
625
        }
626
627
        Vec3 entityPos = entity.position();
628
        Vec3 vecToPlayer = mc.player.getBoundingBox().getCenter().subtract(entityPos);
629
        double dot = vecToPlayer.dot(velocity);
630
        boolean movingTowardsPlayer = dot > 0.5 * velocity.length() * vecToPlayer.length();
631
632
        AABB extendedHitbox = mc.player.getBoundingBox().inflate(entity.getBoundingBox().getXsize() * 0.5);
633
        boolean touchesHitbox = extendedHitbox.clip(entityPos, entityPos.add(velocity.scale(20.0))).isPresent();
634
        boolean willHitPlayer = !extendedHitbox.contains(entityPos) && touchesHitbox;
635
636
        if (!movingTowardsPlayer && !willHitPlayer) {
637
            return false;
638
        }
639
640
        return predictedDistanceSq(entity) <= range.get() * range.get();
641
    }
642
643
    private boolean isSupportedProjectile(Entity entity) {
644
        if (entity == null || entity.isRemoved()) return false;
645
        EntityType<?> type = entity.getType();
646
        if (type == net.minecraft.world.entity.EntityTypes.FIREBALL) {
647
            return projectiles.get(PROJECTILE_FIREBALL);
648
        }
649
        if (type == net.minecraft.world.entity.EntityTypes.SHULKER_BULLET) {
650
            return projectiles.get(PROJECTILE_SHULKER_BULLET);
651
        }
652
        return false;
653
    }
654
655
    private RotationTarget buildRotationTarget(Rotation rotation, Entity target) {
656
        List<RotationProcessor> processors = new ArrayList<>();
657
        AngleSmooth smooth = selectAngleSmooth();
658
        if (smooth != null) {
659
            processors.add(smooth);
660
        }
661
662
        return new RotationTarget(
663
                rotation,
664
                target,
665
                processors,
666
                rotationResetTicks.get(),
667
                rotationResetThreshold.get(),
668
                !ignoreOpenInventory.get(),
669
                movementCorrection.get(),
670
                null
671
        );
672
    }
673
674
    private int calculateTicks(Rotation rotation) {
675
        AngleSmooth smooth = selectAngleSmooth();
676
        if (smooth == null) return 0;
677
        Rotation base = RotationManager.INSTANCE.getServerRotation();
678
        if (base == null) return 0;
679
        return smooth.calculateTicks(base, rotation);
680
    }
681
682
    private AngleSmooth selectAngleSmooth() {
683
        return switch (rotationMode.get()) {
684
            case LINEAR -> linearSmooth;
685
            case SIGMOID -> sigmoidSmooth;
686
            case SMART -> smartSmooth;
687
            case SPOOKY -> spookySmooth;
688
            case NONE -> null;
689
        };
690
    }
691
692
    private void clearTarget() {
693
        currentTarget = null;
694
        lastAttackExecutionAge = -1;
695
        clearRotationState(true);
696
    }
697
698
    private void clearTargetImmediate() {
699
        currentTarget = null;
700
        lastAttackExecutionAge = -1;
701
        clearRotationState(false);
702
    }
703
704
    private void clearRotationState(boolean smoothReturn) {
705
        if (smoothReturn && rotationReleased) {
706
            return;
707
        }
708
709
        RotationManager.INSTANCE.release(this, smoothReturn);
710
        lastAimPoint = null;
711
        lastAimEntityId = -1;
712
        lastRotation = null;
713
        lastRotationTick = -1;
714
        rotationReleased = true;
715
    }
716
}
717
LiquidBounce (Kotlin)WORLDsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/ModuleProjectilePuncher.ktKotlin · 176 lines · 6.5 KB

Shoots back incoming projectiles around you.

SettingsRangeSwingModeIgnoreOpenInventory
ModuleProjectilePuncher.ktKotlin · Minecraft 26.2 · 176 lines · 6.5 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.world
20
21
import net.ccbluex.liquidbounce.event.events.GameTickEvent
22
import net.ccbluex.liquidbounce.event.events.RotationUpdateEvent
23
import net.ccbluex.liquidbounce.event.handler
24
import net.ccbluex.liquidbounce.features.module.ClientModule
25
import net.ccbluex.liquidbounce.features.module.ModuleCategories
26
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
27
import net.ccbluex.liquidbounce.utils.aiming.RotationsValueGroup
28
import net.ccbluex.liquidbounce.utils.aiming.utils.raytraceBox
29
import net.ccbluex.liquidbounce.utils.block.SwingMode
30
import net.ccbluex.liquidbounce.utils.clicking.Clicker
31
import net.ccbluex.liquidbounce.utils.combat.attackEntity
32
import net.ccbluex.liquidbounce.utils.entity.box
33
import net.ccbluex.liquidbounce.utils.entity.isWithinWorldBorder
34
import net.ccbluex.liquidbounce.utils.entity.lastPos
35
import net.ccbluex.liquidbounce.utils.entity.squaredBoxedDistanceTo
36
import net.ccbluex.liquidbounce.utils.kotlin.Priority
37
import net.ccbluex.liquidbounce.utils.math.isLikelyZero
38
import net.ccbluex.liquidbounce.utils.math.minus
39
import net.ccbluex.liquidbounce.utils.math.plus
40
import net.ccbluex.liquidbounce.utils.math.times
41
import net.ccbluex.liquidbounce.utils.raytracing.isLookingAtEntity
42
import net.minecraft.world.entity.Entity
43
import net.minecraft.world.entity.projectile.ShulkerBullet
44
import net.minecraft.world.entity.projectile.hurtingprojectile.LargeFireball
45
46
/**
47
 * ProjectilePuncher module
48
 *
49
 * Shoots back incoming projectiles around you.
50
 */
51
object ModuleProjectilePuncher : ClientModule(
52
    "ProjectilePuncher",
53
    ModuleCategories.WORLD,
54
    aliases = listOf("AntiFireball")
55
) {
56
57
    private val clicker = tree(Clicker(ModuleProjectilePuncher, mc.options.keyAttack, null))
58
59
    private val range by float("Range", 3f, 3f..6f)
60
    private val swingMode by enumChoice("SwingMode", SwingMode.DO_NOT_HIDE)
61
    private val ignoreOpenInventory by boolean("IgnoreOpenInventory", true)
62
63
    // Target
64
    private var target: Entity? = null
65
66
    // Rotation
67
    private val rotations = tree(RotationsValueGroup(this))
68
69
    override fun onDisabled() {
70
        target = null
71
    }
72
73
    val tickHandler = handler<RotationUpdateEvent> {
74
        if (player.isSpectator) {
75
            return@handler
76
        }
77
78
        updateTarget()
79
    }
80
81
    /**
82
     * Tries to punch the current projectile target when it is in range and the server-side rotation already faces it.
83
     */
84
    val repeatable = handler<GameTickEvent> {
85
        val target = target ?: return@handler
86
87
        if (target.squaredBoxedDistanceTo(player) > range * range ||
88
            isLookingAtEntity(
89
                toEntity = target,
90
                rotation = RotationManager.serverRotation,
91
                range = range.toDouble(),
92
                throughWallsRange = 0.0
93
            ) == null) {
94
            return@handler
95
        }
96
97
        clicker.click {
98
            attackEntity(target, swingMode)
99
            true
100
        }
101
    }
102
103
    private fun updateTarget() {
104
        val rangeSquared = range * range
105
106
        target = null
107
108
        for (entity in world.entitiesForRendering().sortedBy { it.squaredBoxedDistanceTo(player) }) {
109
            if (!shouldAttack(entity)) {
110
                continue
111
            }
112
113
            val nextTickFireballPosition = entity.position() + entity.position() - entity.lastPos
114
115
            val entityBox = entity.dimensions.makeBoundingBox(nextTickFireballPosition)
116
            val distanceSquared = entityBox.distanceToSqr(player.eyePosition)
117
118
            if (distanceSquared > rangeSquared) {
119
                continue
120
            }
121
122
            // find best spot
123
            val spot = raytraceBox(
124
                player.eyePosition, entity.box, range = range.toDouble(), wallsRange = 0.0
125
            ) ?: continue
126
127
            target = entity
128
129
            // aim at target
130
            RotationManager.setRotationTarget(
131
                spot.rotation,
132
                considerInventory = !ignoreOpenInventory,
133
                valueGroup = rotations,
134
                Priority.IMPORTANT_FOR_USER_SAFETY,
135
                this@ModuleProjectilePuncher
136
            )
137
            break
138
        }
139
    }
140
141
    private fun shouldAttack(entity: Entity): Boolean {
142
        if (!entity.isWithinWorldBorder || (entity !is LargeFireball && entity !is ShulkerBullet)) {
143
            return false
144
        }
145
146
        val fireballVelocity = entity.position() - entity.lastPos
147
148
        // If the fireball is not moving the player can obviously not be hit. Additionally, the code below only works if
149
        // the fireball is moving.
150
        if (fireballVelocity.isLikelyZero) {
151
            return false
152
        }
153
154
        // Check if the fireball is going towards the player
155
        val vecToPlayer = player.boundingBox.center - entity.position()
156
157
        val dot = vecToPlayer.dot(fireballVelocity)
158
159
        // if angle less than PI/3 (60 degrees) then
160
        val isMovingTowardsPlayer = dot > 0.5 * fireballVelocity.length() * vecToPlayer.length()
161
162
        val extendedHitbox = player.box.inflate(entity.box.xsize / 2.0)
163
164
        // If the fireball was already inside the player's hitbox, but would be moving away from the player, this
165
        // would unnecessarily trigger the player to attack the fireball.
166
        val touchesHitbox = extendedHitbox.clip(entity.position(), fireballVelocity * 20.0).isPresent
167
        val willHitPlayer = !extendedHitbox.contains(entity.position()) && touchesHitbox
168
169
        // We need two checks in order to prevent following situation: The fireball is very close to the player and
170
        // moving towards their feet. The moving towards player check would fail since the velocity line is not similar
171
        // enough to the vector to the player. This situation is covered by the second check.
172
        return isMovingTowardsPlayer || willHitPlayer
173
    }
174
175
}
176