TargetStrafe module

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

3 implementationsCOMBATMOVEMENT

Full module source: 3 implementations

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

MelaHack (ThunderHack fork)COMBATsrc/main/java/thunder/hack/features/modules/combat/TargetStrafe.javaJava · 277 lines · 10.9 KB

Strafes around the targeted player.

SettingsJumpDistanceBoostspeedReductionMaxVelocity
TargetStrafe.javaJava · Minecraft 26.2 · 277 lines · 10.9 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.combat;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
7
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
8
import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket;
9
import net.minecraft.world.effect.MobEffects;
10
import net.minecraft.world.inventory.ContainerInput;
11
import net.minecraft.world.level.block.Blocks;
12
import net.minecraft.world.phys.AABB;
13
import thunder.hack.core.Core;
14
import thunder.hack.core.manager.client.ModuleManager;
15
import thunder.hack.events.impl.*;
16
import thunder.hack.features.modules.Module;
17
import thunder.hack.injection.accesors.ISPacketEntityVelocity;
18
import thunder.hack.setting.Setting;
19
import thunder.hack.utility.player.InventoryUtility;
20
21
import static thunder.hack.utility.player.MovementUtility.isMoving;
22
23
public class TargetStrafe extends Module {
24
    public Setting<Boolean> jump = new Setting<>("Jump", true);
25
    public Setting<Float> distance = new Setting<>("Distance", 1.3F, 0.2F, 7f);
26
27
    private final Setting<Boost> boost = new Setting<>("Boost", Boost.None);
28
    public Setting<Float> setSpeed = new Setting<>("speed", 1.3F, 0.0F, 2f, v -> boost.getValue() == Boost.Elytra);
29
    private final Setting<Float> velReduction = new Setting<>("Reduction", 6.0f, 0.1f, 10f, v -> boost.getValue() == Boost.Damage);
30
    private final Setting<Float> maxVelocitySpeed = new Setting<>("MaxVelocity", 0.8f, 0.1f, 2f, v -> boost.getValue() == Boost.Damage);
31
32
    public static double oldSpeed, contextFriction, fovval;
33
    public static boolean needSwap, needSprintState, skip, switchDir, disabled;
34
    public static int noSlowTicks, jumpTicks, waterTicks;
35
    static long disableTime;
36
    private static TargetStrafe instance;
37
38
    public TargetStrafe() {
39
        super("TargetStrafe", Category.COMBAT);
40
        instance = this;
41
    }
42
43
    public static TargetStrafe getInstance() {
44
        return instance;
45
    }
46
47
    @Override
48
    public void onEnable() {
49
        oldSpeed = 0;
50
        fovval = mc.options.fovEffectScale().get();
51
        mc.options.fovEffectScale().set(0d);
52
        skip = true;
53
    }
54
55
    public boolean canStrafe() {
56
        if (mc.player.isShiftKeyDown()) return false;
57
        if (mc.player.isInLava()) return false;
58
        if (ModuleManager.scaffold.isEnabled()) return false;
59
        if (ModuleManager.speed.isEnabled()) return false;
60
        if (mc.player.isUnderWater() || waterTicks > 0) return false;
61
        return !mc.player.getAbilities().flying;
62
    }
63
64
    public boolean needToSwitch(double x, double z) {
65
        if (mc.player.horizontalCollision || ((mc.options.keyLeft.isDown() || mc.options.keyRight.isDown()) && jumpTicks <= 0)) {
66
            jumpTicks = 10;
67
            return true;
68
        }
69
        for (int i = (int) (mc.player.getY() + 4); i >= 0; --i) {
70
            BlockPos playerPos = new BlockPos((int) Math.floor(x), (int) Math.floor(i), (int) Math.floor(z));
71
            blockFIRE:
72
            {
73
                blockLAVA:
74
                {
75
                    if (mc.level.getBlockState(playerPos).getBlock().equals(Blocks.LAVA))
76
                        break blockLAVA;
77
                    if (!mc.level.getBlockState(playerPos).getBlock().equals(Blocks.FIRE))
78
                        break blockFIRE;
79
                }
80
                return true;
81
            }
82
            if (mc.level.isEmptyBlock(playerPos)) continue;
83
            return false;
84
        }
85
        return false;
86
    }
87
88
    @Override
89
    public void onDisable() {
90
        mc.options.fovEffectScale().set(fovval);
91
    }
92
93
    public double calculateSpeed(EventMove move) {
94
        jumpTicks--;
95
        float speedAttributes = getAIMoveSpeed();
96
        final float frictionFactor = mc.level.getBlockState(new BlockPos.MutableBlockPos().set(mc.player.getX(), getBoundingBox().min(Direction.Axis.Y) - move.getY(), mc.player.getZ())).getBlock().getFriction() * 0.91F;
97
        float n6 = mc.player.hasEffect(MobEffects.JUMP_BOOST) && mc.player.isUsingItem() ? 0.88f : (float) (oldSpeed > 0.32 && mc.player.isUsingItem() ? 0.88 : 0.91F);
98
        if (mc.player.onGround()) {
99
            n6 = frictionFactor;
100
        }
101
        float n7 = (float) (0.1631f / Math.pow(n6, 3.0f));
102
        float n8;
103
        if (mc.player.onGround()) {
104
            n8 = speedAttributes * n7;
105
            if (move.getY() > 0) {
106
                n8 += boost.getValue() == Boost.Elytra && InventoryUtility.getElytra() != -1 && disabled ? 0.65f : 0.2f;
107
            }
108
            disabled = false;
109
        } else {
110
            n8 = 0.0255f;
111
        }
112
        boolean noslow = false;
113
        double max2 = oldSpeed + n8;
114
        double max = 0.0;
115
        if (mc.player.isUsingItem() && move.getY() <= 0) {
116
            double n10 = oldSpeed + n8 * 0.25;
117
            double motionY2 = move.getY();
118
            if (motionY2 != 0.0 && Math.abs(motionY2) < 0.08) {
119
                n10 += 0.055;
120
            }
121
            if (max2 > (max = Math.max(0.043, n10))) {
122
                noslow = true;
123
                ++noSlowTicks;
124
            } else noSlowTicks = Math.max(noSlowTicks - 1, 0);
125
        } else noSlowTicks = 0;
126
        if (noSlowTicks > 3) max2 = max - 0.019;
127
        else max2 = Math.max(noslow ? 0 : 0.25, max2) - (mc.player.tickCount % 2 == 0 ? 0.001 : 0.002);
128
129
        contextFriction = n6;
130
        if (!mc.player.onGround()) {
131
            needSprintState = !mc.player.wasSprinting;
132
            needSwap = true;
133
        } else needSprintState = false;
134
        return max2;
135
    }
136
137
    public AABB getBoundingBox() {
138
        return new AABB(mc.player.getX() - 0.1, mc.player.getY(), mc.player.getZ() - 0.1, mc.player.getX() + 0.1, mc.player.getY() + 1, mc.player.getZ() + 0.1);
139
    }
140
141
    public float getAIMoveSpeed() {
142
        boolean prevSprinting = mc.player.isSprinting();
143
        mc.player.setSprinting(false);
144
        float speed = mc.player.getSpeed() * 1.3f;
145
        mc.player.setSprinting(prevSprinting);
146
        return speed;
147
    }
148
149
    public static void disabler(int elytra) {
150
        if (elytra == -1) return;
151
        if (System.currentTimeMillis() - disableTime > 190L) {
152
            if (elytra != -2) {
153
                mc.gameMode.handleContainerInput(0, elytra, 1, ContainerInput.PICKUP, mc.player);
154
                mc.gameMode.handleContainerInput(0, 6, 1, ContainerInput.PICKUP, mc.player);
155
            }
156
157
            mc.player.connection.send(new ServerboundPlayerCommandPacket(mc.player, ServerboundPlayerCommandPacket.Action.START_FALL_FLYING));
158
            mc.player.connection.send(new ServerboundPlayerCommandPacket(mc.player, ServerboundPlayerCommandPacket.Action.START_FALL_FLYING));
159
160
            if (elytra != -2) {
161
                mc.gameMode.handleContainerInput(0, 6, 1, ContainerInput.PICKUP, mc.player);
162
                mc.gameMode.handleContainerInput(0, elytra, 1, ContainerInput.PICKUP, mc.player);
163
            }
164
            disableTime = System.currentTimeMillis();
165
        }
166
        disabled = true;
167
    }
168
169
    private double wrapDS(double x, double z) {
170
        double diffX = x - mc.player.getX();
171
        double diffZ = z - mc.player.getZ();
172
        return Math.toDegrees(Math.atan2(diffZ, diffX)) - 90;
173
    }
174
175
    @EventHandler
176
    public void onMove(EventMove event) {
177
        int elytraSlot = InventoryUtility.getElytra();
178
179
        if (boost.getValue() == Boost.Elytra && elytraSlot != -1) {
180
            if (isMoving() && !mc.player.onGround() && mc.level.getBlockCollisions(mc.player, mc.player.getBoundingBox().move(0.0, event.getY(), 0.0f)).iterator().hasNext() && disabled) {
181
                oldSpeed = setSpeed.getValue();
182
            }
183
        }
184
185
        if (canStrafe()) {
186
            if (Aura.target != null && ModuleManager.aura.isEnabled()) {
187
                double speed = calculateSpeed(event);
188
189
                double wrap = Math.atan2(mc.player.getZ() - Aura.target.getZ(), mc.player.getX() - Aura.target.getX());
190
                wrap += switchDir ? speed / Math.sqrt(mc.player.distanceToSqr(Aura.target)) : -(speed / Math.sqrt(mc.player.distanceToSqr(Aura.target)));
191
192
                double x = Aura.target.getX() + distance.getValue() * Math.cos(wrap);
193
                double z = Aura.target.getZ() + distance.getValue() * Math.sin(wrap);
194
195
                if (needToSwitch(x, z)) {
196
                    switchDir = !switchDir;
197
                    wrap += 2 * (switchDir ? speed / Math.sqrt(mc.player.distanceToSqr(Aura.target)) : -(speed / Math.sqrt(mc.player.distanceToSqr(Aura.target))));
198
                    x = Aura.target.getX() + distance.getValue() * Math.cos(wrap);
199
                    z = Aura.target.getZ() + distance.getValue() * Math.sin(wrap);
200
                }
201
202
                event.setX(speed * -Math.sin(Math.toRadians(wrapDS(x, z))));
203
                event.setZ(speed * Math.cos(Math.toRadians(wrapDS(x, z))));
204
                event.cancel();
205
206
            }
207
        } else {
208
            oldSpeed = 0;
209
        }
210
    }
211
212
    @EventHandler
213
    public void updateValues(EventSync e) {
214
        oldSpeed = Math.hypot(mc.player.getX() - mc.player.xo, mc.player.getZ() - mc.player.zo) * contextFriction;
215
216
        if (mc.player.onGround() && jump.getValue() && Aura.target != null) {
217
            mc.player.jumpFromGround();
218
        }
219
220
        if (mc.player.isUnderWater()) {
221
            waterTicks = 10;
222
        } else {
223
            waterTicks--;
224
        }
225
    }
226
227
    @EventHandler
228
    public void onUpdate(PlayerUpdateEvent event) {
229
        if ((boost.getValue() == Boost.Elytra && InventoryUtility.getElytra() != -1 && !mc.player.onGround() && mc.player.fallDistance > 0 && !disabled)) {
230
            disabler(InventoryUtility.getElytra());
231
        }
232
    }
233
234
235
    @EventHandler
236
    public void onPacketReceive(PacketEvent.Receive e) {
237
        if (e.getPacket() instanceof ClientboundPlayerPositionPacket) {
238
            oldSpeed = 0;
239
        }
240
        ClientboundSetEntityMotionPacket velocity;
241
        if (e.getPacket() instanceof ClientboundSetEntityMotionPacket && (velocity = e.getPacket()).id() == mc.player.getId() && boost.getValue() == Boost.Damage) {
242
            if (mc.player.onGround()) return;
243
244
            double vX = velocity.movement().x;
245
            double vZ = velocity.movement().z;
246
247
            if (vX < 0) vX *= -1;
248
            if (vZ < 0) vZ *= -1;
249
250
            oldSpeed = (vX + vZ) / (velReduction.getValue() * 1000f);
251
            oldSpeed = Math.min(oldSpeed, maxVelocitySpeed.getValue());
252
253
            ((ISPacketEntityVelocity) (Object) velocity).setMotionX(0);
254
            ((ISPacketEntityVelocity) (Object) velocity).setMotionY(0);
255
            ((ISPacketEntityVelocity) (Object) velocity).setMotionZ(0);
256
        }
257
    }
258
259
260
    @EventHandler
261
    public void actionEvent(EventSprint eventAction) {
262
        if (canStrafe()) {
263
            if (Core.serverSprint != needSprintState) {
264
                eventAction.setSprintState(!Core.serverSprint);
265
            }
266
        }
267
        if (needSwap) {
268
            eventAction.setSprintState(!mc.player.wasSprinting);
269
            needSwap = false;
270
        }
271
    }
272
273
    private enum Boost {
274
        None, Elytra, Damage
275
    }
276
}
277
CombatantMOVEMENTsrc/main/java/combatant/client/features/module/modules/movement/TargetStrafe.javaJava · 328 lines · 12.5 KB
Settingsmodegrim_point_typegrim_radiusmatrix_point_typeradiusspeedauto_jumponly_key_pressedin_front_of_targetdirection_mode
TargetStrafe.javaJava · Minecraft 26.2 · 328 lines · 12.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.movement;
9
10
import lombok.Getter;
11
import lombok.RequiredArgsConstructor;
12
import net.minecraft.client.Minecraft;
13
import net.minecraft.client.player.LocalPlayer;
14
import net.minecraft.util.Mth;
15
import net.minecraft.world.entity.LivingEntity;
16
import net.minecraft.world.phys.Vec3;
17
import combatant.client.config.values.BooleanValue;
18
import combatant.client.config.values.EnumValue;
19
import combatant.client.config.values.NumberValue;
20
import combatant.client.events.EventHandler;
21
import combatant.client.events.impl.GameTickEvent;
22
import combatant.client.events.impl.MovementInputEvent;
23
import combatant.client.features.module.Module;
24
import combatant.client.features.module.ModuleCategory;
25
import combatant.client.features.module.ModuleInfo;
26
import combatant.client.features.module.Modules;
27
import combatant.client.features.module.modules.combat.KillAura;
28
import combatant.client.util.aiming.RotationManager;
29
import combatant.client.util.combat.SprintController;
30
31
//todo Description
32
@ModuleInfo(
33
        id = "targetstrafe",
34
        displayName = "TargetStrafe",
35
        category = ModuleCategory.MOVEMENT
36
)
37
public final class TargetStrafe extends Module {
38
39
    private final Minecraft mc = Minecraft.getInstance();
40
    private final EnumValue<StrafeMode> mode =
41
            enumMode("mode", StrafeMode.MATRIX, StrafeMode.MATRIX, StrafeMode.GRIM);
42
    private final EnumValue<PointType> grimPointType =
43
            visibleWhen(enumMode("grim_point_type", PointType.CUBE, PointType.CUBE, PointType.CENTER, PointType.CIRCLE), this::isGrimMode);
44
    private final NumberValue<Float> grimRadius =
45
            visibleWhen(num("grim_radius", 0.87f, 0.1f, 1.5f), this::usesGrimRadius);
46
    private final EnumValue<PointType> matrixPointType =
47
            visibleWhen(enumMode("matrix_point_type", PointType.CIRCLE, PointType.CUBE, PointType.CIRCLE), this::isMatrixMode);
48
    private final NumberValue<Float> radius =
49
            visibleWhen(num("radius", 2.5f, 0.1f, 7.0f), this::isMatrixMode);
50
    private final NumberValue<Float> speed =
51
            visibleWhen(num("speed", 0.3f, 0.1f, 1.0f), this::isMatrixMode);
52
    private final BooleanValue autoJump =
53
            bool("auto_jump", true);
54
    private final BooleanValue onlyKeyPressed =
55
            bool("only_key_pressed", false);
56
    private final BooleanValue inFrontOfTarget =
57
            bool("in_front_of_target", false);
58
    private final EnumValue<DirectionMode> directionMode =
59
            enumMode("direction_mode", DirectionMode.CLOCKWISE,
60
                    DirectionMode.CLOCKWISE, DirectionMode.COUNTERCLOCKWISE, DirectionMode.RANDOM);
61
    private int pointIndex;
62
63
    private static float resolveControlYaw() {
64
        var rotation = RotationManager.INSTANCE.getCurrentRotation();
65
        if (rotation != null) {
66
            return rotation.yaw();
67
        }
68
69
        LocalPlayer player = Minecraft.getInstance().player;
70
        return player != null ? player.getYRot() : 0.0f;
71
    }
72
73
    private static void setHorizontalVelocity(LocalPlayer player, float yaw, double speed) {
74
        player.setDeltaMovement(
75
                -Math.sin(Math.toRadians(yaw)) * speed,
76
                player.getDeltaMovement().y,
77
                Math.cos(Math.toRadians(yaw)) * speed
78
        );
79
    }
80
81
    private static boolean hasForwardMovement(float angleDiff) {
82
        return angleDiff > -67.5f && angleDiff < 67.5f;
83
    }
84
85
    @Override
86
    public void onEnable() {
87
        pointIndex = 0;
88
    }
89
90
    @EventHandler
91
    private void onMovementInput(MovementInputEvent event) {
92
        if (!isEnabled() || !isGrimMode()) return;
93
94
        LocalPlayer player = mc.player;
95
        LivingEntity target = currentTarget();
96
        if (player == null || mc.level == null || target == null || !target.isAlive()) return;
97
        if (onlyKeyPressed.get() && !isAnyMovementKeyPressed()) return;
98
99
        Vec3 playerPos = player.position();
100
        Vec3 targetPos = target.position();
101
        double r = grimRadius.get();
102
        int directionMultiplier = resolveDirectionMultiplier();
103
104
        Vec3 nextPoint;
105
        if (inFrontOfTarget.get()) {
106
            float targetYaw = target.getYRot();
107
            if (grimPointType.get() == PointType.CENTER) {
108
                nextPoint = targetPos.add(
109
                        -Math.sin(Math.toRadians(targetYaw)) * r * directionMultiplier,
110
                        0.0,
111
                        Math.cos(Math.toRadians(targetYaw)) * r * directionMultiplier
112
                );
113
            } else {
114
                double offset = Math.cos(System.currentTimeMillis() / 500.0) * r * directionMultiplier;
115
                nextPoint = targetPos.add(
116
                        -Math.sin(Math.toRadians(targetYaw)) * r + Math.cos(Math.toRadians(targetYaw)) * offset,
117
                        0.0,
118
                        Math.cos(Math.toRadians(targetYaw)) * r + Math.sin(Math.toRadians(targetYaw)) * offset
119
                );
120
            }
121
        } else {
122
            nextPoint = switch (grimPointType.get()) {
123
                case CUBE -> nextCubePoint(playerPos, targetPos, r, directionMultiplier);
124
                case CIRCLE -> nextCirclePoint(playerPos, targetPos, r, directionMultiplier);
125
                case CENTER -> new Vec3(targetPos.x, playerPos.y, targetPos.z);
126
            };
127
        }
128
129
        Vec3 direction = nextPoint.subtract(playerPos);
130
        if (direction.lengthSqr() < 1.0E-6) return;
131
        direction = direction.normalize();
132
133
        float yaw = resolveControlYaw();
134
        float movementAngle = (float) Math.toDegrees(Math.atan2(direction.z, direction.x)) - 90.0f;
135
        float angleDiff = Mth.wrapDegrees(movementAngle - yaw);
136
137
        boolean forward = false;
138
        boolean backward = false;
139
        boolean left = false;
140
        boolean right = false;
141
142
        if (angleDiff >= -22.5f && angleDiff < 22.5f) {
143
            forward = true;
144
        } else if (angleDiff >= 22.5f && angleDiff < 67.5f) {
145
            forward = true;
146
            right = true;
147
        } else if (angleDiff >= 67.5f && angleDiff < 112.5f) {
148
            right = true;
149
        } else if (angleDiff >= 112.5f && angleDiff < 157.5f) {
150
            backward = true;
151
            right = true;
152
        } else if (angleDiff >= -67.5f && angleDiff < -22.5f) {
153
            forward = true;
154
            left = true;
155
        } else if (angleDiff >= -112.5f && angleDiff < -67.5f) {
156
            left = true;
157
        } else if (angleDiff >= -157.5f && angleDiff < -112.5f) {
158
            backward = true;
159
            left = true;
160
        } else {
161
            backward = true;
162
        }
163
164
        event.setForward(forward);
165
        event.setBackward(backward);
166
        event.setLeft(left);
167
        event.setRight(right);
168
        event.setSprint(SprintController.INSTANCE.canStartSprinting(player)
169
                && hasForwardMovement(angleDiff));
170
171
        if (autoJump.get() && player.onGround()) {
172
            event.setJump(true);
173
        }
174
    }
175
176
    @EventHandler
177
    private void onTick(GameTickEvent event) {
178
        if (!isEnabled() || !isMatrixMode()) return;
179
180
        LocalPlayer player = mc.player;
181
        LivingEntity target = currentTarget();
182
        if (player == null || mc.level == null || target == null || !target.isAlive()) return;
183
        if (onlyKeyPressed.get() && !isAnyMovementKeyPressed()) return;
184
185
        Vec3 playerPos = player.position();
186
        Vec3 targetPos = target.position();
187
        double r = radius.get();
188
189
        if (autoJump.get() && player.onGround()) {
190
            player.jumpFromGround();
191
        }
192
193
        int directionMultiplier = resolveDirectionMultiplier();
194
195
        if (inFrontOfTarget.get()) {
196
            float targetYaw = target.getYRot();
197
            double x = targetPos.x - Math.sin(Math.toRadians(targetYaw)) * r * directionMultiplier;
198
            double z = targetPos.z + Math.cos(Math.toRadians(targetYaw)) * r * directionMultiplier;
199
200
            float yaw = (float) Math.toDegrees(Math.atan2(z - playerPos.z, x - playerPos.x)) - 90.0f;
201
            setHorizontalVelocity(player, yaw, speed.get());
202
            requestSprintForMovementYaw(player, yaw);
203
            return;
204
        }
205
206
        if (matrixPointType.get() == PointType.CUBE) {
207
            Vec3 nextPoint = nextCubePoint(playerPos, targetPos, r, directionMultiplier);
208
            Vec3 dirVec = nextPoint.subtract(playerPos);
209
            if (dirVec.lengthSqr() < 1.0E-6) return;
210
            dirVec = dirVec.normalize();
211
212
            float yaw = (float) Math.toDegrees(Math.atan2(dirVec.z, dirVec.x)) - 90.0f;
213
            setHorizontalVelocity(player, yaw, speed.get());
214
            requestSprintForMovementYaw(player, yaw);
215
            return;
216
        }
217
218
        double angle = Math.atan2(playerPos.z - targetPos.z, playerPos.x - targetPos.x);
219
        angle += directionMultiplier * speed.get() / Math.max(playerPos.distanceTo(targetPos), r);
220
221
        double x = targetPos.x + r * Math.cos(angle);
222
        double z = targetPos.z + r * Math.sin(angle);
223
        float yaw = (float) Math.toDegrees(Math.atan2(z - playerPos.z, x - playerPos.x)) - 90.0f;
224
        setHorizontalVelocity(player, yaw, speed.get());
225
        requestSprintForMovementYaw(player, yaw);
226
    }
227
228
    private LivingEntity currentTarget() {
229
        KillAura killAura = Modules.get(KillAura.class);
230
        if (killAura == null || !killAura.isEnabled()) {
231
            return null;
232
        }
233
        return killAura.getCurrentTarget();
234
    }
235
236
    public boolean shouldDisableAuraFreeCorrection() {
237
        return isEnabled() && isGrimMode() && currentTarget() != null;
238
    }
239
240
    private int resolveDirectionMultiplier() {
241
        return switch (directionMode.get()) {
242
            case COUNTERCLOCKWISE -> -1;
243
            case RANDOM -> ((System.currentTimeMillis() / 3000L) % 2L == 0L) ? 1 : -1;
244
            case CLOCKWISE -> 1;
245
        };
246
    }
247
248
    private Vec3 nextCubePoint(Vec3 playerPos, Vec3 targetPos, double radius, int directionMultiplier) {
249
        Vec3[] points = new Vec3[]{
250
                new Vec3(targetPos.x - radius, playerPos.y, targetPos.z - radius),
251
                new Vec3(targetPos.x - radius, playerPos.y, targetPos.z + radius),
252
                new Vec3(targetPos.x + radius, playerPos.y, targetPos.z + radius),
253
                new Vec3(targetPos.x + radius, playerPos.y, targetPos.z - radius)
254
        };
255
256
        if (playerPos.distanceTo(points[pointIndex]) < 0.5) {
257
            pointIndex = (pointIndex + directionMultiplier + points.length) % points.length;
258
        }
259
260
        return points[pointIndex];
261
    }
262
263
    private Vec3 nextCirclePoint(Vec3 playerPos, Vec3 targetPos, double radius, int directionMultiplier) {
264
        double baseAngle = (System.currentTimeMillis() % 3600L) / 3600.0 * 4.0 * Math.PI;
265
        double angle = directionMultiplier > 0 ? baseAngle : (2.0 * Math.PI - baseAngle);
266
        return new Vec3(
267
                targetPos.x + Math.cos(angle) * radius,
268
                playerPos.y,
269
                targetPos.z + Math.sin(angle) * radius
270
        );
271
    }
272
273
    private boolean isAnyMovementKeyPressed() {
274
        return mc.options != null
275
                && (mc.options.keyUp.isDown()
276
                || mc.options.keyDown.isDown()
277
                || mc.options.keyLeft.isDown()
278
                || mc.options.keyRight.isDown());
279
    }
280
281
    private void requestSprintForMovementYaw(LocalPlayer player, float movementYaw) {
282
        float controlYaw = resolveControlYaw();
283
        float angleDiff = Mth.wrapDegrees(movementYaw - controlYaw);
284
        SprintController.INSTANCE.requestStartSprinting(mc, player, hasForwardMovement(angleDiff));
285
    }
286
287
    private boolean isMatrixMode() {
288
        return mode.get() == StrafeMode.MATRIX;
289
    }
290
291
    private boolean isGrimMode() {
292
        return mode.get() == StrafeMode.GRIM;
293
    }
294
295
    private boolean usesGrimRadius() {
296
        return isGrimMode() && (grimPointType.get() == PointType.CUBE || grimPointType.get() == PointType.CIRCLE);
297
    }
298
299
    @Getter
300
    @RequiredArgsConstructor
301
    private enum StrafeMode implements EnumValue.IdProvider {
302
        MATRIX("Matrix"),
303
        GRIM("Grim");
304
305
        private final String id;
306
    }
307
308
    @Getter
309
    @RequiredArgsConstructor
310
    private enum PointType implements EnumValue.IdProvider {
311
        CUBE("Cube"),
312
        CENTER("Center"),
313
        CIRCLE("Circle");
314
315
        private final String id;
316
    }
317
318
    @Getter
319
    @RequiredArgsConstructor
320
    private enum DirectionMode implements EnumValue.IdProvider {
321
        CLOCKWISE("Clockwise"),
322
        COUNTERCLOCKWISE("Counterclockwise"),
323
        RANDOM("Random");
324
325
        private final String id;
326
    }
327
}
328
LiquidBounce (Kotlin)MOVEMENTsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleTargetStrafe.ktKotlin · 460 lines · 16.6 KB

