velocity module

velocity: Minecraft 26.3 cheat module, full source for every implementation (4 clients: Meteor Client, MelaHack (ThunderHack fork), Combatant, …).

4 implementationsMovementMOVEMENTCOMBAT

Full module source: 4 implementations

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

Meteor ClientMovementsrc/main/java/meteordevelopment/meteorclient/systems/modules/movement/Velocity.javaJava · 172 lines · 6.4 KB

Prevents you from being moved by external forces.

Settingsknockbackknockback-horizontalknockback-verticalexplosionsexplosions-horizontalexplosions-verticalliquidsliquids-horizontalliquids-verticalentity-pushentity-push-amountblockssinkingfishing
Velocity.javaJava · Minecraft 26.2 · 172 lines · 6.4 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3
 * Copyright (c) Meteor Development.
4
 */
5
6
package meteordevelopment.meteorclient.systems.modules.movement;
7
8
import meteordevelopment.meteorclient.events.packets.PacketEvent;
9
import meteordevelopment.meteorclient.events.world.TickEvent;
10
import meteordevelopment.meteorclient.mixin.ClientboundSetEntityMotionPacketAccessor;
11
import meteordevelopment.meteorclient.mixininterface.IVec3;
12
import meteordevelopment.meteorclient.settings.BoolSetting;
13
import meteordevelopment.meteorclient.settings.DoubleSetting;
14
import meteordevelopment.meteorclient.settings.Setting;
15
import meteordevelopment.meteorclient.settings.SettingGroup;
16
import meteordevelopment.meteorclient.systems.modules.Categories;
17
import meteordevelopment.meteorclient.systems.modules.Module;
18
import meteordevelopment.orbit.EventHandler;
19
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
20
import net.minecraft.world.phys.Vec3;
21
22
public class Velocity extends Module {
23
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
24
25
    public final Setting<Boolean> knockback = sgGeneral.add(new BoolSetting.Builder()
26
        .name("knockback")
27
        .description("Modifies the amount of knockback you take from attacks.")
28
        .defaultValue(true)
29
        .build()
30
    );
31
32
    public final Setting<Double> knockbackHorizontal = sgGeneral.add(new DoubleSetting.Builder()
33
        .name("knockback-horizontal")
34
        .description("How much horizontal knockback you will take.")
35
        .defaultValue(0)
36
        .sliderMax(1)
37
        .visible(knockback::get)
38
        .build()
39
    );
40
41
    public final Setting<Double> knockbackVertical = sgGeneral.add(new DoubleSetting.Builder()
42
        .name("knockback-vertical")
43
        .description("How much vertical knockback you will take.")
44
        .defaultValue(0)
45
        .sliderMax(1)
46
        .visible(knockback::get)
47
        .build()
48
    );
49
50
    public final Setting<Boolean> explosions = sgGeneral.add(new BoolSetting.Builder()
51
        .name("explosions")
52
        .description("Modifies your knockback from explosions.")
53
        .defaultValue(true)
54
        .build()
55
    );
56
57
    public final Setting<Double> explosionsHorizontal = sgGeneral.add(new DoubleSetting.Builder()
58
        .name("explosions-horizontal")
59
        .description("How much velocity you will take from explosions horizontally.")
60
        .defaultValue(0)
61
        .sliderMax(1)
62
        .visible(explosions::get)
63
        .build()
64
    );
65
66
    public final Setting<Double> explosionsVertical = sgGeneral.add(new DoubleSetting.Builder()
67
        .name("explosions-vertical")
68
        .description("How much velocity you will take from explosions vertically.")
69
        .defaultValue(0)
70
        .sliderMax(1)
71
        .visible(explosions::get)
72
        .build()
73
    );
74
75
    public final Setting<Boolean> liquids = sgGeneral.add(new BoolSetting.Builder()
76
        .name("liquids")
77
        .description("Modifies the amount you are pushed by flowing liquids.")
78
        .defaultValue(true)
79
        .build()
80
    );
81
82
    public final Setting<Double> liquidsHorizontal = sgGeneral.add(new DoubleSetting.Builder()
83
        .name("liquids-horizontal")
84
        .description("How much velocity you will take from liquids horizontally.")
85
        .defaultValue(0)
86
        .sliderMax(1)
87
        .visible(liquids::get)
88
        .build()
89
    );
90
91
    public final Setting<Double> liquidsVertical = sgGeneral.add(new DoubleSetting.Builder()
92
        .name("liquids-vertical")
93
        .description("How much velocity you will take from liquids vertically.")
94
        .defaultValue(0)
95
        .sliderMax(1)
96
        .visible(liquids::get)
97
        .build()
98
    );
99
100
    public final Setting<Boolean> entityPush = sgGeneral.add(new BoolSetting.Builder()
101
        .name("entity-push")
102
        .description("Modifies the amount you are pushed by entities.")
103
        .defaultValue(true)
104
        .build()
105
    );
106
107
    public final Setting<Double> entityPushAmount = sgGeneral.add(new DoubleSetting.Builder()
108
        .name("entity-push-amount")
109
        .description("How much you will be pushed.")
110
        .defaultValue(0)
111
        .sliderMax(1)
112
        .visible(entityPush::get)
113
        .build()
114
    );
115
116
    public final Setting<Boolean> blocks = sgGeneral.add(new BoolSetting.Builder()
117
        .name("blocks")
118
        .description("Prevents you from being pushed out of blocks.")
119
        .defaultValue(true)
120
        .build()
121
    );
122
123
    public final Setting<Boolean> sinking = sgGeneral.add(new BoolSetting.Builder()
124
        .name("sinking")
125
        .description("Prevents you from sinking in liquids.")
126
        .defaultValue(false)
127
        .build()
128
    );
129
130
    public final Setting<Boolean> fishing = sgGeneral.add(new BoolSetting.Builder()
131
        .name("fishing")
132
        .description("Prevents you from being pulled by fishing rods.")
133
        .defaultValue(false)
134
        .build()
135
    );
136
137
    public Velocity() {
138
        super(Categories.Movement, "velocity", "Prevents you from being moved by external forces.");
139
    }
140
141
    @EventHandler
142
    private void onTick(TickEvent.Post event) {
143
        if (!sinking.get()) return;
144
        if (mc.options.keyJump.isDown() || mc.options.keyShift.isDown()) return;
145
146
        if ((mc.player.isInWater() || mc.player.isInLava()) && mc.player.getDeltaMovement().y < 0) {
147
            ((IVec3) mc.player.getDeltaMovement()).meteor$setY(0);
148
        }
149
    }
150
151
    @EventHandler
152
    private void onPacketReceive(PacketEvent.Receive event) {
153
        if (knockback.get() && event.packet instanceof ClientboundSetEntityMotionPacket packet
154
            && packet.id() == mc.player.getId()) {
155
            double velX = (packet.movement().x() - mc.player.getDeltaMovement().x) * knockbackHorizontal.get();
156
            double velY = (packet.movement().y() - mc.player.getDeltaMovement().y) * knockbackVertical.get();
157
            double velZ = (packet.movement().z() - mc.player.getDeltaMovement().z) * knockbackHorizontal.get();
158
            ((ClientboundSetEntityMotionPacketAccessor) (Object) packet).meteor$setMovement(
159
                new Vec3(velX + mc.player.getDeltaMovement().x, velY + mc.player.getDeltaMovement().y, velZ + mc.player.getDeltaMovement().z)
160
            );
161
        }
162
    }
163
164
    public double getHorizontal(Setting<Double> setting) {
165
        return isActive() ? setting.get() : 1;
166
    }
167
168
    public double getVertical(Setting<Double> setting) {
169
        return isActive() ? setting.get() : 1;
170
    }
171
}
172
MelaHack (ThunderHack fork)MOVEMENTsrc/main/java/thunder/hack/features/modules/movement/Velocity.javaJava · 232 lines · 10.7 KB

Prevents knockback.

