Spicy AntiKnockback module 1 files, 71 lines

Spicy AntiKnockback: Full Source Analysis

Spicy's AntiKnockback is a two-setting packet filter for incoming knockback, driven entirely from the pre-phase of EventPacket.

info/spicyclient/modules/movement/AntiKnockback.java · GitHub source ↗

Published 2026-08-13 · Updated 2026-08-13

Packets This Module Uses

Analysis

Overview

Spicy's AntiKnockback is a two-setting packet filter for incoming knockback, driven entirely from the pre-phase of EventPacket. Two NumberSettings - Horizontal Knockback and Vertical Knockback, both 0-100 defaulting to 0 - scale the components of the self-entity S12PacketEntityVelocity in place using integer fixed-point arithmetic: setMotionX((int)((motionX / 100) * horizontal)), setMotionY((int)((motionY / 100) * vertical)), setMotionZ((int)((motionZ / 100) * horizontal)). When both settings are 0 the packet is cancelled outright instead of scaled, so the default configuration removes all entity knockback. The handler also cancels every S27PacketExplosion unconditionally, removing explosion knockback entirely regardless of the settings. EventUpdate only updates the module's suffix text ('H: x V: y') for the module list. The module never touches outgoing packets, has no state beyond the two settings, and its onEnable/onDisable are empty.

Architecture

onEvent branches on event type. EventUpdate pre only writes additionalInformation from the two settings' current values, purely cosmetic. EventPacket pre casts to the Spicy EventPacket and tests the packet type: an S12PacketEntityVelocity is scaled or cancelled, an S27PacketExplosion is always cancelled, and anything else passes through untouched. There is no entity-id check - the module assumes the only S12 a client sees for itself matters, and because Spicy's event system delivers packets before they reach the client's vanilla handler, the rewrite or cancel is the last word before the client applies the velocity. The two settings live in the settings list with resetSettings() restoring the 0/0 defaults, and the module registers under the MOVEMENT category with no default keybind.

Scale-or-cancel semantics

The S12 branch rewrites the packet's fixed-point components with integer division: each component is divided by 100, multiplied by the corresponding percentage setting, and truncated back to int. At 100/100 the packet is rewritten to its own values (a no-op that still passes through), at 50/50 half knockback, and at 0/0 the module cancels the packet instead of sending a zeroed vector. Because the setting check uses equality with 0, partial configurations (e.g. 0 horizontal, 50 vertical) send a scaled packet rather than cancelling, which keeps the server's knockback bookkeeping from seeing a fully missing response. The S27 branch has no such subtlety: any explosion packet is dropped, so TNT, creeper and explosion-lag knockback never reach the client.

source AntiKnockback.java (module)

AntiKnockback.java71 lines · JavaOriginal ↗
1
package info.spicyclient.modules.movement;
2
3
import org.lwjgl.input.Keyboard;
4
5
import info.spicyclient.chatCommands.Command;
6
import info.spicyclient.events.Event;
7
import info.spicyclient.events.listeners.EventMotion;
8
import info.spicyclient.events.listeners.EventPacket;
9
import info.spicyclient.events.listeners.EventUpdate;
10
import info.spicyclient.modules.Module;
11
import info.spicyclient.settings.NumberSetting;
12
import net.minecraft.network.play.server.S12PacketEntityVelocity;
13
import net.minecraft.network.play.server.S27PacketExplosion;
14
import net.minecraft.util.MathHelper;
15
16
public class AntiKnockback extends Module {
17
	
18
	public NumberSetting horizontalKnockback = new NumberSetting("Horizontal Knockback", 0, 0, 100, 1);
19
	public NumberSetting verticalKnockback = new NumberSetting("Vertical Knockback", 0, 0, 100, 1);
20
	
21
	public AntiKnockback() {
22
		super("AntiKnockback", Keyboard.KEY_NONE, Category.MOVEMENT);
23
		resetSettings();
24
	}
25
	
26
	@Override
27
	public void resetSettings() {
28
		this.settings.clear();
29
		addSettings(horizontalKnockback, verticalKnockback);
30
	}
31
	
32
	public void onEnable() {
33
		
34
	}
35
	
36
	public void onDisable() {
37
		
38
	}
39
	
40
	public void onEvent(Event e) {
41
		
42
		if (e instanceof EventUpdate && e.isPre()) {
43
			this.additionalInformation = "H: " + horizontalKnockback.getValue() + " V: " + verticalKnockback.getValue();
44
		}
45
		
46
		if (e instanceof EventPacket && e.isPre()) {
47
			
48
			EventPacket event = (EventPacket) e;
49
			
50
			if (event.packet instanceof S12PacketEntityVelocity) {
51
				
52
				S12PacketEntityVelocity packet = (S12PacketEntityVelocity) event.packet;
53
				packet.setMotionX((int) ((packet.getMotionX() / 100) * horizontalKnockback.getValue()));
54
				packet.setMotionY((int) ((packet.getMotionY() / 100) * verticalKnockback.getValue()));
55
				packet.setMotionZ((int) ((packet.getMotionZ() / 100) * horizontalKnockback.getValue()));
56
				
57
				if (horizontalKnockback.getValue() == 0 && verticalKnockback.getValue() == 0) {
58
					e.setCanceled(true);
59
				}
60
				
61
				
62
			}
63
			else if (event.packet instanceof S27PacketExplosion) {
64
				e.setCanceled(true);
65
			}
66
			
67
		}
68
		
69
	}
70
	
71
}

