LiquidSense Dev Velocity module 2 files, 592 lines

LiquidSense Dev Velocity: Full Source Analysis

LiquidSense Dev's Velocity is the classic LiquidBounce knockback controller with eight modes selected by a ListValue: Simple scales or cancels the S12 packet outright, AAC and AACZero defer…

net/ccbluex/liquidbounce/features/module/modules/combat/Velocity.kt · GitHub source ↗

Published 2026-08-12 · Updated 2026-08-12

Packets This Module Uses

Analysis

Overview

LiquidSense Dev's Velocity is the classic LiquidBounce knockback controller with eight modes selected by a ListValue: Simple scales or cancels the S12 packet outright, AAC and AACZero defer cancellation into the tick handler with motion rewrites, AACPush divides the incoming XZ motion and drains Y while hurt, Reverse and SmoothReverse preserve or gently damp the knockback through strafe and speedInAir manipulation, AAC4.4.0 halves horizontal motion in air, Jump converts the knockback into a launch, and Glitch cancels the packet and rides noClip for a few ticks. The packet handler also cancels every S27 explosion packet and every S06 health update unconditionally, with a TODO comment noting explosion velocity support is unimplemented.

Packet-side handling

The onPacket handler watches S12PacketEntityVelocity for the self entity. Simple mode rewrites the packet's motion fields: with Horizontal and Vertical both at 0 it cancels the packet entirely, otherwise it scales each motion component by the matching value with integer fixed-point math, so the server still applies a reduced knockback. Glitch cancels the packet only while onGround and sets the velocityInput flag that the update handler turns into noClip. Every other mode just records velocityInput, hurt or the timer reset and defers the actual motion work to the tick handler. The handler also cancels S27PacketExplosion and S06PacketUpdateHealth with no mode check at all, which suppresses explosion knockback and health sync on every mode.

Tick-side modes

The onUpdate handler implements the deferred modes. AAC waits 80ms then multiplies motionX and motionZ by the Horizontal value, leaving Y alone. AACPush divides motionX and motionZ by the AACPushXZReducer while hurtResistantTime is at least 19, subtracts 0.014999993 from motionY each tick while hurt and the Speed module is off, and forces the local onGround true while hurt to fool ground checks. AACZero adds velocity 0, -1, 0 and sets onGround true while hurt, and cancels the JumpEvent during the hurt window. Reverse strafes at the current speed times ReverseStrength while airborne, SmoothReverse sets speedInAir to the SmoothReverseStrength value during the hurt window, and AAC4.4.0 multiplies horizontal motion by 0.6 in air. Jump sets motionY to 0.42 and adds a 0.2 directional boost whenever hurtTime is positive and the player is onGround.

State and disable behavior

velocityInput is the master flag the packet handler arms and the update handler consumes: Reverse and AAC modes check it before acting, SmoothReverse resets speedInAir to 0.02 when it is false, and Glitch assigns noClip = velocityInput each tick so the player becomes non-colliding for exactly as long as the flag stays set. Two MSTimer fields pace the 80ms deferrals, and onDisable resets speedInAir to 0.02F. The JumpEvent handler cancels the vanilla jump for AACPush, AAC4.4.0 and AACZero during the hurt window, which stops the vanilla jump from masking the module's motion work.

source Velocity.kt (module)

Velocity.kt248 lines · JavaOriginal ↗
1
/*
2
 * LiquidBounce Hacked Client
3
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
4
 * https://github.com/CCBlueX/LiquidBounce/
5
 */
6
package net.ccbluex.liquidbounce.features.module.modules.combat
7
8
import net.ccbluex.liquidbounce.LiquidBounce
9
import net.ccbluex.liquidbounce.event.EventTarget
10
import net.ccbluex.liquidbounce.event.JumpEvent
11
import net.ccbluex.liquidbounce.event.PacketEvent
12
import net.ccbluex.liquidbounce.event.UpdateEvent
13
import net.ccbluex.liquidbounce.features.module.Module
14
import net.ccbluex.liquidbounce.features.module.ModuleCategory
15
import net.ccbluex.liquidbounce.features.module.ModuleInfo
16
import net.ccbluex.liquidbounce.features.module.modules.movement.Speed
17
import net.ccbluex.liquidbounce.utils.MovementUtils
18
import net.ccbluex.liquidbounce.utils.timer.MSTimer
19
import net.ccbluex.liquidbounce.value.BoolValue
20
import net.ccbluex.liquidbounce.value.FloatValue
21
import net.ccbluex.liquidbounce.value.IntegerValue
22
import net.ccbluex.liquidbounce.value.ListValue
23
import net.minecraft.network.play.server.S06PacketUpdateHealth
24
import net.minecraft.network.play.server.S12PacketEntityVelocity
25
import net.minecraft.network.play.server.S27PacketExplosion
26
import net.minecraft.util.MathHelper
27
28
@ModuleInfo(name = "Velocity", description = "Allows you to modify the amount of knockback you take.", category = ModuleCategory.COMBAT)
29
class Velocity : Module() {
30
31
    /**
32
     * OPTIONS
33
     */
34
    private val horizontalValue = FloatValue("Horizontal", 0F, 0F, 1F)
35
    private val verticalValue = FloatValue("Vertical", 0F, 0F, 1F)
36
    private val modeValue = ListValue("Mode", arrayOf("Simple", "AAC", "AACPush", "AACZero",
37
            "Reverse","SmoothReverse","AAC4.4.0", "Jump", "Glitch"), "Simple")
38
39
    // Reverse
40
    private val reverseStrengthValue = FloatValue("ReverseStrength", 1F, 0.1F, 1F)
41
    private val reverse2StrengthValue = FloatValue("SmoothReverseStrength", 0.05F, 0.02F, 0.1F)
42
43
    // AAC Push
44
    private val aacPushXZReducerValue = FloatValue("AACPushXZReducer", 2F, 1F, 3F)
45
    private val aacPushYReducerValue = BoolValue("AACPushYReducer", true)
46
    /**
47
     * VALUES
48
     */
49
    private var velocityTimer = MSTimer()
50
    private var velocityTimer2 = MSTimer()
51
    private var velocityInput = false
52
    var a = false
53
    var b = false
54
55
    // SmoothReverse
56
    private var hurt = false
57
58
    private var reverseHurt = false
59
60
    // AACPush
61
    private var jump = false
62
63
    override val tag: String
64
        get() = modeValue.get()
65
66
    override fun onDisable() {
67
        mc.thePlayer?.speedInAir = 0.02F
68
    }
69
70
    @EventTarget
71
    fun onUpdate(event: UpdateEvent) {
72
        if (mc.thePlayer.isInWater || mc.thePlayer.isInLava || mc.thePlayer.isInWeb)
73
            return
74
75
        when (modeValue.get().toLowerCase()) {
76
            "jump" -> if (mc.thePlayer.hurtTime > 0 && mc.thePlayer.onGround) {
77
                mc.thePlayer.motionY = 0.42
78
79
                val yaw = mc.thePlayer.rotationYaw * 0.017453292F
80
                mc.thePlayer.motionX -= MathHelper.sin(yaw) * 0.2
81
                mc.thePlayer.motionZ += MathHelper.cos(yaw) * 0.2
82
            }
83
84
            "glitch" -> {
85
                mc.thePlayer.noClip = velocityInput
86
                if (mc.thePlayer.hurtTime == 7)
87
                    mc.thePlayer.motionY = 0.4
88
89
                velocityInput = false
90
            }
91
92
            "reverse" -> {
93
                if (!velocityInput)
94
                    return
95
96
                if (!mc.thePlayer.onGround) {
97
                    MovementUtils.strafe(MovementUtils.getSpeed() * reverseStrengthValue.get())
98
                } else if (velocityTimer.hasTimePassed(80L))
99
                    velocityInput = false
100
            }
101
102
            "smoothreverse" -> {
103
                if (!velocityInput) {
104
                    mc.thePlayer.speedInAir = 0.02F
105
                    return
106
                }
107
108
                if (mc.thePlayer.hurtTime > 0)
109
                    reverseHurt = true
110
111
                if (!mc.thePlayer.onGround) {
112
                    if (reverseHurt)
113
                        mc.thePlayer.speedInAir = reverse2StrengthValue.get()
114
                } else if (velocityTimer.hasTimePassed(80L)) {
115
                    velocityInput = false
116
                    reverseHurt = false
117
                }
118
            }
119
120
            "aac4.4.0" -> {
121
                if (!mc.thePlayer.onGround) {
122
                    if (hurt) {
123
                        mc.thePlayer.speedInAir = 0.02f
124
                        mc.thePlayer.motionX *= 0.6
125
                        mc.thePlayer.motionZ *= 0.6
126
                    }
127
                } else if (velocityTimer.hasTimePassed(80L)) {
128
                    hurt = false
129
                    mc.thePlayer.speedInAir = 0.02f
130
                }
131
            }
132
133
            "aacpush" -> {
134
                if (jump) {
135
                    if (mc.thePlayer.onGround)
136
                        jump = false
137
                } else {
138
                    // Strafe
139
                    if (mc.thePlayer.hurtTime > 0 && mc.thePlayer.motionX != 0.0 && mc.thePlayer.motionZ != 0.0)
140
                        mc.thePlayer.onGround = true
141
142
                    // Reduce Y
143
                    if (mc.thePlayer.hurtResistantTime > 0 && aacPushYReducerValue.get()
144
                            && !LiquidBounce.moduleManager[Speed::class.java]!!.state)
145
                        mc.thePlayer.motionY -= 0.014999993
146
                }
147
148
                // Reduce XZ
149
                if (mc.thePlayer.hurtResistantTime >= 19) {
150
                    val reduce = aacPushXZReducerValue.get()
151
152
                    mc.thePlayer.motionX /= reduce
153
                    mc.thePlayer.motionZ /= reduce
154
                }
155
            }
156
157
            "aac" -> if (velocityInput && velocityTimer.hasTimePassed(80L)) {
158
                mc.thePlayer.motionX *= horizontalValue.get()
159
                mc.thePlayer.motionZ *= horizontalValue.get()
160
                //mc.thePlayer.motionY *= verticalValue.get() ?
161
                velocityInput = false
162
            }
163
164
            "aaczero" -> if (mc.thePlayer.hurtTime > 0) {
165
                if (!velocityInput || mc.thePlayer.onGround || mc.thePlayer.fallDistance > 2F)
166
                    return
167
168
                mc.thePlayer.addVelocity(0.0, -1.0, 0.0)
169
                mc.thePlayer.onGround = true
170
            } else
171
                velocityInput = false
172
        }
173
    }
174
175
    @EventTarget
176
    fun onPacket(event: PacketEvent) {
177
        val packet = event.packet
178
179
        if (packet is S12PacketEntityVelocity) {
180
            if (mc.thePlayer == null || (mc.theWorld?.getEntityByID(packet.entityID) ?: return) != mc.thePlayer)
181
                return
182
183
            velocityTimer.reset()
184
            velocityTimer2.reset()
185
186
187
            when (modeValue.get().toLowerCase()) {
188
                "simple" -> {
189
                    val horizontal = horizontalValue.get()
190
                    val vertical = verticalValue.get()
191
192
                    if (horizontal == 0F && vertical == 0F)
193
                        event.cancelEvent()
194
195
                    packet.motionX = (packet.getMotionX() * horizontal).toInt()
196
                    packet.motionY = (packet.getMotionY() * vertical).toInt()
197
                    packet.motionZ = (packet.getMotionZ() * horizontal).toInt()
198
                }
199
200
                "aac","reverse", "aaczero","smoothreverse"-> velocityInput = true
201
202
                "aac4.4.0" -> hurt = true
203
204
                "glitch" -> {
205
                    if (!mc.thePlayer.onGround)
206
                        return
207
208
                    velocityInput = true
209
                    event.cancelEvent()
210
                }
211
            }
212
        }
213
214
        if (packet is S06PacketUpdateHealth) {
215
            // TODO: Support velocity for explosions
216
            event.cancelEvent()
217
        }
218
219
        if (packet is S27PacketExplosion) {
220
            // TODO: Support velocity for explosions
221
            event.cancelEvent()
222
        }
223
    }
224
225
    @EventTarget
226
    fun onJump(event: JumpEvent) {
227
        val thePlayer = mc.thePlayer
228
229
        if (thePlayer == null || thePlayer.isInWater || thePlayer.isInLava || thePlayer.isInWeb)
230
            return
231
232
        when (modeValue.get().toLowerCase()) {
233
            "aacpush" -> {
234
                jump = true
235
236
                if (!thePlayer.isCollidedVertically)
237
                    event.cancelEvent()
238
            }
239
            "aac4.4.0" -> {
240
                if (thePlayer.hurtTime > 0) {
241
                    event.cancelEvent()
242
                }
243
            }
244
            "aaczero" -> if (thePlayer.hurtTime > 0)
245
                event.cancelEvent()
246
        }
247
    }
248
}