SettingsOnlyDuringAuraPauseInLiquidsExplosionsPauseOnFlagPauseOnFireModeVerticalJumpModeHorizontalMotionSmartFailFailRateFailJumpRate
Velocity.javaJava · Minecraft 26.2 · 232 lines · 10.7 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.movement;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.network.protocol.common.ClientboundPingPacket;
7
import net.minecraft.network.protocol.game.ClientboundExplodePacket;
8
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
9
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
10
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
11
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
12
import net.minecraft.world.phys.Vec3;
13
import thunder.hack.core.manager.client.ModuleManager;
14
import thunder.hack.events.impl.PacketEvent;
15
import thunder.hack.features.modules.Module;
16
import thunder.hack.injection.accesors.IClientPlayerEntity;
17
import thunder.hack.injection.accesors.IEntity;
18
import thunder.hack.injection.accesors.IExplosionS2CPacket;
19
import thunder.hack.injection.accesors.ISPacketEntityVelocity;
20
import thunder.hack.setting.Setting;
21
import thunder.hack.utility.player.MovementUtility;
22
23
import java.util.Optional;
24
//TY <3
25
//https://github.com/SkidderMC/FDPClient/blob/main/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/velocitys/vanilla/JumpVelocity.kt
26
27
public class Velocity extends Module {
28
    public Velocity() {
29
        super("Velocity", Category.MOVEMENT);
30
    }
31
32
    public Setting<Boolean> onlyAura = new Setting<>("OnlyDuringAura", false);
33
    public Setting<Boolean> pauseInWater = new Setting<>("PauseInLiquids", false);
34
    public Setting<Boolean> explosions = new Setting<>("Explosions", true);
35
    public Setting<Boolean> cc = new Setting<>("PauseOnFlag", false);
36
    public Setting<Boolean> fire = new Setting<>("PauseOnFire", false);
37
    private final Setting<modeEn> mode = new Setting<>("Mode", modeEn.Matrix);
38
    public Setting<Float> vertical = new Setting<>("Vertical", 0.0f, 0.0f, 100.0f, v -> mode.getValue() == modeEn.Custom);
39
    private final Setting<jumpModeEn> jumpMode = new Setting<>("JumpMode", jumpModeEn.Jump, v -> mode.getValue() == modeEn.Jump);
40
    public Setting<Float> horizontal = new Setting<>("Horizontal", 0.0f, 0.0f, 100.0f, v -> mode.getValue() == modeEn.Custom || mode.getValue() == modeEn.Jump);
41
    public Setting<Float> motion = new Setting<>("Motion", .42f, 0.4f, 0.5f, v -> mode.getValue() == modeEn.Jump);
42
    public Setting<Boolean> fail = new Setting<>("SmartFail", true, v -> mode.getValue() == modeEn.Jump);
43
    public Setting<Float> failRate = new Setting<>("FailRate", 0.3f, 0.0f, 1.0f, v -> mode.getValue() == modeEn.Jump && fail.getValue());
44
    public Setting<Float> jumpRate = new Setting<>("FailJumpRate", 0.25f, 0.0f, 1.0f, v -> mode.getValue() == modeEn.Jump && fail.getValue());
45
46
    private boolean doJump, failJump, skip, flag;
47
    private int grimTicks, ccCooldown;
48
49
50
    @EventHandler
51
    public void onPacketReceive(PacketEvent.Receive e) {
52
        if (fullNullCheck()) return;
53
54
        if (mc.player != null && (mc.player.isInWater() || mc.player.isUnderWater() || mc.player.isInLava()) && pauseInWater.getValue())
55
            return;
56
57
        if (mc.player != null && mc.player.isOnFire() && fire.getValue() && (mc.player.hurtTime > 0)) {
58
            return;
59
        }
60
61
        if (ccCooldown > 0) {
62
            ccCooldown--;
63
            return;
64
        }
65
66
        // MAIN VELOCITY
67
        if (e.getPacket() instanceof ClientboundSetEntityMotionPacket pac) {
68
            if (pac.id() == mc.player.getId() && (!onlyAura.getValue() || ModuleManager.aura.isEnabled())) {
69
                switch (mode.getValue()) {
70
                    case Matrix -> {
71
                        if (!flag) {
72
                            e.cancel();
73
                            flag = true;
74
                        } else {
75
                            flag = false;
76
                            ((ISPacketEntityVelocity) (Object) pac).setMotionX(pac.movement().x * -0.1);
77
                            ((ISPacketEntityVelocity) (Object) pac).setMotionZ(pac.movement().z * -0.1);
78
                        }
79
                    }
80
                    case Redirect -> {
81
                        double vX = Math.abs(pac.movement().x);
82
                        double vZ = Math.abs(pac.movement().z);
83
                        double[] motion = MovementUtility.forward(vX + vZ);
84
                        ((ISPacketEntityVelocity) (Object) pac).setMotionX(motion[0]);
85
                        ((ISPacketEntityVelocity) (Object) pac).setMotionY(0);
86
                        ((ISPacketEntityVelocity) (Object) pac).setMotionZ(motion[1]);
87
                    }
88
                    case Custom -> {
89
                        ((ISPacketEntityVelocity) (Object) pac).setMotionX(pac.movement().x * horizontal.getValue() / 100f);
90
                        ((ISPacketEntityVelocity) (Object) pac).setMotionY(pac.movement().y * vertical.getValue() / 100f);
91
                        ((ISPacketEntityVelocity) (Object) pac).setMotionZ(pac.movement().z * horizontal.getValue() / 100f);
92
                    }
93
                    case Sunrise -> {
94
                        e.cancel();
95
                        sendPacket(new ServerboundMovePlayerPacket.Pos(mc.player.getX(), -999.0, mc.player.getZ(), true, mc.player.horizontalCollision));
96
                    }
97
                    case Cancel -> e.cancel();
98
                    case Jump -> {
99
                        ((ISPacketEntityVelocity) (Object) pac).setMotionX(pac.movement().x * horizontal.getValue() / 100f);
100
                        ((ISPacketEntityVelocity) (Object) pac).setMotionZ(pac.movement().z * horizontal.getValue() / 100f);
101
                    }
102
                    case OldGrim -> {
103
                        e.cancel();
104
                        grimTicks = 6;
105
                    }
106
                    case GrimNew -> {
107
                        e.cancel();
108
                        flag = true;
109
                    }
110
                }
111
            }
112
        }
113
114
        // EXPLOSION
115
        if (e.getPacket() instanceof ClientboundExplodePacket explosion && explosions.getValue()) {
116
            Optional<Vec3> knockback = ((IExplosionS2CPacket) (Object) explosion).getPlayerKnockback();
117
            if (knockback.isEmpty()) {
118
                return;
119
            }
120
            Vec3 playerKnockback = knockback.get();
121
            switch (mode.getValue()) {
122
                case Cancel -> {
123
                    ((IExplosionS2CPacket) (Object) explosion).setPlayerKnockback(Optional.of(Vec3.ZERO));
124
                }
125
                case Custom -> {
126
                    Vec3 scaled = new Vec3(
127
                        playerKnockback.x * horizontal.getValue() / 100f,
128
                        playerKnockback.y * vertical.getValue() / 100f,
129
                        playerKnockback.z * horizontal.getValue() / 100f
130
                    );
131
                    ((IExplosionS2CPacket) (Object) explosion).setPlayerKnockback(Optional.of(scaled));
132
                }
133
                case GrimNew -> {
134
                    ((IExplosionS2CPacket) (Object) explosion).setPlayerKnockback(Optional.of(Vec3.ZERO));
135
                    flag = true;
136
                }
137
            }
138
        }
139
140
        // PING
141
        if (mode.getValue() == modeEn.OldGrim) {
142
            if (e.getPacket() instanceof ClientboundPingPacket && grimTicks > 0) {
143
                e.cancel();
144
                grimTicks--;
145
            }
146
        }
147
148
        // LAGBACK
149
        if (e.getPacket() instanceof ClientboundPlayerPositionPacket) {
150
            if (cc.getValue() || mode.getValue() == modeEn.GrimNew)
151
                ccCooldown = 5;
152
        }
153
    }
154
155
156
    @Override
157
    public void onUpdate() {
158
        if (mc.player != null && (mc.player.isInWater() || mc.player.isUnderWater()) && pauseInWater.getValue())
159
            return;
160
161
        switch (mode.getValue()) {
162
            case Matrix -> {
163
                if (mc.player.hurtTime > 0 && !mc.player.onGround()) {
164
                    double var3 = mc.player.getYRot() * 0.017453292F;
165
                    double var5 = Math.sqrt(mc.player.getDeltaMovement().x * mc.player.getDeltaMovement().x + mc.player.getDeltaMovement().z * mc.player.getDeltaMovement().z);
166
                    mc.player.setDeltaMovement(-Math.sin(var3) * var5, mc.player.getDeltaMovement().y, Math.cos(var3) * var5);
167
                    mc.player.setSprinting(mc.player.tickCount % 2 != 0);
168
                }
169
            }
170
            case Jump -> {
171
                if ((failJump || mc.player.hurtTime > 6) && mc.player.onGround()) {
172
                    if (failJump) failJump = false;
173
                    if (!doJump) skip = true;
174
                    if (Math.random() <= failRate.getValue() && fail.getValue()) {
175
                        if (Math.random() <= jumpRate.getValue()) {
176
                            doJump = true;
177
                            failJump = true;
178
                        } else {
179
                            doJump = false;
180
                            failJump = false;
181
                        }
182
                    } else {
183
                        doJump = true;
184
                        failJump = false;
185
                    }
186
                    if (skip) {
187
                        skip = false;
188
                        return;
189
                    }
190
                    switch (jumpMode.getValue()) {
191
                        case Jump -> mc.player.jumpFromGround();
192
                        case Motion ->
193
                                mc.player.setDeltaMovement(mc.player.getDeltaMovement().x(), motion.getValue(), mc.player.getDeltaMovement().z());
194
                        case Both -> {
195
                            mc.player.jumpFromGround();
196
                            mc.player.setDeltaMovement(mc.player.getDeltaMovement().x(), motion.getValue(), mc.player.getDeltaMovement().z());
197
                        }
198
                    }
199
                }
200
            }
201
            case GrimNew -> {
202
                if (flag) {
203
                    if (ccCooldown <= 0) {
204
                        sendPacket(new ServerboundMovePlayerPacket.PosRot(mc.player.getX(), mc.player.getY(), mc.player.getZ(), ((IEntity) mc.player).getLastYaw(), ((IEntity) mc.player).getLastPitch(), mc.player.onGround(), mc.player.horizontalCollision));
205
                        sendPacket(new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, BlockPos.containing(mc.player.position()), Direction.DOWN));
206
                    }
207
                    flag = false;
208
                }
209
            }
210
        }
211
        if (grimTicks > 0)
212
            grimTicks--;
213
    }
214
215
    private boolean isValidMotion(double motion, double min, double max) {
216
        return Math.abs(motion) > min && Math.abs(motion) < max;
217
    }
218
219
    @Override
220
    public void onEnable() {
221
        grimTicks = 0;
222
    }
223
224
    public enum modeEn {
225
        Matrix, Cancel, Sunrise, Custom, Redirect, OldGrim, Jump, GrimNew
226
    }
227
228
    public enum jumpModeEn {
229
        Motion, Jump, Both
230
    }