Automatically strafes around enemies targeted by KillAura.

SettingsWidthHeightOffsetOuterColorInnerColorOutlineColorShowNextPointPointRadiusPointColorPointOutlineColorInvalidPointColorInvalidPointOutlineColorControlDirectionMaxFallHeightSafetyExpandMaxRangeRangeStepHypixel
ModuleTargetStrafe.ktKotlin · Minecraft 26.2 · 460 lines · 16.6 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
package net.ccbluex.liquidbounce.features.module.modules.movement
21
22
import net.ccbluex.liquidbounce.config.types.group.Mode
23
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
24
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
25
import net.ccbluex.liquidbounce.config.types.list.Tagged
26
import net.ccbluex.liquidbounce.event.events.MovementInputEvent
27
import net.ccbluex.liquidbounce.event.events.PlayerMoveEvent
28
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
29
import net.ccbluex.liquidbounce.event.handler
30
import net.ccbluex.liquidbounce.features.module.ClientModule
31
import net.ccbluex.liquidbounce.features.module.ModuleCategories
32
import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleAimbot
33
import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura
34
import net.ccbluex.liquidbounce.features.module.modules.movement.speed.ModuleSpeed
35
import net.ccbluex.liquidbounce.features.module.modules.movement.speed.modes.watchdog.SpeedHypixelLowHop
36
import net.ccbluex.liquidbounce.render.drawCircleOutline
37
import net.ccbluex.liquidbounce.render.drawGradientCircle
38
import net.ccbluex.liquidbounce.render.engine.type.Color4b
39
import net.ccbluex.liquidbounce.render.renderEnvironment
40
import net.ccbluex.liquidbounce.render.withPositionRelativeToCamera
41
import net.ccbluex.liquidbounce.utils.combat.TargetSelector
42
import net.ccbluex.liquidbounce.utils.entity.anyHorizontal
43
import net.ccbluex.liquidbounce.utils.entity.horizontalSpeed
44
import net.ccbluex.liquidbounce.utils.entity.initial
45
import net.ccbluex.liquidbounce.utils.entity.interpolateCurrentPosition
46
import net.ccbluex.liquidbounce.utils.entity.untransformed
47
import net.ccbluex.liquidbounce.utils.entity.withStrafe
48
import net.ccbluex.liquidbounce.utils.entity.wouldFallIntoVoid
49
import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention.MODEL_STATE
50
import net.ccbluex.liquidbounce.utils.math.horizontalDistanceTo
51
import net.ccbluex.liquidbounce.utils.movement.DirectionalInput
52
import net.ccbluex.liquidbounce.utils.movement.getDegreesRelativeToView
53
import net.ccbluex.liquidbounce.utils.movement.getDirectionalInputForDegrees
54
import net.minecraft.util.Mth
55
import net.minecraft.world.entity.LivingEntity
56
import net.minecraft.world.entity.MoverType
57
import net.minecraft.world.phys.Vec3
58
import net.ccbluex.liquidbounce.utils.math.yaw
59
import kotlin.math.atan2
60
import kotlin.math.cos
61
import kotlin.math.floor
62
import kotlin.math.sin
63
64
/**
65
 * Target Strafe Module
66
 *
67
 * Handles strafing around a locked target.
68
 */