What this file does

The entire module is this file. onPacket handles the S12 rewrite or cancel plus the unconditional S27 and S06 cancels, onUpdate implements the eight tick-side mode branches with the motion math for each, and onJump coordinates the AAC-family jump suppression. The value declarations at the top define every knob: Horizontal and Vertical scale factors, ReverseStrength, SmoothReverseStrength, AACPushXZReducer and the AACPushYReducer toggle, and the mode ListValue with its default Simple. The tag property mirrors the selected mode into the HUD, and onDisable's speedInAir reset is the cleanup contract the countering checks rely on.

source MovementUtils.java (strafe math)

MovementUtils.java344 lines · JavaOriginal ↗
1
/*
2
 * LiquidBounce Hacked Client
3
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
4
 * https://github.com/CCBlueX/LiquidBounce/
5
 */
6
package net.ccbluex.liquidbounce.utils;
7
8
import net.ccbluex.liquidbounce.event.MoveEvent;
9
import net.minecraft.block.Block;
10
import net.minecraft.block.BlockAir;
11
import net.minecraft.block.BlockLiquid;
12
import net.minecraft.block.material.Material;
13
import net.minecraft.client.Minecraft;
14
import net.minecraft.client.entity.EntityPlayerSP;
15
import net.minecraft.client.multiplayer.WorldClient;
16
import net.minecraft.entity.Entity;
17
import net.minecraft.potion.Potion;
18
import net.minecraft.potion.PotionEffect;
19
import net.minecraft.util.AxisAlignedBB;
20
import net.minecraft.util.BlockPos;
21
import net.minecraft.util.MathHelper;
22
23
public final class MovementUtils extends MinecraftInstance {
24
25
    public static float getSpeed() {
26
        return (float) Math.sqrt(mc.thePlayer.motionX * mc.thePlayer.motionX + mc.thePlayer.motionZ * mc.thePlayer.motionZ);
27
    }
28
29
    public static float getMaxFallDist() {
30
        PotionEffect potioneffect = mc.thePlayer.getActivePotionEffect(Potion.jump);
31
        int f2 = potioneffect != null ? potioneffect.getAmplifier() + 1 : 0;
32
        return mc.thePlayer.getMaxFallHeight() + f2;
33
        //  int f = potioneffect != null ? potioneffect.getAmplifier() + 1 : 0;
34
        //return mc.thePlayer.getMaxFallHeight() + f;
35
    }
36
37
    public static int LongJumpEffect() {
38
        if (mc.thePlayer.isPotionActive(Potion.jump))
39
            return mc.thePlayer.getActivePotionEffect(Potion.jump).getAmplifier() + 1;
40
        else
41
            return 0;
42
    }
43
44
    public static double LongJumpMoveSpeed() {
45
        double baseSpeed = 0.2873;
46
        if (mc.thePlayer.isPotionActive(Potion.moveSpeed)) {
47
            int amplifier = mc.thePlayer.getActivePotionEffect(Potion.moveSpeed).getAmplifier();
48
            baseSpeed *= 1.0 + 0.2 * (amplifier + 1);
49
        }
50
        return baseSpeed;
51
    }
52
53
    public static void setMoveSpeed(final MoveEvent event, final double speed) {
54
        double forward = mc.thePlayer.moveForward;
55
        double strafe = mc.thePlayer.moveStrafing;
56
        float yaw = mc.thePlayer.rotationYaw;
57
        if (forward == 0.0 && strafe == 0.0) {
58
            event.setX(0.0);
59
            event.setZ(0.0);
60
        } else {
61
            if (forward != 0.0) {
62
                if (strafe > 0.0) {
63
                    yaw += ((forward > 0.0) ? -45 : 45);
64
                } else if (strafe < 0.0) {
65
                    yaw += ((forward > 0.0) ? 45 : -45);
66
                }
67
                strafe = 0.0;
68
                if (forward > 0.0) {
69
                    forward = 1.0;
70
                } else if (forward < 0.0) {
71
                    forward = -1.0;
72
                }
73
            }
74
            event.setX(forward * speed * Math.cos(Math.toRadians(yaw + 90.0f))
75
                    + strafe * speed * Math.sin(Math.toRadians(yaw + 90.0f)));
76
            event.setZ(forward * speed * Math.sin(Math.toRadians(yaw + 90.0f))
77
                    - strafe * speed * Math.cos(Math.toRadians(yaw + 90.0f)));
78
        }
79
    }
80
81
    public static void setSpeed(final MoveEvent moveEvent, final double moveSpeed) {
82
        setSpeed(moveEvent, moveSpeed, mc.thePlayer.rotationYaw, mc.thePlayer.movementInput.moveStrafe, mc.thePlayer.movementInput.moveForward);
83
    }
84
    public static boolean isBlockUnder() {
85
        EntityPlayerSP player = mc.thePlayer;
86
        WorldClient world = mc.theWorld;
87
        AxisAlignedBB pBb = player.getEntityBoundingBox();
88
        double height = player.posY + (double) player.getEyeHeight();
89
        int offset = 0;
90
        while ((double) offset < height) {
91
            if (!world.getCollidingBoundingBoxes(player, pBb.offset(0.0, -offset, 0.0)).isEmpty()) {
92
                return true;
93
            }
94
            offset += 2;
95
        }
96
        return false;
97
    }
98
    public static void setSpeed(final MoveEvent moveEvent, final double moveSpeed, final float pseudoYaw, final double pseudoStrafe, final double pseudoForward) {
99
        double forward = pseudoForward;
100
        double strafe = pseudoStrafe;
101
        float yaw = pseudoYaw;
102
        if (forward != 0.0) {
103
            if (strafe > 0.0) {
104
                yaw += ((forward > 0.0) ? -45 : 45);
105
            }
106
            else if (strafe < 0.0) {
107
                yaw += ((forward > 0.0) ? 45 : -45);
108
            }
109
            strafe = 0.0;
110
            if (forward > 0.0) {
111
                forward = 1.0;
112
            }
113
            else if (forward < 0.0) {
114
                forward = -1.0;
115
            }
116
        }
117
        if (strafe > 0.0) {
118
            strafe = 1.0;
119
        }
120
        else if (strafe < 0.0) {
121
            strafe = -1.0;
122
        }
123
        final double mx = Math.cos(Math.toRadians(yaw + 90.0f));
124
        final double mz = Math.sin(Math.toRadians(yaw + 90.0f));
125
        moveEvent.setX(forward * moveSpeed * mx + strafe * moveSpeed * mz);
126
        moveEvent.setZ(forward * moveSpeed * mz - strafe * moveSpeed * mx);
127
    }
128
129
    public static float getDistanceToGround(Entity e) {
130
        if (mc.thePlayer.isCollidedVertically && mc.thePlayer.onGround) {
131
            return 0.0F;
132
        }
133
        for (float a = (float) e.posY; a > 0.0F; a -= 1.0F) {
134
            int[] stairs = { 53, 67, 108, 109, 114, 128, 134, 135, 136, 156, 163, 164, 180 };
135
            int[] exemptIds = { 6, 27, 28, 30, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 63, 65, 66, 68, 69, 70, 72, 75,
136
                    76, 77, 83, 92, 93, 94, 104, 105, 106, 115, 119, 131, 132, 143, 147, 148, 149, 150, 157, 171, 175,
137
                    176, 177 };
138
            Block block = mc.theWorld.getBlockState(new BlockPos(e.posX, a - 1.0F, e.posZ)).getBlock();
139
            if (!(block instanceof BlockAir)) {
140
                if ((Block.getIdFromBlock(block) == 44) || (Block.getIdFromBlock(block) == 126)) {
141
                    return (float) (e.posY - a - 0.5D) < 0.0F ? 0.0F : (float) (e.posY - a - 0.5D);
142
                }
143
                int[] arrayOfInt1;
144
                int j = (arrayOfInt1 = stairs).length;
145
                for (int i = 0; i < j; i++) {
146
                    int id = arrayOfInt1[i];
147
                    if (Block.getIdFromBlock(block) == id) {
148
                        return (float) (e.posY - a - 1.0D) < 0.0F ? 0.0F : (float) (e.posY - a - 1.0D);
149
                    }
150
                }
151
                j = (arrayOfInt1 = exemptIds).length;
152
                for (int i = 0; i < j; i++) {
153
                    int id = arrayOfInt1[i];
154
                    if (Block.getIdFromBlock(block) == id) {
155
                        return (float) (e.posY - a) < 0.0F ? 0.0F : (float) (e.posY - a);
156
                    }
157
                }
158
                return (float) (e.posY - a + block.getBlockBoundsMaxY() - 1.0D);
159
            }
160
        }
161
        return 0.0F;
162
    }
163
164
    public static double getBaseMoveSpeed() {
165
        double baseSpeed = 0.2873;
166
        if (mc.thePlayer.isPotionActive(Potion.moveSpeed))
167
            baseSpeed *= 1.0 + 0.2 * (mc.thePlayer.getActivePotionEffect(Potion.moveSpeed).getAmplifier() + 1);
168
        return baseSpeed;
169
    }
170
171
    public static int getSpeedEffect() {
172
        return Minecraft.getMinecraft().thePlayer.isPotionActive(Potion.moveSpeed)?Minecraft.getMinecraft().thePlayer.getActivePotionEffect(Potion.moveSpeed).getAmplifier() + 1:0;
173
    }
174
175
    public static int getJumpEffect() {
176
        return Minecraft.getMinecraft().thePlayer.isPotionActive(Potion.jump)?Minecraft.getMinecraft().thePlayer.getActivePotionEffect(Potion.jump).getAmplifier() + 1:0;
177
    }
178
179
180
    public static boolean isInLiquid() {
181
        if(Minecraft.getMinecraft().thePlayer.isInWater()) {
182
            return true;
183
        } else {
184
            boolean inLiquid = false;
185
            int y = (int)Minecraft.getMinecraft().thePlayer.getEntityBoundingBox().minY;
186
187
            for(int x = MathHelper.floor_double(Minecraft.getMinecraft().thePlayer.getEntityBoundingBox().minX); x < MathHelper.floor_double(Minecraft.getMinecraft().thePlayer.getEntityBoundingBox().maxX) + 1; ++x) {
188
                for(int z = MathHelper.floor_double(Minecraft.getMinecraft().thePlayer.getEntityBoundingBox().minZ); z < MathHelper.floor_double(Minecraft.getMinecraft().thePlayer.getEntityBoundingBox().maxZ) + 1; ++z) {
189
                    Block block = Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(x, y, z)).getBlock();
190
                    if(block != null && block.getMaterial() != Material.air) {
191
                        if(!(block instanceof BlockLiquid)) {
192
                            return false;
193
                        }
194
195
                        inLiquid = true;
196
                    }
197
                }
198
            }
199
200
            return inLiquid;
201
        }
202
    }