231
}
232
CombatantMOVEMENTsrc/main/java/combatant/client/features/module/modules/movement/Velocity.javaJava · 1,080 lines · 45.9 KB
SettingsvelocityModevelocityDelayvelocityPauseOnFlagvelocityModifyHorizontalvelocityModifyVerticalvelocityModifyMotionHorizontalvelocityModifyMotionVerticalvelocityModifyChancevelocityModifyFiltervelocityModifyOnlyMovevelocityModifyTransactionBuffervelocityReversalDelayvelocityReversalXModifiervelocityReversalZModifiervelocityReversalOnlyMovingvelocityStrafeDelayvelocityStrafeStrengthvelocityStrafeUntilGroundvelocityJumpResetChancevelocityJumpResetByHitsvelocityJumpResetHitsvelocityJumpResetByDelayvelocityJumpResetTicksvelocityLagTimevelocityLagJumpResetvelocityDexlandHReducevelocityDexlandAttacksToWorkvelocityGrim2344AlternativeBypassvelocityAACReducevelocityIntaveReduceOnAttackvelocityIntaveReduceFactorvelocityIntaveHurtTimeMinvelocityIntaveHurtTimeMaxvelocityIntaveLastAttackTimevelocityIntaveJumpResetvelocityIntaveJumpChancevelocityIntaveRandomizevelocityIntaveRandomDelayTicksvelocityVulcan297ExemptRatiovelocityVulcan297Exempts
Velocity.javaJava · Minecraft 26.2 · 1,080 lines · 45.9 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Combatant modifications copyright (c) 2026 pivosos2007.
4
 *
5
 * Portions of this file are based on LiquidBounce