What this file does

The whole module is this file: the two NumberSetting fields, the constructor wiring them into the settings list with resetSettings(), and the EventUpdate/EventPacket handlers. The EventPacket branch contains the S12 scale-or-cancel logic and the unconditional S27 cancel; there is no other interception point and no timer or state machine, which is the module's defining trait - it is a pure packet filter whose entire behavior is the two percentage settings. The integer arithmetic (motion / 100 * percentage) is the detail that matters to the countering checks below: partial settings produce truncated vectors that still differ from the server's recorded knockback.

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-velocity 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 is a PacketSendListener on ENTITY_VELOCITY that wraps the packet in a transaction sandwich: a transaction is sent before the velocity packet and a second one after it. The vector is recorded into firstBreadMap keyed by the first transaction id, and once the client echoes a larger transaction id - proof the packet reached the client - it is promoted into lastKnockbackKnownTaken. From that moment the vector is required movement: the prediction engine must reproduce it in the player's motion. onPredictionComplete compares the prediction offset against offsetToFlag (default 0.001) and set-backs at an offset of 0.1 or more. Knockbacks that arrive while Grim itself is sending a setback are recorded with isSetback and treated leniently.

Both Spicy configurations fail the requirement. At 0/0 the S12 is cancelled client-side, but the sandwich already confirmed delivery, so the required vector simply never appears in the predicted motion and the offset is the full knockback. At partial percentages the client rewrites the vector, which cannot change the record Grim read off the wire, so any reduction below 100% produces an offset above the 0.001 floor. The S27 cancel fails the same way through Grim's ExplosionHandler, and the isSetback leniency does not apply because Grim is not the one teleporting the player.

anticheat ExplosionHandler (required explosion knockback)

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 is the explosion twin of KnockbackHandler: it listens on the EXPLOSION packet send, stores the knockback vector in firstBreadMap (a deque of VelocityData), and once the client's transaction echo proves delivery it promotes the entry into lastExplosionsKnownTaken. The PostPredictionListener side then requires the predicted motion to consume that vector, flagging with the AntiExplosion check ('Did not take the expected explosion knockback', setback 10) when the offset exceeds the configured threshold. For versions below 1.21.2 it also derives knockback from the explosion's block-destruction changes.

Spicy's unconditional S27 cancellation is the direct target: the server sent the explosion packet, the sandwich confirmed it, and the client dropped it - so the required explosion vector is never taken, and the offset accumulates exactly as if the player had ignored entity knockback. Because the module cancels the S27 before the client's vanilla handler applies it, there is no partial-consumption window to hide in; the only escape would be eating the transaction echo so the entry stays in the uncertain firstBreadMap, which is a network-level attack the module does not perform.

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 MoveEvent keeps a pending knockback list per player and matches every move's delta against it. handlePendingVelocities compares the Y component within 0.01 (unless the player collides, jumps, swims or steps) and X/Z within maxDiscrepancy, which scales with the player's speed, sprint state and the weirdConstant surface modifier (0.098 on ground, 0.2518462 jump-sprinting, 0.0196 swimming). A pending entry older than ping + 200ms with no matching move sets failedKnockback, and AntiVelocityBasic.check punishes that at VL 5 with 'may be using anti-velocity (basic)'; the class comment claims detection down to a 10% difference.