203
204
    public static void SpeedSetMotion(double speed) {
205
        double forward = mc.thePlayer.movementInput.moveForward;
206
        double strafe = mc.thePlayer.movementInput.moveStrafe;
207
        float yaw = mc.thePlayer.rotationYaw;
208
        if ((forward == 0.0D) && (strafe == 0.0D)) {
209
            mc.thePlayer.motionX = 0;
210
            mc.thePlayer.motionZ = 0;
211
        } else {
212
            if (forward != 0.0D) {
213
                if (strafe > 0.0D) {
214
                    yaw += (forward > 0.0D ? -45 : 45);
215
                } else if (strafe < 0.0D) {
216
                    yaw += (forward > 0.0D ? 45 : -45);
217
                }
218
                strafe = 0.0D;
219
                if (forward > 0.0D) {
220
                    forward = 1;
221
                } else if (forward < 0.0D) {
222
                    forward = -1;
223
                }
224
            }
225
            mc.thePlayer.motionX = forward * speed * Math.cos(Math.toRadians(yaw + 90.0F)) + strafe * speed * Math.sin(Math.toRadians(yaw + 90.0F));
226
            mc.thePlayer.motionZ = forward * speed * Math.sin(Math.toRadians(yaw + 90.0F)) - strafe * speed * Math.cos(Math.toRadians(yaw + 90.0F));
227
        }
228
    }