69
object ModuleTargetStrafe : ClientModule("TargetStrafe", ModuleCategories.MOVEMENT) {
70
71
    private data class StrafePlan(
72
        val target: LivingEntity,
73
        val orbitRadius: Float,
74
        val strafeVec: Vec3,
75
        val pointCoords: Vec3,
76
        val pointValid: Boolean,
77
    )
78
79
    private val renderState = object {
80
        @JvmField var target: LivingEntity? = null
81
        @JvmField var orbitRadius: Float = 0F
82
        @JvmField var nextPoint: Vec3 = Vec3.ZERO
83
        @JvmField var nextPointValid: Boolean = false
84
85
        fun reset() {
86
            this.target = null
87
            this.orbitRadius = 0F
88
            this.nextPoint = Vec3.ZERO
89
            this.nextPointValid = false
90
        }
91
    }
92
93
    private var direction = 1
94
95
    // Configuration options
96
    private val modes = choices("Mode", MotionMode, arrayOf(MotionMode, InputMode)).apply { tagBy(this) }
97
    private val range = float("Range", 2.95f, 0.0f..8.0f)
98
    private val targetSelector = TargetSelector(range = range)
99
    private val followRangeValue = float("FollowRange", 4f, 0.0f..10.0f).onChange {
100
        it.coerceAtLeast(targetSelector.maxRange)
101
    }
102
    private val followRange get() = followRangeValue.get()
103
104
    private val requirements by multiEnumChoice<Requirements>("Requirements")
105
106
    private fun firstTarget() =
107
        ModuleKillAura.targetTracker.target
108
            ?: ModuleAimbot.targetTracker.target
109
            ?: targetSelector.targets().firstOrNull()
110
111
    private val requirementsMet
112
        get() = requirements.all { it.meets() }
113
114
    init {
115
        range.onChanged { updatedRange ->
116
            if (followRange < updatedRange) {
117
                followRangeValue.set(updatedRange)
118
            }
119
        }
120
121
        tree(Planner)
122
        tree(Visuals)
123
    }
124
125
    private object Visuals : ToggleableValueGroup(ModuleTargetStrafe, "Visuals", true) {
126
127
        init {
128
            doNotIncludeAlways()
129
        }
130
131
        private val width by float("Width", 0.12f, 0.01f..1.0f)
132
        private val heightOffset by float("HeightOffset", 0.05f, -1.0f..1.0f)
133
134
        private val outerColor by color("OuterColor", Color4b.LIQUID_BOUNCE.alpha(100))
135
        private val innerColor by color("InnerColor", Color4b.LIQUID_BOUNCE.alpha(20))
136
        private val outlineColor by color("OutlineColor", Color4b.LIQUID_BOUNCE.alpha(180))
137
138
        private val showNextPoint by boolean("ShowNextPoint", true)
139
        private val pointRadius by float("PointRadius", 0.18f, 0.05f..1.0f)
140
        private val pointColor by color("PointColor", Color4b.LIQUID_BOUNCE.alpha(90))
141
        private val pointOutlineColor by color("PointOutlineColor", Color4b.LIQUID_BOUNCE.alpha(180))
142
        private val invalidPointColor by color("InvalidPointColor", Color4b(255, 90, 90, 90))
143
        private val invalidPointOutlineColor by color("InvalidPointOutlineColor", Color4b(255, 90, 90, 180))
144
145
        override fun onDisabled() {
146
            renderState.reset()
147
        }
148
149
        @Suppress("unused")
150
        private val renderHandler = handler<WorldRenderEvent> { event ->
151
            val state = renderState
152
            val target = state.target ?: return@handler
153
            if (target.isRemoved) {
154
                renderState.reset()
155
                return@handler
156
            }
157
158
            event.renderEnvironment {
159
                val orbitOuterRadius = state.orbitRadius + width / 2f
160
                val orbitInnerRadius = (state.orbitRadius - width / 2f).coerceAtLeast(0f)
161
                val orbitPosition = target.interpolateCurrentPosition(event.partialTicks)
162
                    .add(0.0, heightOffset.toDouble(), 0.0)
163
164
                withPositionRelativeToCamera(orbitPosition) {
165
                    drawGradientCircle(orbitOuterRadius, orbitInnerRadius, outerColor, innerColor)
166
                    drawCircleOutline(orbitOuterRadius, outlineColor)
167
                }
168
169
                if (!showNextPoint) {
170
                    return@renderEnvironment
171
                }
172
173
                val markerColor = if (state.nextPointValid) pointColor else invalidPointColor
174
                val markerOutlineColor = if (state.nextPointValid) pointOutlineColor else invalidPointOutlineColor
175
176
                withPositionRelativeToCamera(state.nextPoint.add(0.0, heightOffset.toDouble(), 0.0)) {
177
                    drawGradientCircle(pointRadius, 0f, markerColor, Color4b.TRANSPARENT)
178
                    drawCircleOutline(pointRadius, markerOutlineColor)
179
                }
180
            }
181
        }
182
    }
183
184
    object Planner : ToggleableValueGroup(ModuleTargetStrafe, "Planner", true) {
185
        val controlDirection by boolean("ControlDirection", true)
186
187
        init {
188
            tree(Validation)
189
            tree(AdaptiveRange)
190
        }
191
192
        object Validation : ToggleableValueGroup(Planner, "Validation", true) {
193
194
            init {
195
                tree(EdgeCheck)
196
                tree(VoidCheck)
197
            }
198
199
            object EdgeCheck : ToggleableValueGroup(Validation, "EdgeCheck", true) {
200
                val maxFallHeight by float("MaxFallHeight", 1.2f, 0.1f..4f)
201
            }
202
203
            object VoidCheck : ToggleableValueGroup(Validation, "VoidCheck", true) {
204
                val safetyExpand by float("SafetyExpand", 0.1f, 0.0f..5f)
205
            }
206
207
            /**
208
             * Validate if [point] is safe to strafe to
209
             */
210
            internal fun validatePoint(point: Vec3): Boolean {
211
                if (!validateCollision(point)) {
212
                    return false
213
                }
214
215
                if (!enabled) {
216
                    return true
217
                }
218
219
                if (EdgeCheck.enabled && isCloseToFall(point)) {
220
                    return false
221
                }
222
223
                if (VoidCheck.enabled && player.wouldFallIntoVoid(
224
                        point,
225
                        safetyExpand = VoidCheck.safetyExpand.toDouble()
226
                    )
227
                ) {
228
                    return false
229
                }
230
231
                return true
232
            }
233
234
            private fun validateCollision(point: Vec3, expand: Double = 0.0): Boolean {
235
                val hitbox = player.dimensions.makeBoundingBox(point).inflate(expand, 0.0, expand)
236
                return world.noCollision(player, hitbox)
237
            }
238
239
            private fun isCloseToFall(position: Vec3): Boolean {
240
                position.y = floor(position.y)
241
                val hitbox = player.dimensions
242
                    .makeBoundingBox(position)
243
                    .inflate(-0.05, 0.0, -0.05)
244
                    .move(0.0, -EdgeCheck.maxFallHeight.toDouble(), 0.0)
245
                return world.noCollision(player, hitbox)
246
            }
247
        }
248
249
        object AdaptiveRange : ToggleableValueGroup(Planner, "AdaptiveRange", false) {
250
            val maxRange by float("MaxRange", 4f, 1f..5f)
251
            val rangeStep by float("RangeStep", 0.5f, 0.1f..1.0f)
252
        }
253
    }
254
255
    object MotionMode : Mode("Motion") {
256
        override val parent: ModeValueGroup<Mode>
257
            get() = modes
258
259
        private val hypixel by boolean("Hypixel", false)
260
261
        // Event handler for player movement
262
        @Suppress("unused")
263
        private val moveHandler = handler<PlayerMoveEvent>(priority = MODEL_STATE) { event ->
264
            if (event.type != MoverType.SELF) {
265
                return@handler
266
            }
267
268
            if (!player.input.initial.anyHorizontal) {
269
                renderState.reset()
270
                return@handler
271
            }
272
273
            val strafePlan = computeStrafePlan(
274
                speed = player.horizontalSpeed,
275
                controlInput = DirectionalInput(player.input.untransformed)
276
            ) ?: return@handler
277
278
            if (!strafePlan.pointValid) {
279
                return@handler
280
            }
281
282
            // Perform the strafing movement
283
            if (hypixel && ModuleSpeed.running) {
284
                val minSpeed = if (player.onGround()) {
285
                    0.48
286
                } else {
287
                    0.281
288
                }
289
290
                if (SpeedHypixelLowHop.shouldStrafe) {
291
                    event.movement = event.movement.withStrafe(
292
                        yaw = strafePlan.strafeVec.yaw,
293
                        speed = player.horizontalSpeed.coerceAtLeast(minSpeed),
294
                        input = null
295
                    )
296
                } else {
297
                    event.movement = event.movement.withStrafe(
298
                        yaw = strafePlan.strafeVec.yaw,
299
                        speed = player.horizontalSpeed.coerceAtLeast(minSpeed),
300
                        strength = 0.02,
301
                        input = null
302
                    )
303
                }
304
            } else {
305
                event.movement = event.movement.withStrafe(
306
                    yaw = strafePlan.strafeVec.yaw,
307
                    speed = player.horizontalSpeed,
308
                    input = null
309
                )
310
            }
311
        }
312
    }
313
314
    object InputMode : Mode("Input") {
315
        override val parent: ModeValueGroup<Mode>
316
            get() = modes
317
318
        @Suppress("unused")
319
        private val inputHandler = handler<MovementInputEvent>(priority = MODEL_STATE) { event ->
320
            if (!event.directionalInput.isMoving) {
321
                renderState.reset()
322
                return@handler
323
            }
324
325
            val strafePlan = computeStrafePlan(
326
                speed = player.horizontalSpeed,
327
                controlInput = event.directionalInput
328
            ) ?: return@handler
329
330
            if (!strafePlan.pointValid) {
331
                return@handler
332
            }
333
334
            val movementDegrees = getDegreesRelativeToView(strafePlan.strafeVec, player.yRot)
335
            event.directionalInput = getDirectionalInputForDegrees(
336
                directionalInput = DirectionalInput.NONE,
337
                dgs = movementDegrees
338
            )
339
        }
340
    }
341
342
    /**
343
     * Computes the shared target-strafe plan used by both movement and input modes.
344
     */
345
    @Suppress("CognitiveComplexMethod")
346
    private fun computeStrafePlan(speed: Double, controlInput: DirectionalInput): StrafePlan? {
347
        if (!requirementsMet) {
348
            renderState.reset()
349
            return null
350
        }
351
352
        // Get the target entity, requires a locked target
353
        val target = firstTarget() ?: run {
354
            renderState.reset()
355
            return null
356
        }
357
358
        val playerPos = player.position()
359
        val targetPos = target.position()
360
        val distance = playerPos.horizontalDistanceTo(targetPos)
361
362
        // return if we're too far
363
        if (distance > followRange) {
364
            renderState.reset()
365
            return null
366
        }
367
368
        if (player.horizontalCollision) {
369
            direction = -direction
370
        }
371
372
        // Determine the direction to strafe
373
        if (Planner.controlDirection && !(controlInput.left && controlInput.right)) {
374
            when {
375
                controlInput.left -> direction = -1
376
                controlInput.right -> direction = 1
377
            }
378
        }
379
380
        val strafeYaw = atan2(targetPos.z - playerPos.z, targetPos.x - playerPos.x)
381
        fun createPlan(range: Float): StrafePlan {
382
            val strafeVec = computeDirectionVec(strafeYaw, distance, speed, range, direction)
383
            val pointCoords = playerPos.add(strafeVec)
384
            return StrafePlan(
385
                target = target,
386
                orbitRadius = range,
387
                strafeVec = strafeVec,
388
                pointCoords = pointCoords,
389
                pointValid = Planner.Validation.validatePoint(pointCoords),
390
            )
391
        }
392
393
        var plan = createPlan(targetSelector.maxRange)
394
395
        if (!plan.pointValid) {
396
            if (!Planner.AdaptiveRange.enabled) {
397
                direction = -direction
398
                plan = createPlan(targetSelector.maxRange)
399
            } else {
400
                var currentRange = Planner.AdaptiveRange.rangeStep
401
                while (!plan.pointValid) {
402
                    plan = createPlan(currentRange)
403
                    currentRange += Planner.AdaptiveRange.rangeStep
404
405
                    if (currentRange > Planner.AdaptiveRange.maxRange) {
406
                        direction = -direction
407
                        plan = createPlan(targetSelector.maxRange)
408
                        break
409
                    }
410
                }
411
            }
412
        }
413
414
        renderState.target = plan.target
415
        renderState.orbitRadius = plan.orbitRadius
416
        renderState.nextPoint = plan.pointCoords
417
        renderState.nextPointValid = plan.pointValid
418
419
        return plan
420
    }
421
422
    /**
423
     * Computes the direction vector for strafing
424
     */
425
    private fun computeDirectionVec(
426
        strafeYaw: Double,
427
        distance: Double,
428
        speed: Double,
429
        range: Float,
430
        direction: Int
431
    ): Vec3 {
432
        val yaw = strafeYaw - Mth.HALF_PI
433
        val encirclement = maxOf(-speed, distance - range)
434
        val encirclementX = -sin(yaw) * encirclement
435
        val encirclementZ = cos(yaw) * encirclement
436
        val strafeX = -sin(strafeYaw) * speed * direction
437
        val strafeZ = cos(strafeYaw) * speed * direction
438
        return Vec3(encirclementX + strafeX, 0.0, encirclementZ + strafeZ)
439
    }
440
441
    @Suppress("unused")
442
    private enum class Requirements(
443
        override val tag: String,
444
        val meets: () -> Boolean
445
    ) : Tagged {
446
        SPACE("Space", {
447
            mc.options.keyJump.isDown
448
        }),
449
        SPEED("Speed", {
450
            ModuleSpeed.running
451
        }),
452
        KILLAURA("KillAura", {
453
            ModuleKillAura.running
454
        }),
455
        GROUND("Ground", {
456
            player.onGround()
457
        });
458
    }
459
}
460