At 0/0 the cancelled S12 leaves the entry unmatched forever and it expires into a flag. At partial percentages the match window is the test: the scaled remainder must land inside maxDiscrepancy, and per the check's 10% claim a reduction beyond roughly 10% of the vector falls outside and flags; the integer truncation of the module's arithmetic pushes marginal percentages below the window. The module's own motion after the hit is vanilla (no extra input), so there is no compensating motion to satisfy the matcher - the entry ages out with failedKnockback set.

anticheat UnusedVelocity (unused knockback ledger)

UnusedVelocity.java87 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.moving.player;
16
17
import org.bukkit.entity.Player;
18
19
import fr.neatmonster.nocheatplus.checks.CheckType;
20
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
21
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
22
import fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleAxisVelocity;
23
import fr.neatmonster.nocheatplus.checks.moving.velocity.UnusedTracker;
24
import fr.neatmonster.nocheatplus.logging.debug.DebugUtil;
25
import fr.neatmonster.nocheatplus.players.IPlayerData;
26
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
27
28
public class UnusedVelocity {
29
    
30
    // TODO: Currently is debug only (!). Only call if some debug flag is set. Needs checks.moving.debug to work at all.
31
32
    /**
33
     * Test if any unused velocity has been tracked and what that means. (Convenience.)
34
     * 
35
     * @param player
36
     * @return If the player has failed the check, whatever that means.
37
     */
38
    public static boolean checkUnusedVelocity(final Player player, 
39
            final CheckType checkType, final IPlayerData pData) {
40
        return checkUnusedVelocity(
41
                player, checkType, 
42
                pData.getGenericInstance(MovingData.class), 
43
                pData.getGenericInstance(MovingConfig.class)
44
                );
45
    }
46
47
48
    /**
49
     * Test if any unused velocity has been tracked and what that means.
50
     * 
51
     * @param player
52
     * @param data
53
     * @param cc
54
     * @return If the player has failed the check, whatever that means.
55
     */
56
    public static boolean checkUnusedVelocity(final Player player, 
57
            final CheckType checkType, final MovingData data, final MovingConfig cc) {
58
        boolean violation = false;
59
        final SimpleAxisVelocity verVel = data.getVerticalVelocityTracker();
60
        violation |= quickCheckDirection(player, verVel.unusedTrackerPos, checkType, "vert/pos", data, cc);
61
        violation |= quickCheckDirection(player, verVel.unusedTrackerNeg, checkType, "vert/neg", data, cc);
62
        return violation;
63
    }
64
65
    /**
66
     * Quick check tracker for one direction.
67
     * @param player
68
     * @param checkType 
69
     * @param unusedTrackerPos
70
     * @param string
71
     * @param data
72
     * @param cc
73
     */
74
    private static boolean quickCheckDirection(final Player player, 
75
            final UnusedTracker tracker, final CheckType checkType, final String trackerId ,
76
            MovingData data, MovingConfig cc) {
77
        final int countV = tracker.getResultViolationCount();
78
        if (countV > 0) {
79
            String msg = "Unused velocity " + trackerId + ": c_v: " + countV + " , a_v: " + tracker.getResultViolationAmount() + " , c_u: " + tracker.getResultUpdateCount();
80
            DebugUtil.debug(CheckUtils.getLogMessagePrefix(player, checkType) + msg);
81
        }
82
        tracker.resetResults(); // Reset for now.
83
        // TODO: A real check, e.g. track frequency and/or average amount of violation per so and so time.
84
        return false; // Player can't possibly fail this yet.
85
    }
86
87
}

How it counteracts this module

NCP's movement model queues the vertical velocity the server applied and later consumes it to explain the player's actual movement. checkUnusedVelocity reads the pos and neg UnusedTracker instances of the SimpleAxisVelocity vertical tracker; UnusedTracker.addValue records a violation amount only when the direction has been blocked since the entry was added - i.e. the server pushed velocity in a direction the player never moved - and quickCheckDirection reports the violation count, accumulated amount and update count before resetting the results.

In this build the check is a debug ledger: quickCheckDirection logs through DebugUtil and returns false with a TODO for a real frequency or amount check, so the player cannot fail it yet - the honest framing is that NCP's velocity queue model is what would expose the module once the check is enabled. At 0/0 the cancelled S12 leaves the vertical push un-consumed (the client never moves along it), so the tracker accumulates; at partial settings the scaled vertical motion is a partial consumption and the horizontal rewrite leaves the horizontal component outside what the vertical tracker models. As shipped, an AntiKnockback user faces NCP's SurvivalFly envelope, not this check.

← Back to Analysis Hub