229
230
    public static void setMotion(MoveEvent event, double speed, double motion) {
231
        double forward = mc.thePlayer.movementInput.moveForward;
232
        double strafe = mc.thePlayer.movementInput.moveStrafe;
233
        double yaw = mc.thePlayer.rotationYaw;
234
        if ((forward == 0.0) && (strafe == 0.0)) {
235
            event.setX(0.0);
236
            event.setZ(0.0);
237
        } else {
238
            if (forward != 0.0) {
239
                if (strafe > 0.0) {
240
                    yaw += (forward > 0.0 ? -45 : 45);
241
                } else if (strafe < 0.0) {
242
                    yaw += (forward > 0.0 ? 45 : -45);
243
                }
244
                strafe = 0.0;
245
                if (forward > 0.0) {
246
                    forward = 1.0;
247
                } else if (forward < 0.0) {
248
                    forward = -1.0;
249
                }
250
            }
251
            double cos = Math.cos(Math.toRadians(yaw + 90.0f));
252
            double sin = Math.sin(Math.toRadians(yaw + 90.0f));
253
            event.setX(( forward * speed * cos + strafe * speed * sin) * motion);
254
            event.setZ(( forward * speed * sin - strafe * speed * cos) * motion);
255
        }
256
    }
257
258
    public static double getJumpBoostModifier(double baseJumpHeight, boolean potionJumpHeight) {
259
        if (mc.thePlayer.isPotionActive(Potion.jump) && potionJumpHeight) {
260
            int amplifier = mc.thePlayer.getActivePotionEffect(Potion.jump).getAmplifier();
261
            baseJumpHeight += ((float)(amplifier + 1) * 0.1f);
262
263
        }
264
        return baseJumpHeight;
265
    }
266
267
    public static void setMotion(MoveEvent e, double speed) {
268
        double forward = mc.thePlayer.movementInput.moveForward;
269
        double strafe = mc.thePlayer.movementInput.moveStrafe;
270
        double yaw = mc.thePlayer.rotationYaw;
271
        if ((forward == 0.0D) && (strafe == 0.0D)) {
272
            mc.thePlayer.motionX = 0;
273
            mc.thePlayer.motionZ = 0;
274
        } else {
275
            if (forward != 0.0D) {
276
                if (strafe > 0.0D) {
277
                    yaw += (forward > 0.0D ? -45 : 45);
278
                } else if (strafe < 0.0D) {
279
                    yaw += (forward > 0.0D ? 45 : -45);
280
                }
281
                strafe = 0.0D;
282
                if (forward > 0.0D) {
283
                    forward = 1;
284
                } else if (forward < 0.0D) {
285
                    forward = -1;
286
                }
287
            }
288
            e.setX( forward * speed * Math.cos(Math.toRadians(yaw + 90.0F)) + strafe * speed * Math.sin(Math.toRadians(yaw + 90.0F)));
289
            e.setZ( forward * speed * Math.sin(Math.toRadians(yaw + 90.0F)) - strafe * speed * Math.cos(Math.toRadians(yaw + 90.0F)));
290
        }
291
    }
292
    public static void strafe() {
293
        strafe(getSpeed());
294
    }
295
    public static boolean isOnGround(double height) {
296
        if (!mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, mc.thePlayer.getEntityBoundingBox().offset(0.0D, -height, 0.0D)).isEmpty()) {
297
            return true;
298
        } else {
299
            return false;
300
        }
301
    }
302
    public static boolean isMoving() {
303
        return mc.thePlayer != null && (mc.thePlayer.movementInput.moveForward != 0F || mc.thePlayer.movementInput.moveStrafe != 0F);
304
    }
305
306
    public static boolean hasMotion() {
307
        return mc.thePlayer.motionX != 0D && mc.thePlayer.motionZ != 0D && mc.thePlayer.motionY != 0D;
308
    }
309
310
    public static void strafe(final float speed) {
311
        if(!isMoving())
312
            return;
313
314
        final double yaw = getDirection();
315
        mc.thePlayer.motionX = -Math.sin(yaw) * speed;
316
        mc.thePlayer.motionZ = Math.cos(yaw) * speed;
317
    }
318
319
    public static void forward(final double length) {
320
        final double yaw = Math.toRadians(mc.thePlayer.rotationYaw);
321
        mc.thePlayer.setPosition(mc.thePlayer.posX + (-Math.sin(yaw) * length), mc.thePlayer.posY, mc.thePlayer.posZ + (Math.cos(yaw) * length));
322
    }
323
324
    public static double getDirection() {
325
        float rotationYaw = mc.thePlayer.rotationYaw;
326
327
        if(mc.thePlayer.moveForward < 0F)
328
            rotationYaw += 180F;
329
330
        float forward = 1F;
331
        if(mc.thePlayer.moveForward < 0F)
332
            forward = -0.5F;
333
        else if(mc.thePlayer.moveForward > 0F)
334
            forward = 0.5F;
335
336
        if(mc.thePlayer.moveStrafing > 0F)
337
            rotationYaw -= 90F * forward;
338
339
        if(mc.thePlayer.moveStrafing < 0F)
340
            rotationYaw += 90F * forward;
341
342
        return Math.toRadians(rotationYaw);
343
    }
344
}

What this file does

The Reverse and AACPush modes consume the utility's motion math. getSpeed returns the horizontal magnitude of the current motion, and strafe(speed) rewrites motionX and motionZ as -sin(direction) times speed and cos(direction) times speed, using the client's directional yaw blending from getDirection. Reverse mode calls strafe(MovementUtils.getSpeed() times ReverseStrength) every airborne tick, so the knockback magnitude is preserved along the player's chosen direction, and the same helper underlies the AACPush strafe behavior. The file also carries the potion-aware base-speed helpers used by the client's speed modules, but Velocity only touches getSpeed, strafe and getDirection.

anticheat Countering Checks

The anticheat code that detects or counters the techniques this module uses. Full source, with the detection mechanism explained below each box.

anticheat KnockbackHandler (required knockback prediction)