6
 * (https://github.com/CCBlueX/LiquidBounce).
7
 * Copyright (c) 2015-2026 CCBlueX.
8
 *
9
 * LiquidBounce portions are licensed under GPLv3-or-later.
10
 * Combatant modifications are licensed under GPLv3.
11
 * See THIRD_PARTY_NOTICES.md for details.
12
 */
13
14
package combatant.client.features.module.modules.movement;
15
16
import combatant.client.events.impl.*;
17
import combatant.client.util.screen.ClientScreen;
18
import lombok.Getter;
19
import lombok.RequiredArgsConstructor;
20
import net.minecraft.client.Minecraft;
21
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
22
import net.minecraft.client.player.LocalPlayer;
23
import net.minecraft.core.BlockPos;
24
import net.minecraft.core.Direction;
25
import net.minecraft.core.Holder;
26
import net.minecraft.core.Registry;
27
import net.minecraft.core.registries.Registries;
28
import net.minecraft.network.Connection;
29
import net.minecraft.network.PacketListener;
30
import net.minecraft.network.protocol.Packet;
31
import net.minecraft.network.protocol.common.ClientboundPingPacket;
32
import net.minecraft.network.protocol.common.ServerboundPongPacket;
33
import net.minecraft.network.protocol.game.*;
34
import net.minecraft.resources.ResourceKey;
35
import net.minecraft.util.Mth;
36
import net.minecraft.world.InteractionHand;
37
import net.minecraft.world.InteractionResult;
38
import net.minecraft.world.effect.MobEffects;
39
import net.minecraft.world.entity.EquipmentSlot;
40
import net.minecraft.world.entity.player.Input;
41
import net.minecraft.world.item.ItemStack;
42
import net.minecraft.world.item.Items;
43
import net.minecraft.world.item.enchantment.Enchantment;
44
import net.minecraft.world.item.enchantment.EnchantmentHelper;
45
import net.minecraft.world.item.enchantment.Enchantments;
46
import net.minecraft.world.level.ClipContext;
47
import net.minecraft.world.level.block.*;
48
import net.minecraft.world.phys.BlockHitResult;
49
import net.minecraft.world.phys.HitResult;
50
import net.minecraft.world.phys.Vec3;
51
import combatant.client.config.common.CommonSettingSchemas;
52
import combatant.client.config.values.BooleanMapValue;
53
import combatant.client.config.values.BooleanValue;
54
import combatant.client.config.values.EnumValue;
55
import combatant.client.config.values.NumberValue;
56
import combatant.client.events.EventHandler;
57
import combatant.client.events.Events;
58
import combatant.client.events.impl.*;
59
import combatant.client.features.module.Module;
60
import combatant.client.features.module.ModuleCategory;
61
import combatant.client.features.module.ModuleInfo;
62
import combatant.client.mixins.accessors.ClientboundExplodePacketAccessor;
63
import combatant.client.mixins.accessors.ClientboundSetEntityMotionPacketAccessor;
64
import combatant.client.util.aiming.RotationManager;
65
import combatant.client.util.aiming.data.Rotation;
66
import combatant.client.util.network.BlinkManager;
67
import combatant.client.util.network.TransferOrigin;
68
import combatant.client.util.player.MovementUtil;
69
70
import java.util.*;
71
import java.util.concurrent.ThreadLocalRandom;
72
73
/**
74
 * Velocity modes ported from LiquidBounce's ModuleVelocity.
75
 */
76
//todo Description
77
@ModuleInfo(
78
        id = "velocity",
79
        displayName = "Velocity",
80
        category = ModuleCategory.MOVEMENT
81
)
82
public final class Velocity extends Module {
83
84
    private static final double VULCAN_297_SAFE_HORIZONTAL_RATIO = 0.25;
85
    private static final double VULCAN_297_TINY_HORIZONTAL = 0.01;
86
    private static final double VULCAN_297_JUMP_LIKE_VERTICAL = 0.41999998688697815;
87
    private static final double VULCAN_297_PROTECTED_VERTICAL = 0.6;
88
    private static final int VULCAN_297_WIND_BURST_PENDING_TICKS = 8;
89
    private static final int VULCAN_297_WIND_BURST_PROTECT_TICKS = 12;
90
    private static final String VULCAN_EXEMPT_LIQUID = "liquid";
91
    private static final String VULCAN_EXEMPT_FROZEN = "frozen";
92
    private static final String VULCAN_EXEMPT_FALL_DAMAGE = "fall_damage";
93
    private static final String VULCAN_EXEMPT_WEB = "web";
94
    private static final String VULCAN_EXEMPT_VOID = "void";
95
    private static final String VULCAN_EXEMPT_SLOW_FALLING = "slow_falling";
96
    private static final String VULCAN_EXEMPT_TRAPDOOR = "trapdoor";
97
    private static final String VULCAN_EXEMPT_SOUL_SAND = "soul_sand";
98
    private static final String VULCAN_EXEMPT_SLIME = "slime";
99
    private static final String VULCAN_EXEMPT_FLIGHT = "flight";
100
    private static final String VULCAN_EXEMPT_VEHICLE = "vehicle";
101
    private static final String VULCAN_EXEMPT_ELYTRA = "elytra";
102
    private static final String VULCAN_EXEMPT_FENCE = "fence";
103
    private static final String VULCAN_EXEMPT_WALL = "wall";
104
    private static final String VULCAN_EXEMPT_SWEET_BERRIES = "sweet_berries";
105
    private static final String VULCAN_EXEMPT_NETHERITE_ARMOR = "netherite_armor";
106
    private final Minecraft mc = Minecraft.getInstance();
107
    private final EnumValue<Mode> mode =
108
            enumCommon("velocityMode", "velocity_mode", CommonSettingSchemas.ANTICHEAT_MODE, Mode.MODIFY, Mode.values());
109
    private final NumberValue<Integer> delay = visibleWhen(num("velocityDelay", "delay", 0, 0, 40), this::supportsIncomingVelocity);
110
    private final NumberValue<Integer> pauseOnFlag = num("velocityPauseOnFlag", "pause_on_flag", 0, 0, 20);
111
    private final NumberValue<Float> modifyHorizontal = visibleWhen(num("velocityModifyHorizontal", "modify_horizontal", 0.0f, -1.0f, 1.0f), () -> mode.get() == Mode.MODIFY);
112
    private final NumberValue<Float> modifyVertical = visibleWhen(num("velocityModifyVertical", "modify_vertical", 0.0f, -1.0f, 1.0f), () -> mode.get() == Mode.MODIFY);
113
    private final NumberValue<Float> modifyMotionHorizontal = visibleWhen(num("velocityModifyMotionHorizontal", "modify_motion_horizontal", 0.0f, 0.0f, 1.0f), () -> mode.get() == Mode.MODIFY);
114
    private final NumberValue<Float> modifyMotionVertical = visibleWhen(num("velocityModifyMotionVertical", "modify_motion_vertical", 0.0f, 0.0f, 1.0f), () -> mode.get() == Mode.MODIFY);
115
    private final NumberValue<Integer> modifyChance = visibleWhen(num("velocityModifyChance", "modify_chance", 100, 0, 100), () -> mode.get() == Mode.MODIFY);
116
    private final EnumValue<Filter> modifyFilter = visibleWhen(enumSetting("velocityModifyFilter", "modify_filter", Filter.ALWAYS, Filter.values()), () -> mode.get() == Mode.MODIFY);
117
    private final BooleanValue modifyOnlyMove = visibleWhen(bool("velocityModifyOnlyMove", "modify_only_move", false), () -> mode.get() == Mode.MODIFY);
118
    private final NumberValue<Integer> modifyTransactionBuffer = visibleWhen(num("velocityModifyTransactionBuffer", "modify_transaction_buffer", 0, 0, 3), () -> mode.get() == Mode.MODIFY);
119
    private final NumberValue<Integer> reversalDelay = visibleWhen(num("velocityReversalDelay", "reversal_delay", 2, 1, 5), () -> mode.get() == Mode.REVERSAL);
120
    private final NumberValue<Float> reversalXModifier = visibleWhen(num("velocityReversalXModifier", "reversal_x_modifier", 0.5f, 0.0f, 1.0f), () -> mode.get() == Mode.REVERSAL);
121
    private final NumberValue<Float> reversalZModifier = visibleWhen(num("velocityReversalZModifier", "reversal_z_modifier", 0.5f, 0.0f, 1.0f), () -> mode.get() == Mode.REVERSAL);
122
    private final BooleanValue reversalOnlyMoving = visibleWhen(bool("velocityReversalOnlyMoving", "reversal_only_moving", false), () -> mode.get() == Mode.REVERSAL);
123
    private final NumberValue<Integer> strafeDelay = visibleWhen(num("velocityStrafeDelay", "strafe_delay", 2, 0, 10), () -> mode.get() == Mode.STRAFE);
124
    private final NumberValue<Float> strafeStrength = visibleWhen(num("velocityStrafeStrength", "strafe_strength", 1.0f, 0.1f, 2.0f), () -> mode.get() == Mode.STRAFE);
125
    private final BooleanValue strafeUntilGround = visibleWhen(bool("velocityStrafeUntilGround", "strafe_until_ground", false), () -> mode.get() == Mode.STRAFE);
126
    private final NumberValue<Float> jumpResetChance = visibleWhen(num("velocityJumpResetChance", "jump_reset_chance", 100.0f, 0.0f, 100.0f), () -> mode.get() == Mode.JUMP_RESET);
127
    private final BooleanValue jumpResetByHits = visibleWhen(bool("velocityJumpResetByHits", "jump_reset_by_hits", false), () -> mode.get() == Mode.JUMP_RESET);
128
    private final NumberValue<Integer> jumpResetHits = visibleWhen(num("velocityJumpResetHits", "jump_reset_hits", 2, 0, 10), () -> mode.get() == Mode.JUMP_RESET);
129
    private final BooleanValue jumpResetByDelay = visibleWhen(bool("velocityJumpResetByDelay", "jump_reset_by_delay", true), () -> mode.get() == Mode.JUMP_RESET);
130
    private final NumberValue<Integer> jumpResetTicks = visibleWhen(num("velocityJumpResetTicks", "jump_reset_ticks", 2, 0, 20), () -> mode.get() == Mode.JUMP_RESET);
131
    private final NumberValue<Integer> lagTime = visibleWhen(num("velocityLagTime", "lag_time", 5, 1, 20), () -> mode.get() == Mode.LAG);
132
    private final BooleanValue lagJumpReset = visibleWhen(bool("velocityLagJumpReset", "lag_jump_reset", false), () -> mode.get() == Mode.LAG);
133
    private final NumberValue<Float> dexlandHReduce = visibleWhen(num("velocityDexlandHReduce", "dexland_h_reduce", 0.3f, 0.0f, 1.0f), () -> mode.get() == Mode.DEXLAND);
134
    private final NumberValue<Integer> dexlandAttacksToWork = visibleWhen(num("velocityDexlandAttacksToWork", "dexland_attacks_to_work", 4, 1, 10), () -> mode.get() == Mode.DEXLAND);
135
    private final BooleanValue grim2344AlternativeBypass = visibleWhen(bool("velocityGrim2344AlternativeBypass", "grim2344_alternative_bypass", true), () -> mode.get() == Mode.GRIM_2344);
136
    private final NumberValue<Float> aacReduce = visibleWhen(num("velocityAACReduce", "aac_reduce", 0.62f, 0.0f, 1.0f), () -> mode.get() == Mode.AAC_442);
137
    private final BooleanValue intaveReduceOnAttack = visibleWhen(bool("velocityIntaveReduceOnAttack", "intave_reduce_on_attack", true), () -> mode.get() == Mode.INTAVE);
138
    private final NumberValue<Float> intaveReduceFactor = visibleWhen(num("velocityIntaveReduceFactor", "intave_reduce_factor", 0.6f, 0.6f, 1.0f), () -> mode.get() == Mode.INTAVE);
139
    private final NumberValue<Integer> intaveHurtTimeMin = visibleWhen(num("velocityIntaveHurtTimeMin", "intave_hurt_time_min", 5, 1, 10), () -> mode.get() == Mode.INTAVE);
140
    private final NumberValue<Integer> intaveHurtTimeMax = visibleWhen(num("velocityIntaveHurtTimeMax", "intave_hurt_time_max", 7, 1, 10), () -> mode.get() == Mode.INTAVE);
141
    private final NumberValue<Integer> intaveLastAttackTime = visibleWhen(num("velocityIntaveLastAttackTime", "intave_last_attack_time", 2000, 1, 10000), () -> mode.get() == Mode.INTAVE);
142
    private final BooleanValue intaveJumpReset = visibleWhen(bool("velocityIntaveJumpReset", "intave_jump_reset", true), () -> mode.get() == Mode.INTAVE);
143
    private final NumberValue<Float> intaveJumpChance = visibleWhen(num("velocityIntaveJumpChance", "intave_jump_chance", 50.0f, 0.0f, 100.0f), () -> mode.get() == Mode.INTAVE);
144
    private final BooleanValue intaveRandomize = visibleWhen(bool("velocityIntaveRandomize", "intave_randomize", false), () -> mode.get() == Mode.INTAVE);
145
    private final NumberValue<Integer> intaveRandomDelayTicks = visibleWhen(num("velocityIntaveRandomDelayTicks", "intave_random_delay_ticks", 5, 0, 10), () -> mode.get() == Mode.INTAVE);
146
    private final NumberValue<Float> vulcan297ExemptRatio = visibleWhen(num("velocityVulcan297ExemptRatio", "vulcan297_exempt_ratio", 0.0f, 0.0f, 1.0f), this::isVulcan297Mode);
147
    private final BooleanMapValue vulcan297Exempts = visibleWhen(group("velocityVulcan297Exempts", "vulcan297_exempts", vulcan297ExemptDefaults()), this::isVulcan297Mode);
148
    private final Queue<DelayedPacket> delayedPackets = new ArrayDeque<>();
149
    private int pause;
150
    private int transactionBuffer;
151
    private boolean reversalHandlingVelocity;
152
    private int reversalVelocityTicks;
153
    private int strafeTicks = -1;
154
    private boolean strafeApplyUntilGround;
155
    private int jumpLimitUntilJump;
156
    private boolean jumpResetFallDamage;
157
    private boolean lagShouldLag;
158
    private int lagTicks;
159
    private int lagShouldJumpTicks;
160
    private boolean hypixelAbsorbedVelocity;
161
    private long dexlandLastAttackTime;
162
    private int dexlandCount;
163
    private boolean grim2371CancelNextVelocity;
164
    private boolean grim2371Delay;
165
    private boolean grim2371NeedClick;
166
    private boolean grim2371WaitForPing;
167
    private boolean grim2371WaitForUpdate;
168
    private boolean grim2371ShouldSkip;
169
    private BlockHitResult grim2371HitResult;
170
    private int grim2371FreezeTicks;
171
    private boolean grim2344CanCancel;
172
    private long intaveLastAttack;
173
    private boolean intaveFallDamage;
174
    private int intaveCurrentDelay;
175
    private int intaveDelayCounter;
176
    private int vulcan297WindBurstPendingTicks;
177
    private int vulcan297WindBurstProtectTicks;
178
179
    private static Map<String, Boolean> vulcan297ExemptDefaults() {
180
        Map<String, Boolean> defaults = new LinkedHashMap<>();
181
        defaults.put(VULCAN_EXEMPT_LIQUID, true);
182
        defaults.put(VULCAN_EXEMPT_FROZEN, true);
183
        defaults.put(VULCAN_EXEMPT_FALL_DAMAGE, true);
184
        defaults.put(VULCAN_EXEMPT_WEB, true);
185
        defaults.put(VULCAN_EXEMPT_VOID, true);
186
        defaults.put(VULCAN_EXEMPT_SLOW_FALLING, true);
187
        defaults.put(VULCAN_EXEMPT_TRAPDOOR, true);
188
        defaults.put(VULCAN_EXEMPT_SOUL_SAND, true);
189
        defaults.put(VULCAN_EXEMPT_SLIME, true);
190
        defaults.put(VULCAN_EXEMPT_FLIGHT, true);
191
        defaults.put(VULCAN_EXEMPT_VEHICLE, true);
192
        defaults.put(VULCAN_EXEMPT_ELYTRA, true);
193
        defaults.put(VULCAN_EXEMPT_FENCE, true);
194
        defaults.put(VULCAN_EXEMPT_WALL, true);
195
        defaults.put(VULCAN_EXEMPT_SWEET_BERRIES, true);
196
        defaults.put(VULCAN_EXEMPT_NETHERITE_ARMOR, true);
197
        return defaults;
198
    }
199
200
    @Override
201
    public void onEnable() {
202
        resetState();
203
    }
204
205
    @Override
206
    public void onDisable() {
207
        BlinkManager.INSTANCE.flush(TransferOrigin.INCOMING);
208
        resetState();
209
    }
210
211
    @EventHandler(priority = 2)
212
    private void onPacket(PacketEvent event) {
213
        if (!isEnabled() || player() == null) return;
214
215
        Packet<?> packet = event.getPacket();
216
        if (event.isOriginal()) {
217
            if (packet instanceof ClientboundPlayerPositionPacket) {
218
                pause = pauseOnFlag.get();
219
                return;
220
            }
221
            if (pause > 0) return;
222
            if (event.getOrigin() == TransferOrigin.INCOMING
223
                    && supportsIncomingVelocity()
224
                    && isLocalPlayerVelocity(packet)
225
                    && delay.get() > 0) {
226
                event.cancel();
227
                delayedPackets.add(new DelayedPacket(packet, delay.get()));
228
                return;
229
            }
230
        }
231
232
        switch (mode.get()) {
233
            case MODIFY -> handleModify(event, packet);
234
            case REVERSAL -> handleReversal(event, packet);
235
            case STRAFE -> handleStrafePacket(event, packet);
236
            case JUMP_RESET -> handleJumpResetPacket(packet);
237
            case LAG -> handleLagPacket(packet);
238
            case HYPIXEL -> handleHypixel(event, packet);
239
            case BLOCKSMC -> handleBlocksMc(event, packet);
240
            case GRIM_2371 -> handleGrim2371Packet(event, packet);
241
            case GRIM_2344 -> handleGrim2344(event, packet);
242
            case INTAVE -> handleIntavePacket(packet);
243
            case VULCAN_297 -> handleVulcan297(event, packet);
244
            default -> {
245
            }
246
        }
247
248
    }
249
250
    @EventHandler
251
    private void onBlinkPacket(BlinkPacketEvent event) {
252
        if (!isEnabled() || player() == null) return;
253
254
        if (mode.get() == Mode.LAG
255
                && lagShouldLag
256
                && event.getOrigin() == TransferOrigin.INCOMING
257
                && !(event.getPacket() instanceof ClientboundPingPacket)) {
258
            event.setAction(BlinkManager.Action.QUEUE);
259
            return;
260
        }
261
262
        if (mode.get() == Mode.GRIM_2371
263
                && !grim2371WaitForUpdate
264
                && grim2371Delay
265
                && event.getOrigin() == TransferOrigin.INCOMING) {
266
            event.setAction(BlinkManager.Action.QUEUE);
267
        }
268
    }
269
270
    @EventHandler
271
    private void onTick(GameTickEvent event) {
272
        if (!isEnabled()) return;
273
274
        if (pause > 0) pause--;
275
        processDelayedPackets();
276
277
        LocalPlayer player = player();
278
        if (player == null) return;
279
280
        switch (mode.get()) {
281
            case REVERSAL -> tickReversal(player);
282
            case STRAFE -> tickStrafe(player);
283
            case LAG -> tickLag(player);
284
            case HYPIXEL -> {
285
                if (player.onGround()) hypixelAbsorbedVelocity = false;
286
            }
287
            case HYLEX -> tickHylex(player);
288
            case GRIM_2371 -> tickGrim2371(player);
289
            case AAC_442 -> {
290
                if (player.hurtTime > 0 && !player.onGround()) {
291
                    multiplyHorizontal(player, aacReduce.get());
292
                }
293
            }
294
            default -> {
295
            }
296
        }
297
298
        if (vulcan297WindBurstProtectTicks > 0) {
299
            vulcan297WindBurstProtectTicks--;
300
        }
301
        if (vulcan297WindBurstPendingTicks > 0) {
302
            vulcan297WindBurstPendingTicks--;
303
        }
304
    }
305
306
    @EventHandler
307
    private void onMovementInput(MovementInputEvent event) {
308
        if (!isEnabled() || player() == null) return;
309
310
        if (mode.get() == Mode.JUMP_RESET) {
311
            handleJumpResetInput(event, player());
312
        } else if (mode.get() == Mode.LAG) {
313
            if (lagJumpReset.get() && lagShouldJumpTicks > 0 && player().onGround() && player().isSprinting()) {
314
                event.setJump(true);
315
                lagShouldJumpTicks = 0;
316
            }
317
        } else if (mode.get() == Mode.INTAVE) {
318
            handleIntaveJumpReset(event, player());
319
        }
320
    }
321
322
    @EventHandler
323
    private void onMove(PlayerMoveEvent event) {
324
        if (!isEnabled() || mode.get() != Mode.STRAFE || !strafeApplyUntilGround || player() == null) return;
325
326
        if (player().onGround()) {
327
            strafeApplyUntilGround = false;
328
            return;
329
        }
330
331
        event.setMovement(withStrafe(event.getMovement(), strafeStrength.get()));
332
    }
333
334
    @EventHandler
335
    private void onAttack(AttackEntityEvent event) {
336
        if (!isEnabled() || player() == null) return;
337
338
        if (mode.get() == Mode.DEXLAND) {
339
            long now = System.currentTimeMillis();
340
            if (player().hurtTime > 0
341
                    && ++dexlandCount % dexlandAttacksToWork.get() == 0
342
                    && now - dexlandLastAttackTime <= 8000L) {
343
                multiplyHorizontal(player(), dexlandHReduce.get());
344
            }
345
            dexlandLastAttackTime = now;
346
        } else if (mode.get() == Mode.HYLEX) {
347
            handleHylexAttack(player());
348
        } else if (mode.get() == Mode.INTAVE && intaveReduceOnAttack.get()) {
349
            long now = System.currentTimeMillis();
350
            int min = Math.min(intaveHurtTimeMin.get(), intaveHurtTimeMax.get());
351
            int max = Math.max(intaveHurtTimeMin.get(), intaveHurtTimeMax.get());
352
            if (player().hurtTime >= min && player().hurtTime <= max && now - intaveLastAttack <= intaveLastAttackTime.get()) {
353
                multiplyHorizontal(player(), intaveReduceFactor.get());
354
            }
355
            intaveLastAttack = now;
356
        } else if (mode.get() == Mode.VULCAN_297 && isVulcan297WindBurstMaceAttack(event, player())) {
357
            armVulcan297MaceVelocityWindow();
358
        }
359
    }
360
361
    private void handleModify(PacketEvent event, Packet<?> packet) {
362
        if (packet instanceof ClientboundSetEntityMotionPacket velocity && velocity.id() == player().getId()) {
363
            if (!shouldModifyVelocity()) return;
364
365
            if (modifyHorizontal.get() == 0.0f && modifyVertical.get() == 0.0f) {
366
                event.cancel();
367
                return;
368
            }
369
370
            Vec3 packetVelocity = velocity.movement();
371
            Vec3 currentVelocity = player().getDeltaMovement();
372
            double x = modifyHorizontal.get() != 0.0f
373
                    ? packetVelocity.x * modifyHorizontal.get()
374
                    : currentVelocity.x * modifyMotionHorizontal.get();
375
            double y = modifyVertical.get() != 0.0f
376
                    ? packetVelocity.y * modifyVertical.get()
377
                    : currentVelocity.y * modifyMotionVertical.get();
378
            double z = modifyHorizontal.get() != 0.0f
379
                    ? packetVelocity.z * modifyHorizontal.get()
380
                    : currentVelocity.z * modifyMotionHorizontal.get();
381
            ((ClientboundSetEntityMotionPacketAccessor) (Object) velocity).combatant$setVelocity(new Vec3(x, y, z));
382
            transactionBuffer += modifyTransactionBuffer.get();
383
            return;
384
        }
385
386
        if (packet instanceof ClientboundExplodePacket explosion && explosion.playerKnockback().isPresent()) {
387
            if (!shouldModifyVelocity()) return;
388
389
            Vec3 knockback = explosion.playerKnockback().get();
390
            ((ClientboundExplodePacketAccessor) (Object) explosion).combatant$setPlayerKnockback(Optional.of(new Vec3(
391
                    knockback.x * modifyHorizontal.get(),
392
                    knockback.y * modifyVertical.get(),
393
                    knockback.z * modifyHorizontal.get()
394
            )));
395
            transactionBuffer += modifyTransactionBuffer.get();
396
            return;
397
        }
398
399
        if (packet instanceof ServerboundPongPacket && transactionBuffer > 0) {
400
            event.cancel();
401
            transactionBuffer--;
402
        }
403
    }
404
405
    private boolean shouldModifyVelocity() {
406
        if (modifyChance.get() != 100 && ThreadLocalRandom.current().nextInt(100) > modifyChance.get()) return false;
407
        if (modifyOnlyMove.get() && !isMoving()) return false;
408
409
        return switch (modifyFilter.get()) {
410
            case ALWAYS -> true;
411
            case ON_GROUND -> player().onGround();
412
            case IN_AIR -> !player().onGround();
413
        };
414
    }
415
416
    private void handleReversal(PacketEvent event, Packet<?> packet) {
417
        if (!isLocalPlayerVelocity(packet)) return;
418
        if (reversalOnlyMoving.get() && !isMoving()) return;
419
420
        reversalVelocityTicks = 0;
421
        reversalHandlingVelocity = true;
422
    }
423
424
    private void tickReversal(LocalPlayer player) {
425
        if (!reversalHandlingVelocity) return;
426
427
        Vec3 velocity = player.getDeltaMovement();
428
        if (velocity.lengthSqr() == 0.0) {
429
            reversalHandlingVelocity = false;
430
            reversalVelocityTicks = 0;
431
            return;
432
        }
433
434
        if (reversalVelocityTicks++ >= reversalDelay.get()) {
435
            player.setDeltaMovement(
436
                    velocity.x * -reversalXModifier.get(),
437
                    velocity.y,
438
                    velocity.z * -reversalZModifier.get()
439
            );
440
            reversalHandlingVelocity = false;
441
            reversalVelocityTicks = 0;
442
        }
443
    }
444
445
    private void handleStrafePacket(PacketEvent event, Packet<?> packet) {
446
        if (!isLocalPlayerVelocity(packet)) return;
447
448
        strafeTicks = strafeDelay.get();
449
        if (strafeTicks <= 0) {
450
            applyStrafe(player());
451
        }
452
    }
453
454
    private void tickStrafe(LocalPlayer player) {
455
        if (strafeTicks < 0) return;
456
457
        if (strafeTicks-- <= 0) {
458
            applyStrafe(player);
459
            strafeTicks = -1;
460
        }
461
    }
462
463
    private void applyStrafe(LocalPlayer player) {
464
        if (player == null) return;
465
466
        player.setDeltaMovement(withStrafe(player.getDeltaMovement(), strafeStrength.get()));
467
        if (strafeUntilGround.get()) {
468
            strafeApplyUntilGround = true;
469
        }
470
    }
471
472
    private Vec3 withStrafe(Vec3 currentVelocity, double strength) {
473
        return MovementUtil.withStrafe(
474
                currentVelocity,
475
                movementInput(),
476
                movementYaw(),
477
                horizontalSpeed(currentVelocity) * strength,
478
                1.0
479
        );
480
    }
481
482
    private void handleJumpResetPacket(Packet<?> packet) {
483
        if (packet instanceof ClientboundSetEntityMotionPacket(int id, Vec3 v) && id == player().getId()) {
484
            jumpResetFallDamage = v.x == 0.0 && v.z == 0.0 && v.y < 0.0;
485
        }
486
    }
487
488
    private void handleJumpResetInput(MovementInputEvent event, LocalPlayer player) {
489
        if (player.hurtTime != 9
490
                || !player.onGround()
491
                || !player.isSprinting()
492
                || jumpResetFallDamage
493
                || !jumpResetCooldownOver()
494
                || !rollChance(jumpResetChance.get())) {
495
            updateJumpResetLimit(player);
496
            return;
497
        }
498
499
        event.setJump(true);
500
        jumpLimitUntilJump = 0;
501
    }
502
503
    private boolean jumpResetCooldownOver() {
504
        if (jumpResetByHits.get()) return jumpLimitUntilJump >= jumpResetHits.get();
505
        if (jumpResetByDelay.get()) return jumpLimitUntilJump >= jumpResetTicks.get();
506
        return true;
507
    }
508
509
    private void updateJumpResetLimit(LocalPlayer player) {
510
        if (jumpResetByHits.get()) {
511
            if (player.hurtTime == 9) jumpLimitUntilJump++;
512
        } else {
513
            jumpLimitUntilJump++;
514
        }
515
    }
516
517
    private void handleLagPacket(Packet<?> packet) {
518
        if (packet instanceof ClientboundSetEntityMotionPacket velocity && velocity.id() == player().getId()) {
519
            lagShouldLag = true;
520
            lagTicks = lagTime.get();
521
        }
522
    }
523
524
    private void tickLag(LocalPlayer player) {
525
        if (lagShouldLag && --lagTicks <= 0) {
526
            lagShouldLag = false;
527
            lagTicks = 0;
528
            BlinkManager.INSTANCE.flush(TransferOrigin.INCOMING);
529
            lagShouldJumpTicks = 2;
530
        }
531
        if (lagShouldJumpTicks > 0) {
532
            lagShouldJumpTicks--;
533
        }
534
    }
535
536
    private void handleHypixel(PacketEvent event, Packet<?> packet) {
537
        if (!(packet instanceof ClientboundSetEntityMotionPacket velocity) || velocity.id() != player().getId()) return;
538
539
        if (!player().onGround() && !hypixelAbsorbedVelocity) {
540
            event.cancel();
541
            hypixelAbsorbedVelocity = true;
542
            return;
543
        }
544
545
        Vec3 current = player().getDeltaMovement();
546
        Vec3 packetVelocity = velocity.movement();
547
        ((ClientboundSetEntityMotionPacketAccessor) (Object) velocity).combatant$setVelocity(new Vec3(current.x, packetVelocity.y, current.z));
548
    }
549
550
    private void handleBlocksMc(PacketEvent event, Packet<?> packet) {
551
        if (!(packet instanceof ClientboundSetEntityMotionPacket velocity) || velocity.id() != player().getId()) return;
552
553
        event.cancel();
554
        sendSneaking(true);
555
        sendSneaking(false);
556
    }
557
558
    private void handleHylexAttack(LocalPlayer player) {
559
        if (!isMoving() || !player.isSprinting()) return;
560
561
        switch (player.hurtTime) {
562
            case 9 -> multiplyHorizontal(player, 0.8);
563
            case 8 -> multiplyHorizontal(player, 0.11);
564
            case 7 -> multiplyHorizontal(player, 0.4);
565
            case 4 -> multiplyHorizontal(player, 0.37);
566
            default -> {
567
            }
568
        }
569
    }
570
571
    private void tickHylex(LocalPlayer player) {
572
        if (player.hurtTime > 5 && player.onGround()) {
573
            player.jumpFromGround();
574
        }
575
    }
576
577
    private void handleGrim2371Packet(PacketEvent event, Packet<?> packet) {
578
        if (packet instanceof ServerboundInteractPacket || packet instanceof ServerboundUseItemOnPacket) {
579
            grim2371ShouldSkip = true;
580
        } else if (packet instanceof ServerboundMovePlayerPacket move && move.hasPosition() && grim2371WaitForUpdate) {
581
            event.cancel();
582
            return;
583
        } else if (packet instanceof ServerboundPongPacket && grim2371WaitForPing) {
584
            grim2371WaitForUpdate = false;
585
            grim2371WaitForPing = false;
586
        }
587
588
        if (packet instanceof ClientboundBlockUpdatePacket block
589
                && grim2371WaitForUpdate
590
                && block.getPos().equals(player().blockPosition())) {
591
            grim2371WaitForPing = true;
592
            grim2371NeedClick = false;
593
        }
594
595
        if (event.isCancelled() || grim2371WaitForUpdate || grim2371Delay) return;
596
597
        if (isLocalPlayerDamage(packet)) {
598
            grim2371CancelNextVelocity = true;
599
        } else if (grim2371CancelNextVelocity && isLocalPlayerVelocity(packet)) {
600
            event.cancel();
601
            grim2371Delay = true;
602
            grim2371CancelNextVelocity = false;
603
            grim2371NeedClick = true;
604
        }
605
    }
606
607
    private void tickGrim2371(LocalPlayer player) {
608
        if (grim2371NeedClick && !grim2371ShouldSkip && !player.isUsingItem()) {
609
            grim2371HitResult = traceDownToPlayerBlock(player);
610
        }
611
612
        if (grim2371HitResult != null) {
613
            grim2371Delay = false;
614
            BlinkManager.INSTANCE.flush(TransferOrigin.INCOMING);
615
616
            if (mc.gameMode != null) {
617
                InteractionResult result = mc.gameMode.useItemOn(player, InteractionHand.MAIN_HAND, grim2371HitResult);
618
                if (result.consumesAction()) {
619
                    player.swing(InteractionHand.MAIN_HAND);
620
                }
621
            }
622
623
            sendGrim2371Rotation(player);
624
            grim2371FreezeTicks = 0;
625
            grim2371WaitForUpdate = true;
626
            grim2371HitResult = null;
627
            grim2371NeedClick = false;
628
        }
629
630
        if (grim2371WaitForUpdate && ++grim2371FreezeTicks > 20) {
631
            grim2371WaitForUpdate = false;
632
            grim2371WaitForPing = false;
633
            grim2371NeedClick = false;
634
        }
635
636
        grim2371ShouldSkip = false;
637
    }
638
639
    private void handleGrim2344(PacketEvent event, Packet<?> packet) {
640
        if (isLocalPlayerDamage(packet)) {
641
            grim2344CanCancel = true;
642
        }
643
644
        if (isLocalPlayerVelocity(packet) && grim2344CanCancel) {
645
            event.cancel();
646
            int repeats = grim2344AlternativeBypass.get() ? 4 : 1;
647
            for (int i = 0; i < repeats; i++) {
648
                sendFullMovePacket(player());
649
            }
650
            sendStopDestroyBlock(player());
651
            grim2344CanCancel = false;
652
        }
653
    }
654
655
    private void handleIntavePacket(Packet<?> packet) {
656
        if (packet instanceof ClientboundSetEntityMotionPacket(int id, Vec3 v) && id == player().getId()) {
657
            intaveFallDamage = v.x == 0.0 && v.z == 0.0 && v.y < 0.0;
658
        }
659
    }
660
661
    private void handleIntaveJumpReset(MovementInputEvent event, LocalPlayer player) {
662
        if (!intaveJumpReset.get()) return;
663
664
        boolean shouldJump = rollChance(intaveJumpChance.get()) && player.hurtTime > 5 && !intaveFallDamage;
665
        boolean canJump = player.onGround() && !(ClientScreen.current() instanceof InventoryScreen);
666
667
        if (intaveRandomize.get()) {
668
            intaveDelayCounter++;
669
            if (intaveDelayCounter >= intaveCurrentDelay) {
670
                if (shouldJump && canJump) event.setJump(true);
671
                intaveDelayCounter = 0;
672
                intaveCurrentDelay = ThreadLocalRandom.current().nextInt(intaveRandomDelayTicks.get() + 1);
673
            }
674
        } else if (shouldJump && canJump) {
675
            event.setJump(true);
676
        }
677
    }
678
679
    private void handleVulcan297(PacketEvent event, Packet<?> packet) {
680
        LocalPlayer player = player();
681
        if (player == null) return;
682
683
        if (event.getOrigin() == TransferOrigin.OUTGOING
684
                && packet instanceof ServerboundSwingPacket swing
685
                && isVulcan297MaceSwing(swing, player)) {
686
            armVulcan297MaceVelocityWindow();
687
            return;
688
        }
689
690
        if (packet instanceof ClientboundSetEntityMotionPacket velocity && velocity.id() == player.getId()) {
691
            if (vulcan297WindBurstProtectTicks > 0) {
692
                return;
693
            }
694
695
            Vec3 modified = getVulcan297Velocity(player, velocity.movement());
696
            if (isZeroVelocity(modified)) {
697
                event.cancel();
698
                return;
699
            }
700
701
            ((ClientboundSetEntityMotionPacketAccessor) (Object) velocity).combatant$setVelocity(modified);
702
            return;
703
        }
704
705
        if (packet instanceof ClientboundExplodePacket explosion && explosion.playerKnockback().isPresent()) {
706
            if (vulcan297WindBurstPendingTicks > 0) {
707
                vulcan297WindBurstPendingTicks = 0;
708
                vulcan297WindBurstProtectTicks = VULCAN_297_WIND_BURST_PROTECT_TICKS;
709
            }
710
        }
711
    }
712
713
    private void armVulcan297MaceVelocityWindow() {
714
        vulcan297WindBurstPendingTicks = Math.max(vulcan297WindBurstPendingTicks, VULCAN_297_WIND_BURST_PENDING_TICKS);
715
        vulcan297WindBurstProtectTicks = Math.max(vulcan297WindBurstProtectTicks, VULCAN_297_WIND_BURST_PROTECT_TICKS);
716
    }
717
718
    private boolean isVulcan297MaceSwing(ServerboundSwingPacket packet, LocalPlayer player) {
719
        return packet.getHand() == InteractionHand.MAIN_HAND && player.getMainHandItem().is(Items.MACE);
720
    }
721
722
    private boolean isVulcan297WindBurstMaceAttack(AttackEntityEvent event, LocalPlayer player) {
723
        if (event.getPlayer() != player || player.isFallFlying() || player.fallDistance < 1.5f) {
724
            return false;
725
        }
726
727
        ItemStack stack = player.getMainHandItem();
728
        return stack.is(Items.MACE) && getEnchantmentLevel(Enchantments.WIND_BURST, stack) > 0;
729
    }
730
731
    private int getEnchantmentLevel(ResourceKey<Enchantment> key, ItemStack stack) {
732
        Holder<Enchantment> entry = getEnchantmentEntry(key);
733
        return entry == null ? 0 : EnchantmentHelper.getItemEnchantmentLevel(entry, stack);
734
    }
735
736
    private Holder<Enchantment> getEnchantmentEntry(ResourceKey<Enchantment> key) {
737
        if (mc.level == null) return null;
738
        Registry<Enchantment> registry = mc.level.registryAccess().lookupOrThrow(Registries.ENCHANTMENT);
739
        Enchantment enchantment = registry.getValue(key);
740
        return enchantment != null ? registry.wrapAsHolder(enchantment) : null;
741
    }
742
743
    private Vec3 getVulcan297Velocity(LocalPlayer player, Vec3 velocity) {
744
        double horizontal = horizontalSpeed(velocity);
745
        boolean typeAExempt = isVulcan297TypeAExempt(player);
746
        boolean typeBExempt = isVulcan297TypeBExempt(player);
747
748
        if (!typeAExempt && shouldPreserveVulcan297EntityImpulse(velocity)) {
749
            return velocity;
750
        }
751
752
        double exemptRatio = vulcan297ExemptRatio.get();
753
        double horizontalFactor = typeBExempt ? exemptRatio : VULCAN_297_SAFE_HORIZONTAL_RATIO;
754
        double verticalFactor = typeAExempt ? exemptRatio : velocity.y > 0.0 ? 1.0 : 0.0;
755
756
        if (!typeBExempt && horizontal < VULCAN_297_TINY_HORIZONTAL && velocity.y <= VULCAN_297_JUMP_LIKE_VERTICAL) {
757
            horizontalFactor = 0.0;
758
        }
759
760
        return applyVulcan297Budget(velocity, horizontalFactor, verticalFactor);
761
    }
762
763
    private Vec3 applyVulcan297Budget(Vec3 velocity, double horizontalFactor, double verticalFactor) {
764
        return new Vec3(
765
                velocity.x * horizontalFactor,
766
                velocity.y * verticalFactor,
767
                velocity.z * horizontalFactor
768
        );
769
    }
770
771
    private boolean shouldPreserveVulcan297EntityImpulse(Vec3 velocity) {
772
        double horizontal = horizontalSpeed(velocity);
773
774
        if (velocity.y >= VULCAN_297_PROTECTED_VERTICAL) {
775
            return true;
776
        }
777
778
        return velocity.y > VULCAN_297_JUMP_LIKE_VERTICAL && horizontal >= VULCAN_297_SAFE_HORIZONTAL_RATIO;
779
    }
780
781
    private boolean isVulcan297TypeAExempt(LocalPlayer player) {
782
        return isVulcan297SharedExempt(player)
783
                || getVulcan297BlockExempt(player);
784
    }
785
786
    private boolean isVulcan297TypeBExempt(LocalPlayer player) {
787
        return isVulcan297SharedExempt(player)
788
                || getVulcan297BlockExempt(player)
789
                || vulcan297Exempts.get(VULCAN_EXEMPT_NETHERITE_ARMOR) && hasVulcan297NetheriteArmor(player);
790
    }
791
792
    private boolean isVulcan297SharedExempt(LocalPlayer player) {
793
        if (vulcan297Exempts.get(VULCAN_EXEMPT_VEHICLE) && player.isPassenger()) return true;
794
        if (vulcan297Exempts.get(VULCAN_EXEMPT_ELYTRA) && player.isFallFlying()) return true;
795
        if (vulcan297Exempts.get(VULCAN_EXEMPT_LIQUID) && (player.isInWater()
796
                || player.isUnderWater()
797
                || player.isInLava()
798
                || player.isSwimming())) {
799
            return true;
800
        }
801
        if (vulcan297Exempts.get(VULCAN_EXEMPT_FROZEN) && player.isFullyFrozen()) return true;
802
        if (vulcan297Exempts.get(VULCAN_EXEMPT_FLIGHT) && player.getAbilities().flying) return true;
803
        if (vulcan297Exempts.get(VULCAN_EXEMPT_FALL_DAMAGE) && player.fallDistance > 3.0f) return true;
804
        if (vulcan297Exempts.get(VULCAN_EXEMPT_VOID) && isBelowWorld(player)) return true;
805
        return vulcan297Exempts.get(VULCAN_EXEMPT_SLOW_FALLING) && player.hasEffect(MobEffects.SLOW_FALLING);
806
    }
807
808
    private boolean isBelowWorld(LocalPlayer player) {
809
        return mc.level != null && player.getY() < mc.level.getMinY();
810
    }
811
812
    private boolean getVulcan297BlockExempt(LocalPlayer player) {
813
        if (mc.level == null) {
814
            return false;
815
        }
816
817
        BlockPos feet = player.blockPosition();
818
        return isVulcan297ExemptBlock(mc.level.getBlockState(feet).getBlock())
819
                || isVulcan297ExemptBlock(mc.level.getBlockState(feet.below()).getBlock());
820
    }
821
822
    private boolean isVulcan297ExemptBlock(Block block) {
823
        return vulcan297Exempts.get(VULCAN_EXEMPT_WEB) && (block == Blocks.COBWEB || block == Blocks.POWDER_SNOW)
824
                || vulcan297Exempts.get(VULCAN_EXEMPT_SOUL_SAND) && block == Blocks.SOUL_SAND
825
                || vulcan297Exempts.get(VULCAN_EXEMPT_SLIME) && block == Blocks.SLIME_BLOCK
826
                || vulcan297Exempts.get(VULCAN_EXEMPT_SWEET_BERRIES) && block == Blocks.SWEET_BERRY_BUSH
827
                || vulcan297Exempts.get(VULCAN_EXEMPT_TRAPDOOR) && block instanceof TrapDoorBlock
828
                || vulcan297Exempts.get(VULCAN_EXEMPT_FENCE) && block instanceof FenceBlock
829
                || vulcan297Exempts.get(VULCAN_EXEMPT_WALL) && block instanceof WallBlock;
830
    }
831
832
    private boolean hasVulcan297NetheriteArmor(LocalPlayer player) {
833
        return isNetheriteArmor(player.getItemBySlot(EquipmentSlot.HEAD))
834
                || isNetheriteArmor(player.getItemBySlot(EquipmentSlot.CHEST))
835
                || isNetheriteArmor(player.getItemBySlot(EquipmentSlot.LEGS))
836
                || isNetheriteArmor(player.getItemBySlot(EquipmentSlot.FEET));
837
    }
838
839
    private boolean isNetheriteArmor(ItemStack stack) {
840
        return stack.is(Items.NETHERITE_HELMET)
841
                || stack.is(Items.NETHERITE_CHESTPLATE)
842
                || stack.is(Items.NETHERITE_LEGGINGS)
843
                || stack.is(Items.NETHERITE_BOOTS);
844
    }
845
846
    private boolean isZeroVelocity(Vec3 velocity) {
847
        return velocity.x == 0.0 && velocity.y == 0.0 && velocity.z == 0.0;
848
    }
849
850
    private void processDelayedPackets() {
851
        int size = delayedPackets.size();
852
        for (int i = 0; i < size; i++) {
853
            DelayedPacket delayed = delayedPackets.poll();
854
            if (delayed == null) continue;
855
856
            delayed.ticks--;
857
            if (delayed.ticks > 0) {
858
                delayedPackets.add(delayed);
859
                continue;
860
            }
861
862
            PacketEvent.Receive packetEvent = new PacketEvent.Receive(delayed.packet, false);
863
            Events.BUS.post(packetEvent);
864
            if (!packetEvent.isCancelled()) {
865
                handleIncomingPacket(delayed.packet);
866
            }
867
        }
868
    }
869
870
    @SuppressWarnings({"rawtypes", "unchecked"})
871
    private void handleIncomingPacket(Packet<?> packet) {
872
        Connection connection = mc.getConnection() != null ? mc.getConnection().getConnection() : null;
873
        PacketListener listener = connection != null ? connection.getPacketListener() : null;
874
        if (listener != null) {
875
            ((Packet) packet).handle(listener);
876
        }
877
    }
878
879
    private boolean supportsIncomingVelocity() {
880
        return mode.get() != Mode.DEXLAND
881
                && mode.get() != Mode.HYLEX
882
                && mode.get() != Mode.AAC_442
883
                && mode.get() != Mode.INTAVE
884
                && mode.get() != Mode.VULCAN_297;
885
    }
886
887
    private boolean isVulcan297Mode() {
888
        return mode.get() == Mode.VULCAN_297;
889
    }
890
891
    private boolean isLocalPlayerVelocity(Packet<?> packet) {
892
        LocalPlayer player = player();
893
        if (player == null) return false;
894
        if (packet instanceof ClientboundSetEntityMotionPacket velocity) {
895
            return velocity.id() == player.getId();
896
        }
897
        return packet instanceof ClientboundExplodePacket explosion && explosion.playerKnockback().isPresent();
898
    }
899
900
    private boolean isLocalPlayerDamage(Packet<?> packet) {
901
        return packet instanceof ClientboundDamageEventPacket damage && player() != null && damage.entityId() == player().getId();
902
    }
903
904
    private LocalPlayer player() {
905
        return mc.player;
906
    }
907
908
    private boolean isMoving() {
909
        return MovementUtil.isMoving();
910
    }
911
912
    private Vec3 movementInput() {
913
        if (player() == null || player().input == null) return Vec3.ZERO;
914
        var input = player().input.getMoveVector();
915
        return new Vec3(input.x, 0.0, input.y);
916
    }
917
918
    private float movementYaw() {
919
        Rotation rotation = RotationManager.INSTANCE.getMovementRotation();
920
        return rotation != null ? rotation.yaw() : player().getYRot();
921
    }
922
923
    private double horizontalSpeed(Vec3 velocity) {
924
        return Math.hypot(velocity.x, velocity.z);
925
    }
926
927
    private void multiplyHorizontal(LocalPlayer player, double factor) {
928
        Vec3 velocity = player.getDeltaMovement();
929
        player.setDeltaMovement(velocity.x * factor, velocity.y, velocity.z * factor);
930
    }
931
932
    private boolean rollChance(float chance) {
933
        return chance >= 100.0f || ThreadLocalRandom.current().nextDouble(100.0) < chance;
934
    }
935
936
    private void sendSneaking(boolean sneaking) {
937
        if (mc.getConnection() == null) return;
938
        Input input = player() != null && player().input != null
939
                ? player().input.keyPresses
940
                : new Input(false, false, false, false, false, false, false);
941
        mc.getConnection().send(new ServerboundPlayerInputPacket(new Input(
942
                input.forward(),
943
                input.backward(),
944
                input.left(),
945
                input.right(),
946
                input.jump(),
947
                sneaking,
948
                input.sprint()
949
        )));
950
    }
951
952
    private BlockHitResult traceDownToPlayerBlock(LocalPlayer player) {
953
        Rotation server = RotationManager.INSTANCE.getServerRotation();
954
        float yaw = server != null ? server.yaw() : player.getYRot();
955
        Vec3 start = player.getEyePosition();
956
        Vec3 end = start.add(Vec3.directionFromRotation(90.0f, yaw).scale(4.5));
957
        HitResult hit = player.level().clip(new ClipContext(
958
                start,
959
                end,
960
                ClipContext.Block.OUTLINE,
961
                ClipContext.Fluid.NONE,
962
                player
963
        ));
964
        if (!(hit instanceof BlockHitResult blockHit) || blockHit.getType() == HitResult.Type.MISS) return null;
965
966
        BlockPos playerBlock = player.blockPosition();
967
        return blockHit.getBlockPos().relative(blockHit.getDirection()).equals(playerBlock) ? blockHit : null;
968
    }
969
970
    private void sendGrim2371Rotation(LocalPlayer player) {
971
        if (mc.getConnection() == null) return;
972
        Rotation server = RotationManager.INSTANCE.getServerRotation();
973
        if (server == null || Mth.abs(server.pitch() - 90.0f) > 0.001f) {
974
            mc.getConnection().send(new ServerboundMovePlayerPacket.Rot(
975
                    player.getYRot(),
976
                    90.0f,
977
                    player.onGround(),
978
                    player.horizontalCollision
979
            ));
980
        } else {
981
            mc.getConnection().send(new ServerboundMovePlayerPacket.StatusOnly(
982
                    player.onGround(),
983
                    player.horizontalCollision
984
            ));
985
        }
986
    }
987
988
    private void sendFullMovePacket(LocalPlayer player) {
989
        if (mc.getConnection() == null || player == null) return;
990
        mc.getConnection().send(new ServerboundMovePlayerPacket.PosRot(
991
                player.getX(),
992
                player.getY(),
993
                player.getZ(),
994
                player.getYRot(),
995
                player.getXRot(),
996
                player.onGround(),
997
                player.horizontalCollision
998
        ));
999
    }
1000
1001
    private void sendStopDestroyBlock(LocalPlayer player) {
1002
        if (mc.getConnection() == null || player == null) return;
1003
        mc.getConnection().send(new ServerboundPlayerActionPacket(
1004
                ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK,
1005
                player.blockPosition(),
1006
                Direction.DOWN
1007
        ));
1008
    }
1009
1010
    private void resetState() {
1011
        delayedPackets.clear();
1012
        pause = 0;
1013
        transactionBuffer = 0;
1014
        reversalHandlingVelocity = false;
1015
        reversalVelocityTicks = 0;
1016
        strafeTicks = -1;
1017
        strafeApplyUntilGround = false;
1018
        jumpLimitUntilJump = 0;
1019
        jumpResetFallDamage = false;
1020
        lagShouldLag = false;
1021
        lagTicks = 0;
1022
        lagShouldJumpTicks = 0;
1023
        hypixelAbsorbedVelocity = false;
1024
        dexlandLastAttackTime = 0L;
1025
        dexlandCount = 0;
1026
        grim2371CancelNextVelocity = false;
1027
        grim2371Delay = false;
1028
        grim2371NeedClick = false;
1029
        grim2371WaitForPing = false;
1030
        grim2371WaitForUpdate = false;
1031
        grim2371ShouldSkip = false;
1032
        grim2371HitResult = null;
1033
        grim2371FreezeTicks = 0;
1034
        grim2344CanCancel = false;
1035
        intaveLastAttack = 0L;
1036
        intaveFallDamage = false;
1037
        intaveCurrentDelay = 0;
1038
        intaveDelayCounter = 0;
1039
        vulcan297WindBurstPendingTicks = 0;
1040
        vulcan297WindBurstProtectTicks = 0;
1041
    }
1042
1043
    @Getter
1044
    @RequiredArgsConstructor
1045
    public enum Mode implements EnumValue.IdProvider {
1046
        MODIFY("modify"),
1047
        REVERSAL("reversal"),
1048
        STRAFE("strafe"),
1049
        JUMP_RESET("jump_reset"),
1050
        LAG("lag"),
1051
        HYPIXEL("hypixel"),
1052
        DEXLAND("dexland"),
1053
        HYLEX("hylex"),
1054
        BLOCKSMC("blocksmc"),
1055
        GRIM_2371("grim_2371"),
1056
        GRIM_2344("grim_2344_117"),
1057
        AAC_442("aac_4_4_2"),
1058
        INTAVE("intave"),
1059
        VULCAN_297("vulcan_297");
1060
1061
        private final String id;
1062
    }
1063
1064
    private enum Filter {
1065
        ALWAYS,
1066
        ON_GROUND,
1067
        IN_AIR
1068
    }
1069
1070
    private static final class DelayedPacket {
1071
        final Packet<?> packet;
1072
        int ticks;
1073
1074
        DelayedPacket(Packet<?> packet, int ticks) {
1075
            this.packet = packet;
1076
            this.ticks = ticks;
1077
        }
1078
    }
1079
}
1080
LiquidBounce (Kotlin)COMBATsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.ktKotlin · 128 lines · 5.0 KB

Modifies the amount of velocity you take.

SettingsDelayPauseOnFlag
ModuleVelocity.ktKotlin · Minecraft 26.2 · 128 lines · 5.0 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.combat.velocity
20
21
import net.ccbluex.liquidbounce.event.EventManager
22
import net.ccbluex.liquidbounce.event.events.GameTickEvent
23
import net.ccbluex.liquidbounce.event.events.PacketEvent
24
import net.ccbluex.liquidbounce.event.events.TransferOrigin
25
import net.ccbluex.liquidbounce.event.handler
26
import net.ccbluex.liquidbounce.event.sequenceHandler
27
import net.ccbluex.liquidbounce.event.tickUntil
28
import net.ccbluex.liquidbounce.features.module.ClientModule
29
import net.ccbluex.liquidbounce.features.module.ModuleCategories
30
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityAAC442
31
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityBlocksMC
32
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityDexland
33
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityGrim2344
34
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityGrim2371
35
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityHylex
36
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityHypixel
37
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityIntave
38
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityJumpReset
39
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityLag
40
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityModify
41
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityReduce
42
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityReversal
43
import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.VelocityStrafe
44
import net.ccbluex.liquidbounce.utils.network.isLocalPlayerVelocity
45
import net.minecraft.network.protocol.Packet
46
import net.minecraft.network.protocol.game.ClientGamePacketListener
47
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket
48
49
/**
50
 * Velocity module
51
 *
52
 * Modifies the amount of velocity you take.
53
 */
54
55
object ModuleVelocity : ClientModule("Velocity", ModuleCategories.COMBAT, aliases = listOf("AntiKnockBack")) {
56
57
    val modes = choices(
58
        "Mode", VelocityModify, arrayOf(
59
            // Generic modes
60
            VelocityModify,
61
            VelocityReversal,
62
            VelocityStrafe,
63
            VelocityJumpReset,
64
            VelocityLag,
65
            VelocityReduce,
66
67
            // Server modes
68
            VelocityHypixel,
69
            VelocityDexland,
70
            VelocityHylex,
71
            VelocityBlocksMC,
72
73
            // Anti cheat modes
74
            VelocityGrim2371,
75
            VelocityGrim2344,
76
            VelocityAAC442,
77
            VelocityIntave,
78
        )
79
    ).apply(::tagBy)
80
81
    private val delay by intRange("Delay", 0..0, 0..40, "ticks")
82
    private val pauseOnFlag by int("PauseOnFlag", 0, 0..20, "ticks")
83
84
    internal var pause = 0
85
86
    @Suppress("unused")
87
    private val pauseHandler = handler<GameTickEvent> {
88
        if (pause > 0) {
89
            pause--
90
        }
91
    }
92
93
    @Suppress("unused")
94
    private val packetHandler = sequenceHandler<PacketEvent>(priority = 1) { event ->
95
        val packet = event.packet
96
97
        if (!event.original || pause > 0) {
98
            return@sequenceHandler
99
        }
100
101
        if (packet.isLocalPlayerVelocity()) {
102
            // When delay is above 0, we will delay the velocity update
103
            if (delay.last > 0) {
104
                event.cancelEvent()
105
106
                delay.random().let { ticks ->
107
                    if (ticks > 0) {
108
                        val timeToWait = System.currentTimeMillis() + (ticks * 50L)
109
110
                        tickUntil { System.currentTimeMillis() >= timeToWait }
111
                    }
112
                }
113
114
                val packetEvent = PacketEvent(TransferOrigin.INCOMING, packet, false)
115
                EventManager.callEvent(packetEvent)
116
117
                if (!packetEvent.isCancelled) {
118
                    @Suppress("UNCHECKED_CAST")
119
                    (packet as Packet<ClientGamePacketListener>).handle(network)
120
                }
121
            }
122
        } else if (packet is ClientboundPlayerPositionPacket) {
123
            pause = pauseOnFlag
124
        }
125
    }
126
127
}
128