KnockbackHandler.java262 lines · Java
1
package ac.grim.grimac.checks.impl.velocity;
2
3
import ac.grim.grimac.api.config.ConfigManager;
4
import ac.grim.grimac.api.storage.verbose.Verbose;
5
import ac.grim.grimac.checks.Check;
6
import ac.grim.grimac.checks.CheckData;
7
import ac.grim.grimac.checks.type.PacketSendListener;
8
import ac.grim.grimac.checks.type.PostPredictionListener;
9
import ac.grim.grimac.player.GrimPlayer;
10
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
11
import ac.grim.grimac.utils.data.Pair;
12
import ac.grim.grimac.utils.data.VectorData;
13
import ac.grim.grimac.utils.data.VelocityData;
14
import ac.grim.grimac.utils.math.Vector3dm;
15
import com.github.retrooper.packetevents.event.PacketSendEvent;
16
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
17
import com.github.retrooper.packetevents.util.Vector3d;
18
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityVelocity;
19
import lombok.Getter;
20
import org.jetbrains.annotations.NotNull;
21
22
import java.util.Deque;
23
import java.util.LinkedList;
24
25
// We are making a velocity sandwich between two pieces of transaction packets (bread)
26
@CheckData(name = "AntiKB", stableKey = "grim.velocity.anti_knockback", alternativeName = "AntiKnockback", configName = "Knockback", description = "Did not take the expected entity knockback", setback = 10, decay = 0.025)
27
public class KnockbackHandler extends Check implements PacketSendListener, PostPredictionListener {
28
    private static final Verbose V = Verbose.of("[ignored knockback|o: {offset}]");
29
30
    private final Deque<VelocityData> firstBreadMap = new LinkedList<>();
31
32
    private final Deque<VelocityData> lastKnockbackKnownTaken = new LinkedList<>();
33
    private VelocityData firstBreadOnlyKnockback = null;
34
    @Getter
35
    private boolean knockbackPointThree = false;
36
37
    private double offsetToFlag;
38
    private double maxAdv, immediate, ceiling, multiplier;
39
40
    private double threshold;
41
42
    public KnockbackHandler(GrimPlayer player) {
43
        super(player);
44
    }
45
46
    @Override
47
    public void onPacketSend(final PacketSendEvent event) {
48
        if (event.getPacketType() == PacketType.Play.Server.ENTITY_VELOCITY) {
49
            WrapperPlayServerEntityVelocity velocity = new WrapperPlayServerEntityVelocity(event);
50
            int entityId = velocity.getEntityId();
51
52
            // Detect whether this knockback packet affects the player or if it is useless
53
            // Mojang sends extra useless knockback packets for no apparent reason
54
            if (player.compensatedEntities.serverPlayerVehicle != null && entityId != player.compensatedEntities.serverPlayerVehicle) {
55
                return;
56
            }
57
            if (player.compensatedEntities.serverPlayerVehicle == null && entityId != player.entityID) {
58
                return;
59
            }
60
61
            // If the player isn't in a vehicle and the ID is for the player, the player will take kb
62
            // If the player is in a vehicle and the ID is for the player's vehicle, the player will take kb
63
            Vector3d playerVelocity = velocity.getVelocity();
64
65
            // Blacklist problemated vector until mojang fixes a client-sided bug
66
            if (playerVelocity.getY() == -0.04) {
67
                velocity.setVelocity(playerVelocity.add(new Vector3d(0, 1 / 8000D, 0)));
68
                playerVelocity = velocity.getVelocity();
69
                event.markForReEncode(true);
70
            }
71
72
            playerVelocity = VectorPrecisionConverter.convert(player.getClientVersion(), playerVelocity);
73
74
            // Wrap velocity between two transactions
75
            player.sendTransaction();
76
            addPlayerKnockback(entityId, player.lastTransactionSent.get(), new Vector3dm(playerVelocity.getX(), playerVelocity.getY(), playerVelocity.getZ()));
77
            event.getTasksAfterSend().add(player::sendTransaction);
78
        }
79
    }
80
81
    @NotNull
82
    public Pair<VelocityData, Vector3dm> getFutureKnockback() {
83
        // Chronologically in the future
84
        if (!firstBreadMap.isEmpty()) {
85
            VelocityData data = firstBreadMap.peek();
86
            return new Pair<>(data, data != null ? data.vector : null);
87
        }
88
89
        // Less in the future
90
        if (!lastKnockbackKnownTaken.isEmpty()) {
91
            VelocityData data = lastKnockbackKnownTaken.peek();
92
            return new Pair<>(data, data != null ? data.vector : null);
93
        }
94
95
        // Uncertain, might be in the future
96
        if (player.firstBreadKB != null && player.likelyKB == null) {
97
            VelocityData data = player.firstBreadKB;
98
            return new Pair<>(data, data.vector.clone());
99
        } else if (player.likelyKB != null) { // Known to be in the present
100
            VelocityData data = player.likelyKB;
101
            return new Pair<>(data, data.vector.clone());
102
        }
103
        return new Pair<>(null, null);
104
    }
105
106
    private void addPlayerKnockback(int entityID, int breadOne, @NotNull Vector3dm knockback) {
107
        firstBreadMap.add(new VelocityData(entityID, breadOne, player.getSetbackTeleportUtil().isSendingSetback, knockback));
108
    }
109
110
    public VelocityData calculateRequiredKB(int entityID, int transaction, boolean isJustTesting) {
111
        tickKnockback(transaction);
112
113
        VelocityData returnLastKB = null;
114
        for (VelocityData data : lastKnockbackKnownTaken) {
115
            if (data.entityID == entityID)
116
                returnLastKB = data;
117
        }
118
119
        if (!isJustTesting) {
120
            lastKnockbackKnownTaken.clear();
121
        }
122
        return returnLastKB;
123
    }
124
125
    private void tickKnockback(int transactionID) {
126
        firstBreadOnlyKnockback = null;
127
        if (firstBreadMap.isEmpty()) return;
128
        VelocityData data = firstBreadMap.peek();
129
        while (data != null) {
130
            if (data.transaction == transactionID) { // First bread knockback
131
                firstBreadOnlyKnockback = new VelocityData(data.entityID, data.transaction, data.isSetback, data.vector);
132
                //firstBreadMap.poll();
133
                break; // All knockback after this will have not been applied
134
            } else if (data.transaction < transactionID) { // This kb has 100% arrived to the player
135
                VelocityData velocityData = new VelocityData(data.entityID, data.transaction, data.isSetback, data.vector);
136
137
                if (firstBreadOnlyKnockback != null) { // Don't require kb twice
138
                    velocityData.offset = data.offset;
139
                }
140
141
                lastKnockbackKnownTaken.add(velocityData);
142
143
                // Knockback has been applied and is now required, remove it from first bread
144
                firstBreadOnlyKnockback = null;
145
                firstBreadMap.poll();
146
                data = firstBreadMap.peek();
147
            } else { // We are too far ahead in the future
148
                break;
149
            }
150
        }
151
    }
152
153
    public void forceExempt() {
154
        // Unsure knockback was taken
155
        if (player.firstBreadKB != null) {
156
            player.firstBreadKB.offset = 0;
157
        }
158
159
        if (player.likelyKB != null) {
160
            player.likelyKB.offset = 0;
161
        }
162
    }
163
164
    public void setPointThree(boolean isPointThree) {
165
        knockbackPointThree = knockbackPointThree || isPointThree;
166
    }
167
168
    public void handlePredictionAnalysis(double offset) {
169
        if (player.firstBreadKB != null) {
170
            player.firstBreadKB.offset = Math.min(player.firstBreadKB.offset, offset);
171
        }
172
173
        if (player.likelyKB != null) {
174
            player.likelyKB.offset = Math.min(player.likelyKB.offset, offset);
175
        }
176
    }
177
178
    @Override
179
    public void onPredictionComplete(final PredictionComplete predictionComplete) {
180
        double offset = predictionComplete.getOffset();
181
        if (!predictionComplete.isChecked() || predictionComplete.getData().isTeleport()) {
182
            forceExempt();
183
            return;
184
        }
185
186
        boolean wasZero = knockbackPointThree;
187
        knockbackPointThree = false;
188
189
        if (player.likelyKB == null && player.firstBreadKB == null) {
190
            return;
191
        }
192
193
        if (player.predictedVelocity.isFirstBreadKb()) {
194
            firstBreadOnlyKnockback = null;
195
            firstBreadMap.poll(); // Remove from map so we don't pull it again
196
        }
197
198
        if (wasZero || player.predictedVelocity.isKnockback()) {
199
            // Unsure knockback was taken
200
            if (player.firstBreadKB != null) {
201
                player.firstBreadKB.offset = Math.min(player.firstBreadKB.offset, offset);
202
            }
203
204
            // 100% known kb was taken
205
            if (player.likelyKB != null) {
206
                player.likelyKB.offset = Math.min(player.likelyKB.offset, offset);
207
            }
208
        }
209
210
        if (player.likelyKB != null) {
211
            if (player.likelyKB.offset > offsetToFlag) {
212
                threshold = Math.min(threshold + player.likelyKB.offset, ceiling);
213
                if (player.likelyKB.isSetback) { // Don't increase violations if this velocity was setback, just teleport and resend them velocity.
214
                    if (!isNoSetbackPermission()) {
215
                        player.getSetbackTeleportUtil().executeViolationSetback();
216
                    }
217
                } else {
218
                    boolean ignored = player.likelyKB.offset == Integer.MAX_VALUE;
219
                    if (flag(V.write(verbose()).bool(ignored).f64(player.likelyKB.offset))) { // This velocity was sent by the server.
220
                        if (player.likelyKB.offset >= immediate || threshold >= maxAdv) {
221
                            setbackIfAboveSetbackVL();
222
                        }
223
                    } else {
224
                        reward();
225
                    }
226
                }
227
            } else if (threshold > 0.05) {
228
                threshold *= multiplier;
229
            }
230
        }
231
    }
232
233
    public boolean shouldIgnoreForPrediction(VectorData data) {
234
        if (data.isKnockback() && data.isFirstBreadKb()) {
235
            return player.firstBreadKB.offset > offsetToFlag;
236
        }
237
        return false;
238
    }
239
240
    public boolean wouldFlag() {
241
        return (player.likelyKB != null && player.likelyKB.offset > offsetToFlag) || (player.firstBreadKB != null && player.firstBreadKB.offset > offsetToFlag);
242
    }
243
244
    public VelocityData calculateFirstBreadKnockback(int entityID, int transaction) {
245
        tickKnockback(transaction);
246
        if (firstBreadOnlyKnockback != null && firstBreadOnlyKnockback.entityID == entityID)
247
            return firstBreadOnlyKnockback;
248
        return null;
249
    }
250
251
    @Override
252
    public void onReload(@NotNull ConfigManager config) {
253
        offsetToFlag = config.getDoubleElse("Knockback.threshold", 0.001);
254
        maxAdv = config.getDoubleElse("Knockback.max-advantage", 1);
255
        immediate = config.getDoubleElse("Knockback.immediate-setback-threshold", 0.1);
256
        multiplier = config.getDoubleElse("Knockback.setback-decay-multiplier", 0.999);
257
        ceiling = config.getDoubleElse("Knockback.max-ceiling", 4);
258
        if (maxAdv < 0) maxAdv = Double.MAX_VALUE;
259
        if (immediate < 0) immediate = Double.MAX_VALUE;
260
    }
261
262
}

How it counteracts this module

Grim's KnockbackHandler brackets the ENTITY_VELOCITY packet with two transactions and once the client's echo proves receipt, the vector becomes REQUIRED in the predicted motion. onPredictionComplete offsets the actual motion against the required vector with the Knockback threshold at 0.001, accumulating with a 0.999 decay toward a max advantage of 1 and setting back at 0.1. The Simple mode with both values at 0 cancels the S12 outright, so the required vector never appears in the predicted motion and the offset is the full knockback magnitude on the first hurt tick. Every scaling mode produces a proportional offset, because the server-side record of the vector is unaffected by the client's rewrite.

The Reverse and SmoothReverse modes are the honest pass surface: they preserve the knockback magnitude while redirecting it through strafe, so Grim's required-vector prediction sees the motion arrive and the offset stays near zero. AACPush's Y drain of 0.014999993 per tick is a small vertical deficit that accumulates slowly, which is why the mode is the tuned one, while AACZero and Glitch cancel the packet like Simple and flag the same way.

anticheat ExplosionHandler (S27 sandwich)

ExplosionHandler.java267 lines · Java
1
package ac.grim.grimac.checks.impl.velocity;
2
3
import ac.grim.grimac.api.config.ConfigManager;
4
import ac.grim.grimac.api.storage.verbose.Verbose;
5
import ac.grim.grimac.checks.Check;
6
import ac.grim.grimac.checks.CheckData;
7
import ac.grim.grimac.checks.type.PacketSendListener;
8
import ac.grim.grimac.checks.type.PostPredictionListener;
9
import ac.grim.grimac.player.GrimPlayer;
10
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;
11
import ac.grim.grimac.utils.data.VectorData;
12
import ac.grim.grimac.utils.data.VelocityData;
13
import ac.grim.grimac.utils.math.Vector3dm;
14
import com.github.retrooper.packetevents.PacketEvents;
15
import com.github.retrooper.packetevents.event.PacketSendEvent;
16
import com.github.retrooper.packetevents.manager.server.ServerVersion;
17
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
18
import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState;
19
import com.github.retrooper.packetevents.protocol.world.states.defaulttags.BlockTags;
20
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
21
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
22
import com.github.retrooper.packetevents.protocol.world.states.type.StateValue;
23
import com.github.retrooper.packetevents.util.Vector3d;
24
import com.github.retrooper.packetevents.util.Vector3i;
25
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerExplosion;
26
import lombok.Getter;
27
import org.jetbrains.annotations.NotNull;
28
import org.jetbrains.annotations.Nullable;
29
30
import java.util.Deque;
31
import java.util.LinkedList;
32
33
@CheckData(name = "AntiExplosion", stableKey = "grim.velocity.anti_explosion", configName = "Explosion", description = "Did not take the expected explosion knockback", setback = 10)
34
public class ExplosionHandler extends Check implements PacketSendListener, PostPredictionListener {
35
    private static final Verbose V = Verbose.of("[ignored explosion|o: {offset}]");
36
37
    private final Deque<VelocityData> firstBreadMap = new LinkedList<>();
38
39
    private VelocityData lastExplosionsKnownTaken = null;
40
    private VelocityData firstBreadAddedExplosion = null;
41
42
    @Getter
43
    private boolean explosionPointThree = false;
44
45
    private double offsetToFlag;
46
47
    public ExplosionHandler(GrimPlayer player) {
48
        super(player);
49
    }
50
51
    @Override
52
    public void onPacketSend(final PacketSendEvent event) {
53
        if (event.getPacketType() == PacketType.Play.Server.EXPLOSION) {
54
            WrapperPlayServerExplosion explosion = new WrapperPlayServerExplosion(event);
55
56
            // Since 1.21.2, the server will instead send these changes via block change packets
57
            final boolean hasBlocks = PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_21_2);
58
            if (hasBlocks) {
59
                this.handleBlockExplosions(explosion);
60
            }
61
62
            Vector3d velocity = explosion.getKnockback();
63
            if (velocity != null && (velocity.x != 0 || velocity.y != 0 || velocity.z != 0)) {
64
                // No need to spam transactions
65
                if (!hasBlocks || explosion.getRecords().isEmpty()) player.sendTransaction();
66
                addPlayerExplosion(player.lastTransactionSent.get(), velocity);
67
                event.getTasksAfterSend().add(player::sendTransaction);
68
            }
69
        }
70
    }
71
72
    private void handleBlockExplosions(WrapperPlayServerExplosion explosion) {
73
        final @Nullable WrapperPlayServerExplosion.BlockInteraction blockInteraction = explosion.getBlockInteraction();
74
        final boolean shouldDestroy = blockInteraction != WrapperPlayServerExplosion.BlockInteraction.KEEP_BLOCKS;
75
        if (explosion.getRecords().isEmpty() || !shouldDestroy) {
76
            return;
77
        }
78
79
        player.sendTransaction();
80
81
        player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
82
            for (Vector3i record : explosion.getRecords()) {
83
                // Null OR not flip redstone blocks, then set to air
84
                if (blockInteraction != WrapperPlayServerExplosion.BlockInteraction.TRIGGER_BLOCKS) {
85
                    player.compensatedWorld.updateBlock(record.x, record.y, record.z, 0);
86
                } else {
87
                    // We need to flip redstone blocks, or do special things with other blocks
88
                    final WrappedBlockState state = player.compensatedWorld.getBlock(record);
89
                    final StateType type = state.getType();
90
                    if (BlockTags.CANDLES.contains(type) || BlockTags.CANDLE_CAKES.contains(type)) {
91
                        state.setLit(false);
92
                        continue;
93
                    } else if (type == StateTypes.BELL) {
94
                        // Does this affect anything? I don't know, I don't see anything that relies on whether a bell is ringing.
95
                        continue;
96
                    }
97
98
                    // Otherwise try and flip/open it.
99
                    final boolean canFlip = state.hasProperty(StateValue.POWERED) && !state.isPowered() || type == StateTypes.LEVER;
100
                    if (canFlip) {
101
                        player.compensatedWorld.tickOpenable(record.x, record.y, record.z);
102
                    }
103
                }
104
            }
105
        });
106
    }
107
108
    public VelocityData getFutureExplosion() {
109
        // Chronologically in the future
110
        if (!firstBreadMap.isEmpty()) {
111
            return firstBreadMap.peek();
112
        }
113
114
        // Less in the future
115
        if (lastExplosionsKnownTaken != null) {
116
            return lastExplosionsKnownTaken;
117
        }
118
119
        // Uncertain, might be in the future
120
        if (player.firstBreadExplosion != null && player.likelyExplosions == null) {
121
            return player.firstBreadExplosion;
122
        } else if (player.likelyExplosions != null) { // Known to be in the present
123
            return player.likelyExplosions;
124
        }
125
        return null;
126
    }
127
128
    public boolean shouldIgnoreForPrediction(VectorData data) {
129
        if (data.isExplosion() && data.isFirstBreadExplosion()) {
130
            return player.firstBreadExplosion.offset > offsetToFlag;
131
        }
132
        return false;
133
    }
134
135
    public boolean wouldFlag() {
136
        return (player.likelyExplosions != null && player.likelyExplosions.offset > offsetToFlag) || (player.firstBreadExplosion != null && player.firstBreadExplosion.offset > offsetToFlag);
137
    }
138
139
    public void addPlayerExplosion(int breadOne, Vector3d explosion) {
140
        firstBreadMap.add(new VelocityData(-1, breadOne, player.getSetbackTeleportUtil().isSendingSetback, new Vector3dm(explosion.getX(), explosion.getY(), explosion.getZ())));
141
    }
142
143
    public void setPointThree(boolean isPointThree) {
144
        explosionPointThree = explosionPointThree || isPointThree;
145
    }
146
147
    public void handlePredictionAnalysis(double offset) {
148
        if (player.firstBreadExplosion != null) {
149
            player.firstBreadExplosion.offset = Math.min(player.firstBreadExplosion.offset, offset);
150
        }
151
152
        if (player.likelyExplosions != null) {
153
            player.likelyExplosions.offset = Math.min(player.likelyExplosions.offset, offset);
154
        }
155
    }
156
157
    public void forceExempt() {
158
        // Unsure explosion was taken
159
        if (player.firstBreadExplosion != null) {
160
            player.firstBreadExplosion.offset = 0;
161
        }
162
163
        if (player.likelyExplosions != null) {
164
            player.likelyExplosions.offset = 0;
165
        }
166
    }
167
168
    @Override
169
    public void onPredictionComplete(final PredictionComplete predictionComplete) {
170
        double offset = predictionComplete.getOffset();
171
172
        boolean wasZero = explosionPointThree;
173
        explosionPointThree = false;
174
175
        if (player.likelyExplosions == null && player.firstBreadExplosion == null) {
176
            firstBreadAddedExplosion = null;
177
            return;
178
        }
179
180
        // We must check to see if knockback has overridden this explosion
181
        // (Yes, I could make this very simple and exempt on kb, but that allows people to ignore most explosions)
182
        //
183
        // We do this by finding the minimum explosion transaction that could have been overridden
184
        // We then compare this against the maximum velocity transaction that could override
185
        //
186
        // If velocity is over transaction, exempt
187
        int minTrans = Math.min(player.likelyExplosions != null ? player.likelyExplosions.transaction : Integer.MAX_VALUE,
188
                player.firstBreadExplosion != null ? player.firstBreadExplosion.transaction : Integer.MAX_VALUE);
189
        int kbTrans = Math.max(player.likelyKB != null ? player.likelyKB.transaction : Integer.MIN_VALUE,
190
                player.firstBreadKB != null ? player.firstBreadKB.transaction : Integer.MIN_VALUE);
191
192
        if (player.predictedVelocity.isFirstBreadExplosion()) {
193
            firstBreadAddedExplosion = null;
194
            firstBreadMap.poll(); // Remove from map so we don't pull it again
195
        }
196
197
        if (wasZero || player.predictedVelocity.isExplosion() ||
198
                (minTrans < kbTrans)) {
199
            // Unsure knockback was taken
200
            if (player.firstBreadExplosion != null) {
201
                player.firstBreadExplosion.offset = Math.min(player.firstBreadExplosion.offset, offset);
202
            }
203
204
            if (player.likelyExplosions != null) {
205
                player.likelyExplosions.offset = Math.min(player.likelyExplosions.offset, offset);
206
            }
207
        }
208
209
        // 100% known kb was taken
210
        if (player.likelyExplosions != null && !player.compensatedEntities.self.isDead) {
211
            if (player.likelyExplosions.offset > offsetToFlag) {
212
                boolean ignored = player.likelyExplosions.offset == Integer.MAX_VALUE;
213
                flagWithSetback(V.write(verbose()).bool(ignored).f64(offset));
214
            } else {
215
                reward();
216
            }
217
        }
218
    }
219
220
    public VelocityData getPossibleExplosions(int lastTransaction, boolean isJustTesting) {
221
        handleTransactionPacket(lastTransaction);
222
        if (lastExplosionsKnownTaken == null)
223
            return null;
224
225
        VelocityData returnLastExplosion = lastExplosionsKnownTaken;
226
        if (!isJustTesting) {
227
            lastExplosionsKnownTaken = null;
228
        }
229
        return returnLastExplosion;
230
    }
231
232
    private void handleTransactionPacket(int transactionID) {
233
        VelocityData data = firstBreadMap.peek();
234
        while (data != null) {
235
            if (data.transaction == transactionID) { // First bread explosion
236
                if (lastExplosionsKnownTaken != null)
237
                    firstBreadAddedExplosion = new VelocityData(-1, data.transaction, data.isSetback, lastExplosionsKnownTaken.vector.clone().add(data.vector));
238
                else
239
                    firstBreadAddedExplosion = new VelocityData(-1, data.transaction, data.isSetback, data.vector);
240
                break; // All knockback after this will have not been applied
241
            } else if (data.transaction < transactionID) {
242
                if (lastExplosionsKnownTaken != null) {
243
                    lastExplosionsKnownTaken.vector.add(data.vector);
244
                } else {
245
                    lastExplosionsKnownTaken = new VelocityData(-1, data.transaction, data.isSetback, data.vector);
246
                }
247
248
                // Explosion has been applied and is now required, remove it from first bread
249
                firstBreadAddedExplosion = null;
250
                firstBreadMap.poll();
251
                data = firstBreadMap.peek();
252
            } else { // We are too far ahead in the future
253
                break;
254
            }
255
        }
256
    }
257
258
    public VelocityData getFirstBreadAddedExplosion(int lastTransaction) {
259
        handleTransactionPacket(lastTransaction);
260
        return firstBreadAddedExplosion;
261
    }
262
263
    @Override
264
    public void onReload(@NotNull ConfigManager config) {
265
        offsetToFlag = config.getDoubleElse("Explosion.threshold", 0.00001);
266
    }
267
}

How it counteracts this module

Grim's ExplosionHandler applies the same transaction sandwich to S27PacketExplosion, with the entity id at -1 because explosions are not entity-targeted, and feeds the vector into lastExplosionsKnownTaken so the required motion is enforced against the prediction. The LiquidSense module cancels every S27 unconditionally in its packet handler, with a TODO comment admitting explosion velocity support was never written, so every explosion knockback is suppressed and every one of those suppressed vectors is a required-motion deficit for this check.

The honest contrast with the entity-knockback path is the gate structure: modules like Sigma's AntiVelocity cancel S27 only in one mode, and Nekoware's only in its Packet mode, but LiquidSense cancels it in all eight modes with no configuration that restores explosion knockback. That makes the ExplosionHandler the one check that bites every mode equally, including the Reverse and SmoothReverse modes that pass the entity-knockback prediction.

anticheat AntiVelocityBasic (pending knockback matching)

AntiVelocityBasic.java46 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.check.movement.position;
20
21
import me.islandscout.hawk.HawkPlayer;
22
import me.islandscout.hawk.check.MovementCheck;
23
import me.islandscout.hawk.check.Cancelless;
24
import me.islandscout.hawk.event.MoveEvent;
25
26
/**
27
 * The AntiVelocityBasic check verifies that players accept knockback.
28
 * It relies on MoveEvent's knockback acceptance detection.
29
 * The AntiVelocityBasic check has been tested to detect as low as a
30
 * 10% difference in horizontal and/or vertical knockback.
31
 */
32
public class AntiVelocityBasic extends MovementCheck implements Cancelless {
33
34
    public AntiVelocityBasic() {
35
        super("antivelocitybasic", true, -1, 5, 0.999, 5000, "%player% may be using anti-velocity (basic), VL: %vl%", null);
36
    }
37
38
    @Override
39
    protected void check(MoveEvent event) {
40
        HawkPlayer pp = event.getHawkPlayer();
41
        if(event.hasFailedKnockback())
42
            punish(pp, false, event);
43
        else
44
            reward(pp);
45
    }
46
}

How it counteracts this module

Hawk's AntiVelocityBasic is a thin wrapper over MoveEvent.hasFailedKnockback with punishment at VL 5, and the mechanics live in MoveEvent.handlePendingVelocities: each pending server knockback is matched against the player's moves in order, with Y within 0.01 and X and Z inside a maxDiscrepancy built from a weirdConstant times a base multiplier plus 0.003. A knockback entry older than ping plus 200ms with no matching move marks the failure. Simple mode with full cancel produces no matching move at all, so the first hurt tick after the S12 ages the entry and the failure fires.

The honest tolerance is the class comment claiming detection down to a 10 percent difference: percentage reductions below that line, like the small Horizontal scaling values near 1.0, sit inside the discrepancy band and pass. AACPush's division by a reducer of 2 is above the tolerance and fails the match, while the Reverse modes preserve the full magnitude and match cleanly. The mode choice therefore decides which side of this check a player lands on.

anticheat MovingListener and VelocityData (knockback feed)

MovingListener.java168 lines · Java
1
package me.vrekt.arc.listener.moving;
2
3
import me.vrekt.arc.Arc;
4
import me.vrekt.arc.check.CheckResult;
5
import me.vrekt.arc.check.CheckType;
6
import me.vrekt.arc.check.moving.Flight;
7
import me.vrekt.arc.check.moving.NoFall;
8
import me.vrekt.arc.check.moving.Speed;
9
import me.vrekt.arc.check.moving.compatibility.Flight17;
10
import me.vrekt.arc.check.moving.compatibility.Speed17;
11
import me.vrekt.arc.data.moving.MovingData;
12
import me.vrekt.arc.listener.ACheckListener;
13
import me.vrekt.arc.utilties.LocationHelper;
14
import org.bukkit.Location;
15
import org.bukkit.entity.Player;
16
import org.bukkit.event.EventHandler;
17
import org.bukkit.event.EventPriority;
18
import org.bukkit.event.Listener;
19
import org.bukkit.event.player.PlayerMoveEvent;
20
import org.bukkit.event.player.PlayerVelocityEvent;
21
22
public class MovingListener implements Listener, ACheckListener {
23
24
    private final Flight FLIGHT = (Flight) CHECK_MANAGER.getCheck(CheckType.FLIGHT);
25
    private final Flight17 FLIGHT_17 = (Flight17) CHECK_MANAGER.getCheck(CheckType.FLIGHT_17);
26
27
    private final NoFall NO_FALL = (NoFall) CHECK_MANAGER.getCheck(CheckType.NOFALL);
28
    private final Speed SPEED = (Speed) CHECK_MANAGER.getCheck(CheckType.SPEED);
29
    private final Speed17 SPEED_17 = (Speed17) CHECK_MANAGER.getCheck(CheckType.SPEED_17);
30
31
    @EventHandler(priority = EventPriority.LOWEST)
32
    public void onMove(PlayerMoveEvent event) {
33
        boolean compatibility = Arc.COMPATIBILITY;
34
35
        Player player = event.getPlayer();
36
        CheckResult result = new CheckResult();
37
        MovingData data = MovingData.getData(player);
38
39
        Location from = event.getFrom();
40
        Location to = event.getTo();
41
42
        data.setPreviousLocation(from);
43
        data.setCurrentLocation(to);
44
45
        // check if we have swapped worlds, if so stop here.
46
        if (from.getWorld() != to.getWorld()) {
47
            return;
48
        }
49
50
        // check if we have moved.
51
        boolean hasMoved = from.getX() != to.getX() || from.getY() != to.getY() || from.getZ() != to.getZ();
52
53
        // check if we have moved but only from block to another block.
54
        boolean hasMovedByBlock = from.getBlockX() != to.getBlockX() || from.getBlockY() != to.getBlockY()
55
                || from.getBlockZ() != to.getBlockZ();
56
57
        boolean canCheckFlight = CHECK_MANAGER.canCheckPlayer(player, CheckType.FLIGHT);
58
59
        if (hasMoved) {
60
            result.reset();
61
62
            // update our distances.
63
            double vertical = Math.abs(LocationHelper.distanceVertical(from, to));
64
            data.setLastVerticalSpeed(data.getVerticalSpeed());
65
            data.setVerticalSpeed(vertical);
66
67
            // recheck if we are on ground and set it.
68
            boolean prevGround = data.isOnGround();
69
            boolean onGround = LocationHelper.isOnGround(to, vertical);
70
            data.setOnGround(onGround);
71
            if (onGround) {
72
                data.setGroundLocation(to);
73
            }
74
75
            // update wasOnGround.
76
            boolean accAirTime = data.getAirTicks() < 20 && prevGround;
77
            data.setWasOnGround(accAirTime);
78
79
80
            // update ascending/descending.
81
            boolean ascending = to.getY() > from.getY() && vertical > 0.0;
82
            boolean descending = from.getY() > to.getY() && vertical > 0.0;
83
            data.setAscending(ascending);
84
            data.setDescending(descending);
85
86
            // check if we are climbing or not.
87
            data.setClimbing(LocationHelper.isClimbing(to));
88
89
            double velocity = player.getVelocity().length();
90
            data.getVelocityData().setLastVelocity(data.getVelocityData().getCurrentVelocity());
91
            data.getVelocityData().setCurrentVelocity(velocity);
92
93
            if (canCheckFlight) {
94
                // get the result and cancel if there is an alternate setback.
95
                CheckResult flightResult;
96
                if (compatibility) {
97
                    flightResult = FLIGHT_17.check(player, data);
98
                } else {
99
                    flightResult = FLIGHT.check(player, data);
100
                }
101
102
                result.set(flightResult.failed());
103
                if (result.failed()) {
104
                    if (flightResult.getCancelLocation() != null) {
105
                        event.setTo(flightResult.getCancelLocation());
106
                    } else {
107
                        event.setTo(data.getGroundLocation());
108
                    }
109
                }
110
            }
111
112
        }
113
114
115
        if (hasMovedByBlock) {
116
            result.reset();
117
            if (canCheckFlight) {
118
                // check based on compatibility
119
                CheckResult flightResult;
120
                if (compatibility) {
121
                    flightResult = FLIGHT_17.runBlockChecks(player, data);
122
                } else {
123
                    flightResult = FLIGHT.runBlockChecks(player, data);
124
                }
125
126
                // cancel if there is an alternate setback.
127
                result.set(flightResult.failed());
128
                if (result.failed()) {
129
                    if (flightResult.getCancelLocation() != null) {
130
                        event.setTo(flightResult.getCancelLocation());
131
                    } else {
132
                        event.setTo(data.getGroundLocation());
133
                    }
134
                }
135
136
            }
137
138
            boolean canCheckNoFall = CHECK_MANAGER.canCheckPlayer(player, CheckType.NOFALL);
139
            if (canCheckNoFall) {
140
                NO_FALL.check(player, data);
141
            }
142
143
            boolean canCheckSpeed = CHECK_MANAGER.canCheckPlayer(player, CheckType.SPEED);
144
            if (canCheckSpeed) {
145
                boolean failed;
146
                if (compatibility) {
147
                    failed = SPEED_17.check(player, data);
148
                } else {
149
                    failed = SPEED.check(player, data);
150
                }
151
152
                if (failed) {
153
                    event.setTo(data.getSetback());
154
                }
155
156
            }
157
        }
158
159
    }
160
161
    @EventHandler
162
    public void onVelocity(PlayerVelocityEvent event) {
163
        Player player = event.getPlayer();
164
        MovingData data = MovingData.getData(player);
165
        data.getVelocityData().addVelocityTime(event.getVelocity());
166
    }
167
168
}

How it counteracts this module

Arc v2 has no dedicated anti-knockback check in this snapshot, and its MovingListener is the honest evidence: onVelocity (line 165) stamps the knockback into VelocityData.addVelocityTime, and the movement checks consume that feed. Flight reads data.getVelocityData().hasVelocity() and the current and last velocity values, and only grants its vertical-move exemption while a knockback is recorded and the player is not on a step, climbing or in liquid; on landing it clears the velocity state. Speed uses the same feed to widen its horizontal expectation around a fresh knockback.

When the LiquidSense module cancels or rewrites the S12, Arc's listener never records the knockback, so Flight's validVerticalMove gate stays false and the post-hit motion is judged against the normal envelope with no knockback allowance. That is the honest mechanism of this entry: the pressure is not a velocity check flagging the cancel, it is the movement checks losing the exemption that a real knockback would have armed, which turns every cancelled hit into ordinary motion to be measured.

← Back to Analysis Hub