LiquidSense Dev FastPlace module 2 files, 295 lines

LiquidSense Dev FastPlace: Full Source Analysis

LiquidSense Dev's FastPlace is a value holder whose consumption lives in the client's Minecraft mixin.

net/ccbluex/liquidbounce/features/module/modules/world/FastPlace.kt · GitHub source ↗

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

Packets This Module Uses

Analysis

Overview

LiquidSense Dev's FastPlace is a value holder whose consumption lives in the client's Minecraft mixin. The module class carries a single IntegerValue named Speed (default 0, range 0 to 4) and no logic of its own; MixinMinecraft shadows the vanilla rightClickDelayTimer field and injects into rightClickMouse immediately after vanilla writes its 4-tick cooldown, overwriting the timer with the module's speed value whenever the module is enabled. At speed 0 the timer reads zero after every right-click, so the run-tick held-use gate passes every tick and a held right click fires at the 20 per second tick rate; at higher speeds the timer is only clamped down to the configured value.

The holder

The module is 16 lines: the ModuleInfo declaration under ModuleCategory.WORLD and a single IntegerValue field, speedValue, with name 'Speed', default 0 and range 0 to 4. There is no onEnable, no event handler and no packet code. LiquidBounce modules of this era defer their behavior to the mixin layer, and FastPlace is the canonical example: the value is read from the module object by name (LiquidBounce.moduleManager.getModule(FastPlace.class)) at the injection site, so the module file itself is only the setting surface.

The mixin injection

MixinMinecraft declares a shadow field for the vanilla rightClickDelayTimer, and an injection on rightClickMouse targeting the FIELD write to that field with shift AFTER runs the replacement logic at the exact point vanilla has just stored its 4-tick cooldown. The injected body registers the click with the CPSCounter, looks up the FastPlace module, and when the module state is enabled writes rightClickDelayTimer = fastPlace.getSpeedValue().get(), so every click action carries the reduced timer instead of 4.

Vanilla's gate then does the rest: the run-tick loop decrements the timer once per tick and only fires the held-use branch while it reads exactly 0. With the value at 0, each tick's poll passes and a held right click fires every tick (20 per second); with the value at 2, the timer drops to 2 after each click and the 2-tick wait halves the rate. The same gate and timer touchpoints are stock 1.8.9 (rightClickMouse writes 4, decrement once per tick, held-use at 0), verified in the shared MCP sources.

Wire effect

The accelerated clicks emit a denser C08PacketPlayerBlockPlacement stream with untouched payloads: real placements carry position, facing and stack exactly like vanilla, so the only server-visible fingerprint is the inter-placement interval collapsing from the 200ms vanilla grid toward 50ms. The gate governs item use too, so the module also speeds food and bow interaction when the player holds anything else, producing the use-item C08 form (origin position, facing 255) and, for consumables, the C07 release pair.

source FastPlace.kt

FastPlace.kt16 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.world
7
8
import net.ccbluex.liquidbounce.features.module.Module
9
import net.ccbluex.liquidbounce.features.module.ModuleCategory
10
import net.ccbluex.liquidbounce.features.module.ModuleInfo
11
import net.ccbluex.liquidbounce.value.IntegerValue
12
13
@ModuleInfo(name = "FastPlace", description = "Allows you to place blocks faster.", category = ModuleCategory.WORLD)
14
class FastPlace : Module() {
15
    val speedValue = IntegerValue("Speed", 0, 0, 4)
16
}

What this file does

The module is the setting surface: the ModuleInfo declaration registers it under ModuleCategory.WORLD with the description 'Allows you to place blocks faster.', and the only member is speedValue, an IntegerValue named 'Speed' with default 0 and range 0 to 4. No handler exists in the class; the value is consumed entirely by the Minecraft mixin, which reads it through LiquidBounce.moduleManager.getModule(FastPlace.class) when the module is enabled.

This is the classic LiquidBounce split: Kotlin modules are thin declarations and the Forge mixin layer carries the behavior, so the analysis of the module's effect has to follow the value into MixinMinecraft rather than stop at this file.

source MixinMinecraft.java (the timer write)

MixinMinecraft.java279 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.injection.forge.mixins.client;
7
8
import net.ccbluex.liquidbounce.LiquidBounce;
9
import net.ccbluex.liquidbounce.event.*;
10
import net.ccbluex.liquidbounce.features.module.modules.combat.AutoClicker;
11
import net.ccbluex.liquidbounce.features.module.modules.exploit.AbortBreaking;
12
import net.ccbluex.liquidbounce.features.module.modules.world.ChestStealer;
13
import net.ccbluex.liquidbounce.features.module.modules.world.FastPlace;
14
import net.ccbluex.liquidbounce.ui.client.GuiMainMenu;
15
import net.ccbluex.liquidbounce.ui.client.GuiUpdate;
16
import net.ccbluex.liquidbounce.ui.client.GuiWelcome;
17
import net.ccbluex.liquidbounce.utils.CPSCounter;
18
import net.ccbluex.liquidbounce.utils.render.IconUtils;
19
import net.ccbluex.liquidbounce.utils.render.RenderUtils;
20
import net.minecraft.block.material.Material;
21
import net.minecraft.client.Minecraft;
22
import net.minecraft.client.entity.EntityPlayerSP;
23
import net.minecraft.client.gui.GuiGameOver;
24
import net.minecraft.client.gui.GuiScreen;
25
import net.minecraft.client.gui.ScaledResolution;
26
import net.minecraft.client.gui.inventory.GuiChest;
27
import net.minecraft.client.multiplayer.PlayerControllerMP;
28
import net.minecraft.client.multiplayer.WorldClient;
29
import net.minecraft.client.particle.EffectRenderer;
30
import net.minecraft.client.settings.GameSettings;
31
import net.minecraft.client.settings.KeyBinding;
32
import net.minecraft.util.BlockPos;
33
import net.minecraft.util.MouseHelper;
34
import net.minecraft.util.MovingObjectPosition;
35
import net.minecraft.util.Util;
36
import net.minecraftforge.client.event.GuiOpenEvent;
37
import net.minecraftforge.common.MinecraftForge;
38
import net.minecraftforge.fml.relauncher.Side;
39
import net.minecraftforge.fml.relauncher.SideOnly;
40
import org.lwjgl.Sys;
41
import org.lwjgl.input.Keyboard;
42
import org.lwjgl.opengl.Display;
43
import org.spongepowered.asm.mixin.Mixin;
44
import org.spongepowered.asm.mixin.Overwrite;
45
import org.spongepowered.asm.mixin.Shadow;
46
import org.spongepowered.asm.mixin.injection.At;
47
import org.spongepowered.asm.mixin.injection.Inject;
48
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
49
50
import java.nio.ByteBuffer;
51
import java.util.Arrays;
52
53
@Mixin(Minecraft.class)
54
@SideOnly(Side.CLIENT)
55
public abstract class MixinMinecraft {
56
57
    @Shadow
58
    public GuiScreen currentScreen;
59
60
    @Shadow
61
    public boolean skipRenderWorld;
62
63
64
    @Shadow
65
    private int leftClickCounter;
66
67
    @Shadow
68
    public MovingObjectPosition objectMouseOver;
69
70
    @Shadow
71
    public WorldClient theWorld;
72
73
    @Shadow
74
    public EntityPlayerSP thePlayer;
75
76
    @Shadow
77
    public EffectRenderer effectRenderer;
78
79
    @Shadow
80
    public PlayerControllerMP playerController;
81
82
    @Shadow
83
    public int displayWidth;
84
85
    @Shadow
86
    public int displayHeight;
87
88
    @Shadow
89
    public int rightClickDelayTimer;
90
91
    @Shadow
92
    public GameSettings gameSettings;
93
94
    @Shadow
95
    public boolean inGameHasFocus;
96
97
    /*
98
    @Shadow
99
    public abstract void setIngameNotInFocus();
100
101
     */
102
103
    @Shadow
104
    public MouseHelper mouseHelper;
105
106
    @Shadow
107
    public abstract void setIngameFocus();
108
109
    @Overwrite
110
    public void setIngameNotInFocus() {
111
        if (this.inGameHasFocus) {
112
            KeyBinding.unPressAllKeys();
113
            this.inGameHasFocus = false;
114
            this.mouseHelper.ungrabMouseCursor();
115
        }
116
117
118
    }
119
120
    @Inject(method = "run", at = @At("HEAD"))
121
    private void init(CallbackInfo callbackInfo) {
122
        if(displayWidth < 1067)
123
            displayWidth = 1067;
124
125
        if(displayHeight < 622)
126
            displayHeight = 622;
127
    }
128
129
    @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;checkGLError(Ljava/lang/String;)V", ordinal = 2, shift = At.Shift.AFTER))
130
    private void startGame(CallbackInfo callbackInfo) {
131
        LiquidBounce.INSTANCE.startClient();
132
    }
133
134
    @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;displayGuiScreen(Lnet/minecraft/client/gui/GuiScreen;)V", shift = At.Shift.AFTER))
135
    private void afterMainScreen(CallbackInfo callbackInfo) {
136
          //Minecraft.getMinecraft().displayGuiScreen(new GuiWelcome());
137
//        else if (LiquidBounce.INSTANCE.getLatestVersion() > LiquidBounce.CLIENT_VERSION - (LiquidBounce.IN_DEV ? 1 : 0))
138
//            Minecraft.getMinecraft().displayGuiScreen(new GuiUpdate());
139
    }
140
141
    @Inject(method = "createDisplay", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/Display;setTitle(Ljava/lang/String;)V", shift = At.Shift.AFTER))
142
    private void createDisplay(CallbackInfo callbackInfo) {
143
        Display.setTitle(LiquidBounce.CLIENT_NAME + " | " + LiquidBounce.CLIENT_VERSION + " | " + "By AquaVit" + " | " + LiquidBounce.MINECRAFT_VERSION + " | Injection...");
144
    }
145
146
    @Inject(method = "displayGuiScreen", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;currentScreen:Lnet/minecraft/client/gui/GuiScreen;", shift = At.Shift.AFTER))
147
    private void displayGuiScreen(CallbackInfo callbackInfo) {
148
        if(currentScreen instanceof net.minecraft.client.gui.GuiMainMenu || (currentScreen != null && currentScreen.getClass().getName().startsWith("net.labymod") && currentScreen.getClass().getSimpleName().equals("ModGuiMainMenu"))) {
149
            currentScreen = new GuiMainMenu();
150
151
            ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
152
            currentScreen.setWorldAndResolution(Minecraft.getMinecraft(), scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight());
153
            skipRenderWorld = false;
154
        }
155
156
        LiquidBounce.eventManager.callEvent(new ScreenEvent(currentScreen));
157
    }
158
159
    private long lastFrame = getTime();
160
161
    @Inject(method = "runGameLoop", at = @At("HEAD"))
162
    private void runGameLoop(final CallbackInfo callbackInfo) {
163
        final long currentTime = getTime();
164
        final int deltaTime = (int) (currentTime - lastFrame);
165
        lastFrame = currentTime;
166
167
        RenderUtils.deltaTime = deltaTime;
168
    }
169
170
    public long getTime() {
171
        return (Sys.getTime() * 1000) / Sys.getTimerResolution();
172
    }
173
174
    @Inject(method = "runTick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;joinPlayerCounter:I", shift = At.Shift.BEFORE))
175
    private void onTick(final CallbackInfo callbackInfo) {
176
        LiquidBounce.eventManager.callEvent(new TickEvent());
177
    }
178
179
    @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;dispatchKeypresses()V", shift = At.Shift.AFTER))
180
    private void onKey(CallbackInfo callbackInfo) {
181
        if(Keyboard.getEventKeyState() && currentScreen == null)
182
            LiquidBounce.eventManager.callEvent(new KeyEvent(Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey()));
183
    }
184
185
    @Inject(method = "sendClickBlockToController", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MovingObjectPosition;getBlockPos()Lnet/minecraft/util/BlockPos;"))
186
    private void onClickBlock(CallbackInfo callbackInfo) {
187
        if(this.leftClickCounter == 0 && theWorld.getBlockState(objectMouseOver.getBlockPos()).getBlock().getMaterial() != Material.air) {
188
            LiquidBounce.eventManager.callEvent(new ClickBlockEvent(objectMouseOver.getBlockPos(), this.objectMouseOver.sideHit));
189
        }
190
    }
191
192
    @Inject(method = "setWindowIcon", at = @At("HEAD"), cancellable = true)
193
    private void setWindowIcon(CallbackInfo callbackInfo) {
194
        if(Util.getOSType() != Util.EnumOS.OSX) {
195
            final ByteBuffer[] liquidBounceFavicon = IconUtils.getFavicon();
196
            if(liquidBounceFavicon != null) {
197
198
                Display.setIcon(liquidBounceFavicon);
199
                callbackInfo.cancel();
200
            }
201
        }
202
    }
203
204
    @Inject(method = "shutdown", at = @At("HEAD"))
205
    private void shutdown(CallbackInfo callbackInfo) {
206
        try{
207
            LiquidBounce.INSTANCE.stopClient();
208
        }catch (Exception e){
209
            System.exit(0);
210
        }
211
    }
212
213
    @Inject(method = "clickMouse", at = @At("HEAD"))
214
    private void clickMouse(CallbackInfo callbackInfo) {
215
216
        CPSCounter.registerClick(CPSCounter.MouseButton.LEFT);
217
218
        if (LiquidBounce.moduleManager.getModule(AutoClicker.class).getState())
219
            leftClickCounter = 0;
220
    }
221
222
    @Inject(method = "middleClickMouse", at = @At("HEAD"))
223
    private void middleClickMouse(CallbackInfo ci) {
224
        CPSCounter.registerClick(CPSCounter.MouseButton.MIDDLE);
225
    }
226
227
228
    @Inject(method = "rightClickMouse", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;rightClickDelayTimer:I", shift = At.Shift.AFTER))
229
    private void rightClickMouse(final CallbackInfo callbackInfo) {
230
        CPSCounter.registerClick(CPSCounter.MouseButton.RIGHT);
231
232
        final FastPlace fastPlace = (FastPlace) LiquidBounce.moduleManager.getModule(FastPlace.class);
233
234
        if (fastPlace.getState())
235
            rightClickDelayTimer = fastPlace.getSpeedValue().get();
236
    }
237
238
    @Inject(method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", at = @At("HEAD"))
239
    private void loadWorld(WorldClient p_loadWorld_1_, String p_loadWorld_2_, final CallbackInfo callbackInfo) {
240
        LiquidBounce.eventManager.callEvent(new WorldEvent(p_loadWorld_1_));
241
    }
242
243
    /**
244
     * @author CCBlueX
245
     */
246
    @Overwrite
247
    private void sendClickBlockToController(boolean leftClick) {
248
        if(!leftClick)
249
            this.leftClickCounter = 0;
250
251
        if (this.leftClickCounter <= 0 && (!this.thePlayer.isUsingItem())) {
252
            if(leftClick && this.objectMouseOver != null && this.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
253
                BlockPos blockPos = this.objectMouseOver.getBlockPos();
254
255
                if(this.leftClickCounter == 0)
256
                    LiquidBounce.eventManager.callEvent(new ClickBlockEvent(blockPos, this.objectMouseOver.sideHit));
257
258
259
                if(this.theWorld.getBlockState(blockPos).getBlock().getMaterial() != Material.air && this.playerController.onPlayerDamageBlock(blockPos, this.objectMouseOver.sideHit)) {
260
                    this.effectRenderer.addBlockHitEffects(blockPos, this.objectMouseOver.sideHit);
261
                    this.thePlayer.swingItem();
262
                }
263
            } else if (!LiquidBounce.moduleManager.getModule(AbortBreaking.class).getState()) {
264
                this.playerController.resetBlockRemoving();
265
            }
266
267
268
269
        }
270
    }
271
272
    /**
273
     * @author
274
     */
275
    @Overwrite
276
    public int getLimitFramerate() {
277
        return this.theWorld == null && this.currentScreen != null ? 60 : this.gameSettings.limitFramerate;
278
    }
279
}

What this file does

The mechanism file. Line 89 shadows the vanilla field with @Shadow public int rightClickDelayTimer, and the rightClickMouse injection (line 228) targets the FIELD write to that field with shift AFTER, so the injected code runs right after vanilla stores its 4-tick cooldown. The body registers the click with CPSCounter and, when the FastPlace module is enabled, overwrites the timer with the module's speed value (line 235).

The same mixin file carries the client's other Minecraft hooks (middleClickMouse click counting, the loadWorld event), which is why the FastPlace behavior sits in the shared Minecraft mixin rather than in the module package.

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 FastPlace (placement-rate window)

FastPlace.java103 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.blockplace;
16
17
import org.bukkit.block.Block;
18
import org.bukkit.entity.Player;
19
20
import fr.neatmonster.nocheatplus.checks.Check;
21
import fr.neatmonster.nocheatplus.checks.CheckType;
22
import fr.neatmonster.nocheatplus.players.IPlayerData;
23
import fr.neatmonster.nocheatplus.utilities.TickTask;
24
25
/**
26
 * A check used to verify if the player isn't placing blocks too quickly.
27
 */
28
public class FastPlace extends Check {
29
30
    /**
31
     * Instantiates a new fast place check.
32
     */
33
    public FastPlace() {
34
        super(CheckType.BLOCKPLACE_FASTPLACE);
35
    }
36
37
    /**
38
     * Checks a player.
39
     * 
40
     * @param player
41
     *            the player
42
     * @param block
43
     *            the block
44
     * @param tick
45
     * @param data
46
     * @param cc
47
     * @param pData
48
     * @return true, if successful
49
     */
50
    public boolean check(final Player player, final Block block, final int tick, final BlockPlaceData data, 
51
                         final BlockPlaceConfig cc, final IPlayerData pData) {
52
53
        data.fastPlaceBuckets.add(System.currentTimeMillis(), 1f);
54
        final boolean lag = pData.getCurrentWorldData().shouldAdjustToLag(type);
55
        // Full period frequency.
56
        final float fullScore = data.fastPlaceBuckets.score(1f);
57
58
        // Short term limit.
59
        if (tick < data.fastPlaceShortTermTick) {
60
            // TickTask got reset.
61
            data.fastPlaceShortTermTick = tick;
62
            data.fastPlaceShortTermCount = 1;
63
        }
64
        else if (tick - data.fastPlaceShortTermTick < cc.fastPlaceShortTermTicks) {
65
            // Account for server side lag.
66
            if (!lag || TickTask.getLag(50L * (tick - data.fastPlaceShortTermTick), true) < 1.2f) {
67
                // Within range, add.
68
                data.fastPlaceShortTermCount ++;
69
            }
70
            else {
71
                // Too much lag, reset.
72
                data.fastPlaceShortTermTick = tick;
73
                data.fastPlaceShortTermCount = 1;
74
            }
75
        }
76
        else { 
77
            data.fastPlaceShortTermTick = tick;
78
            data.fastPlaceShortTermCount = 1;
79
        }
80
81
        // Find out if one of both are violations:
82
        final float fullViolation;
83
        if (fullScore > cc.fastPlaceLimit) {
84
            // Account for server side lag.
85
            fullViolation = lag ? fullScore / TickTask.getLag(data.fastPlaceBuckets.bucketDuration() * data.fastPlaceBuckets.numberOfBuckets(), true) - cc.fastPlaceLimit
86
                                : fullScore - cc.fastPlaceLimit;
87
        }
88
        else fullViolation = 0;
89
        final float shortTermViolation = data.fastPlaceShortTermCount - cc.fastPlaceShortTermLimit; 
90
        final float violation = Math.max(fullViolation, shortTermViolation);
91
        boolean cancel = false;
92
93
        if (violation > 0.0) {
94
            final double change = (double) violation;
95
            data.fastPlaceVL += change;
96
            cancel = executeActions(player, data.fastPlaceVL, change, cc.fastPlaceActions).willCancel();
97
        }
98
        else if (data.fastPlaceVL > 0D && fullScore < cc.fastPlaceLimit * .75) {
99
            data.fastPlaceVL *= 0.95;
100
        }
101
        return cancel;
102
    }
103
}

How it counteracts this module

NCP's placement-rate check scores every real placement. BlockPlaceListener invokes FastPlace.check from the Bukkit BlockPlaceEvent path, and each invocation adds 1f into data.fastPlaceBuckets, an ActionFrequency(2, 1000) pair of half-second buckets (BlockPlaceData line 53). The window score is compared against cc.fastPlaceLimit, 15 placements per second by default, and a short-term tick counter separately caps 6 placements inside 10 ticks (fastPlaceShortTermLimit and fastPlaceShortTermTicks, lines 59-89 of the check). The violation is the larger of the two excesses, and the default actions start cancelling from vl 5 and escalate to a kick.

The mixin at speed 0 sustains up to 20 placements per second, so the window score sits above 15 and the short-term counter reaches 10 inside 10 ticks: both paths trip. The check only fires through the BlockPlaceEvent path, so the accelerated item-use C08s (facing 255, air coordinates) never reach it; the pressure lands on real block placements, which is exactly the surface the module accelerates when the player holds a block.

anticheat Direction (facing validation)

Direction.java52 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.blockplace;
16
17
import org.bukkit.entity.Player;
18
19
import fr.neatmonster.nocheatplus.actions.ActionList;
20
import fr.neatmonster.nocheatplus.checks.CheckType;
21
import fr.neatmonster.nocheatplus.checks.generic.block.AbstractBlockDirectionCheck;
22
23
/**
24
 * The Direction check will find out if a player tried to interact with
25
 * something that's not in their field of view.
26
 */
27
public class Direction extends AbstractBlockDirectionCheck<BlockPlaceData, BlockPlaceConfig> {
28
29
    /**
30
     * Instantiates a new direction check.
31
     */
32
    public Direction() {
33
        super(CheckType.BLOCKPLACE_DIRECTION);
34
    }
35
36
    @Override
37
    protected double addVL(Player player, double distance, BlockPlaceData data, BlockPlaceConfig cc) {
38
        data.directionVL += distance;
39
        return data.directionVL;
40
    }
41
42
    @Override
43
    protected ActionList getActions(BlockPlaceConfig cc) {
44
        return cc.directionActions;
45
    }
46
47
    @Override
48
    protected void cooldown(Player player, BlockPlaceData data, BlockPlaceConfig cc) {
49
        data.directionVL *= 0.9D;
50
    }
51
52
}

How it counteracts this module

The placement-direction check extends AbstractBlockDirectionCheck and scores the angular distance between the placement's claimed facing and the player's actual look direction, accumulating blockplace VL with a per-hit cooldown. A single placement with an honest facing passes; the check matters as the companion to the rate window because a placement stream that has to track a moving cursor forces look updates that lag the packets, and the sustained mismatch is what accumulates.

Standing-still fast place is invisible to it: the module places straight ahead of the cursor with correct facings, so Direction only contributes when the accelerated stream is combined with strafing or scaffold-style placement, where the cursor moves faster than the look can follow. On its own the rate window does the real work against this module.

anticheat UseItemAdapter (item-use classification and release gate)

UseItemAdapter.java438 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.net.protocollib;
16
17
import java.util.Arrays;
18
import java.util.LinkedList;
19
import java.util.List;
20
21
import org.bukkit.GameMode;
22
import org.bukkit.Material;
23
import org.bukkit.entity.HumanEntity;
24
import org.bukkit.entity.Player;
25
import org.bukkit.event.Event;
26
import org.bukkit.event.EventHandler;
27
import org.bukkit.event.EventPriority;
28
import org.bukkit.event.block.Action;
29
import org.bukkit.event.entity.PlayerDeathEvent;
30
import org.bukkit.event.inventory.InventoryOpenEvent;
31
import org.bukkit.event.player.PlayerInteractEvent;
32
import org.bukkit.event.player.PlayerItemConsumeEvent;
33
import org.bukkit.event.player.PlayerItemHeldEvent;
34
import org.bukkit.event.player.PlayerRespawnEvent;
35
import org.bukkit.event.player.PlayerRiptideEvent;
36
import org.bukkit.inventory.EquipmentSlot;
37
import org.bukkit.inventory.ItemStack;
38
import org.bukkit.inventory.meta.CrossbowMeta;
39
import org.bukkit.plugin.Plugin;
40
41
import com.comphenix.protocol.PacketType;
42
import com.comphenix.protocol.events.ListenerPriority;
43
import com.comphenix.protocol.events.PacketContainer;
44
import com.comphenix.protocol.events.PacketEvent;
45
import com.comphenix.protocol.reflect.StructureModifier;
46
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType;
47
48
import fr.neatmonster.nocheatplus.NCPAPIProvider;
49
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
50
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
51
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
52
import fr.neatmonster.nocheatplus.compat.Bridge1_13;
53
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
54
import fr.neatmonster.nocheatplus.compat.bukkit.BridgeEnchant;
55
import fr.neatmonster.nocheatplus.compat.bukkit.BridgeMaterial;
56
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
57
import fr.neatmonster.nocheatplus.compat.versions.ClientVersion;
58
import fr.neatmonster.nocheatplus.compat.versions.ServerVersion;
59
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
60
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
61
import fr.neatmonster.nocheatplus.event.mini.MiniListener;
62
import fr.neatmonster.nocheatplus.logging.StaticLog;
63
import fr.neatmonster.nocheatplus.players.DataManager;
64
import fr.neatmonster.nocheatplus.players.IPlayerData;
65
import fr.neatmonster.nocheatplus.utilities.entity.InventoryUtil;
66
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
67
import fr.neatmonster.nocheatplus.utilities.map.MaterialUtil;
68
69
/**
70
 * <p>Adapter for listening to packets and Bukkit events relevant to item use.</p>
71
 *
72
 * On versions 1.17 and above, the adapter will only register events related to a specific item-use exploit, 
73
 * as Bukkit provides the {@link HumanEntity#getItemInUse()} method.<br>
74
 *
75
 * <p>On versions 1.12 and above, up to 1.17, all listeners will be registered because Bukkit does not offer a way to 
76
 * determine <em>which</em> item is in use; we can only detect if a player is using an item through {@link HumanEntity#isHandRaised()}.</p>
77
 *
78
 * The {@link PlayerRespawnEvent} is always listened to in order to fix a specific item desynchronization issue.
79
 */
80
public class UseItemAdapter extends BaseAdapter {
81
    
82
    private final static String dftag = "system.nocheatplus.useitemadapter";
83
        
84
    // All relevant Bukkit events for item-use.
85
    private final static MiniListener<?>[] miniListeners = new MiniListener<?>[] {
86
        new MiniListener<PlayerItemConsumeEvent>() {
87
            @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
88
            @RegisterMethodWithOrder(tag = dftag)
89
            @Override
90
            public void onEvent(final PlayerItemConsumeEvent event) {
91
                onItemConsume(event);
92
            }
93
        },
94
        new MiniListener<PlayerInteractEvent>() {
95
            @EventHandler(priority = EventPriority.MONITOR)
96
            @RegisterMethodWithOrder(tag = dftag)
97
            @Override
98
            public void onEvent(final PlayerInteractEvent event) {
99
                onItemInteract(event);
100
            }
101
        },
102
        new MiniListener<InventoryOpenEvent>() {
103
            @EventHandler(priority = EventPriority.LOWEST)
104
            @RegisterMethodWithOrder(tag = dftag)
105
            @Override
106
            public void onEvent(final InventoryOpenEvent event) {
107
                onInventoryOpen(event);
108
            }
109
        },
110
        new MiniListener<PlayerDeathEvent>() {
111
            @EventHandler(priority = EventPriority.MONITOR)
112
            @RegisterMethodWithOrder(tag = dftag)
113
            @Override
114
            public void onEvent(final PlayerDeathEvent event) {
115
                onDeath(event);
116
            }
117
        },
118
        new MiniListener<PlayerItemHeldEvent>() {
119
            @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
120
            @RegisterMethodWithOrder(tag = dftag)
121
            @Override
122
            public void onEvent(final PlayerItemHeldEvent event) {
123
                onChangeSlot(event);
124
            }
125
        },
126
    };
127
128
    private static int timeBetweenRL = 70;
129
130
    private static PacketType[] initPacketTypes() {
131
        // Only interested in these two packets.
132
        final List<PacketType> types = new LinkedList<PacketType>(Arrays.asList(PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.BLOCK_PLACE));
133
        return types.toArray(new PacketType[types.size()]);
134
    }
135
136
    public UseItemAdapter(Plugin plugin) {
137
        super(plugin, ListenerPriority.MONITOR, initPacketTypes());
138
        final NoCheatPlusAPI api = NCPAPIProvider.getNoCheatPlusAPI();
139
        if (!BridgeMisc.hasGetItemInUseMethod()) {
140
            // getItemInUse() isn't there, register all events
141
            if (Bridge1_13.hasPlayerRiptideEvent()) {
142
                // Only register this one if available.
143
                final MiniListener<?> riptideListener = new MiniListener<PlayerRiptideEvent>() {
144
                    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
145
                    @RegisterMethodWithOrder(tag = dftag)
146
                    @Override
147
                    public void onEvent(final PlayerRiptideEvent event) {
148
                        onTridentRelease(event);
149
                   }
150
                };
151
                api.addComponent(riptideListener, false);
152
            }
153
            // ...All the other listeners
154
            for (final MiniListener<?> listener : miniListeners) {
155
                api.addComponent(listener, false);
156
            }
157
        }
158
        // Always register this event, because it is used to fix an MC/Bukkit glitch, not for item-use setting.
159
        final MiniListener<?> respawningListener = new MiniListener<PlayerRespawnEvent>() {
160
            @EventHandler(priority = EventPriority.MONITOR)
161
            @RegisterMethodWithOrder(tag = dftag)
162
            @Override
163
            public void onEvent(final PlayerRespawnEvent event) {
164
                onRespawning(event);
165
            }
166
        };
167
        api.addComponent(respawningListener, false);
168
    }
169
170
    @Override
171
    public void onPacketReceiving(final PacketEvent event) {
172
        // Fast return tests first.
173
        try {
174
            if (event.isPlayerTemporary()) return;
175
        } 
176
        catch (NoSuchMethodError e) {
177
            if (event.getPlayer() == null) {
178
                counters.add(ProtocolLibComponent.idNullPlayer, 1);
179
                return;
180
            }
181
            if (DataManager.getPlayerDataSafe(event.getPlayer()) == null) {
182
                StaticLog.logWarning("Failed to fetch player data with " + event.getPacketType() + " for: " + event.getPlayer().toString());
183
                return;
184
            }
185
        }
186
        if (BridgeMisc.hasGetItemInUseMethod()) {
187
            // getItemInUse() is already there. Only check the digging packet for exploitation prevention purposes.
188
            if (event.getPacketType().equals(PacketType.Play.Client.BLOCK_DIG)) {
189
                handleDiggingPacket(event);
190
            }
191
            // Don't need to do anything else.
192
            return;
193
        }
194
        
195
        // getItemInUse() ins't there: do the ordinary stuff.
196
        if (event.getPacketType().equals(PacketType.Play.Client.BLOCK_DIG)) {
197
            handleDiggingPacket(event);
198
        }
199
        else handleBlockPlacePacket(event);
200
    }
201
    
202
    /** Attempt to fix server-side-only blocking after respawn. */
203
    private static void onRespawning(final PlayerRespawnEvent e) {
204
        final IPlayerData pData = DataManager.getPlayerData(e.getPlayer());
205
        // Patch up issues on Bukkit's (Minecraft's ?) side (item has been reset already on death).
206
        if (Bridge1_9.hasGetItemInOffHand() && e.getPlayer().isBlocking()) {
207
            pData.requestItemUseResync();
208
        }
209
    }
210
211
    private static void onTridentRelease(final PlayerRiptideEvent e) {
212
        final IPlayerData pData = DataManager.getPlayerData(e.getPlayer());
213
        // This event is called on releasing the trident (See ItemTrident.java), so the item is not in use anymore.
214
        pData.setItemInUse(null);
215
    }
216
217
    private static void onItemConsume(final PlayerItemConsumeEvent e) {
218
        final Player p = e.getPlayer();
219
        final IPlayerData pData = DataManager.getPlayerData(p);
220
        // Consume(d) (!!), so the player isn't using the item anymore
221
        pData.setItemInUse(null);   
222
    }
223
224
    private static void onInventoryOpen(final InventoryOpenEvent e) {
225
        if (e.isCancelled()) return;
226
        final Player p = (Player) e.getPlayer();
227
        final IPlayerData pData = DataManager.getPlayerData(p);
228
        // Can't use item with an inventory open.
229
        pData.setItemInUse(null);
230
    }
231
232
    private static void onDeath(final PlayerDeathEvent e) {
233
        final IPlayerData pData = DataManager.getPlayerData((Player) e.getEntity());
234
        // Can't use item if dead
235
        pData.setItemInUse(null);  
236
    }
237
238
    @SuppressWarnings("deprecation")
239
	private static void onItemInteract(final PlayerInteractEvent e) {
240
        if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) {
241
            return;
242
        }
243
        final Player p = e.getPlayer();
244
        final IPlayerData pData = DataManager.getPlayerData(p);
245
        final MovingConfig mCC = pData.getGenericInstance(MovingConfig.class);
246
        final CombinedData data = pData.getGenericInstance(CombinedData.class);
247
        data.offHandUse = false;
248
        if (!data.mightUseItem) {
249
            // Player did not send the block-placement packet, so they are for sure not using anything, return.
250
            return;
251
        }
252
        // Do reset the flag at the start (!)
253
        data.mightUseItem = false;
254
255
        if (e.useItemInHand().equals(Event.Result.DENY)) {
256
            // A plugin denied the item-use.
257
            return;
258
        }
259
260
        if (p.getGameMode() == GameMode.CREATIVE) {
261
            // TODO: If merging SurvivalFly and CreativeFly, creative mode needs to be taken into consideration as well.
262
            pData.setItemInUse(null);
263
            return;
264
        }
265
        
266
        // Proceed to check...
267
        if (e.hasItem()) {
268
            final ItemStack item = e.getItem();
269
            final Material m = item.getType();
270
            if (Bridge1_9.hasElytra() && p.hasCooldown(m)) {
271
                // Item is in cooldown so it cannot be used.
272
                return;
273
            }
274
            
275
            // Edible / consumable items...
276
            if (InventoryUtil.isConsumable(item)) {
277
                if (!Bridge1_9.hasElytra() && item.getDurability() > 16384) {
278
                    // pre1.9 splash potion edge case.
279
                    return;
280
                }
281
                if (m == Material.POTION || m == Material.MILK_BUCKET || m.toString().endsWith("_APPLE") || m.name().startsWith("HONEY_BOTTLE")) {
282
                    // Can be consumed regardless of hunger level
283
                    pData.setItemInUse(m);
284
                    data.offHandUse = Bridge1_9.hasGetItemInOffHand() && e.getHand() == EquipmentSlot.OFF_HAND;
285
                    return;
286
                }
287
                if (item.getType().isEdible() && p.getFoodLevel() < 20) {
288
                    // Hunger level dependant consumables.
289
                    pData.setItemInUse(m); 
290
                    data.offHandUse = Bridge1_9.hasGetItemInOffHand() && e.getHand() == EquipmentSlot.OFF_HAND;
291
                    return;
292
                }
293
            }
294
            // Bows...
295
            if (m == Material.BOW && InventoryUtil.hasArrow(p.getInventory(), false)) {
296
                pData.setItemInUse(m);
297
                data.offHandUse = Bridge1_9.hasGetItemInOffHand() && e.getHand() == EquipmentSlot.OFF_HAND;
298
                return;
299
            }
300
            // Shields and swords (legacy)... Bukkit takes care here, but set anyway.
301
            if (ServerVersion.isAtLeast("1.9") && pData.getClientVersion().isAtLeast(ClientVersion.V_1_9)) {
302
                // Both server and client are on a version that support shield (thus, sword-blocking is not possible)
303
            	if (m == Material.SHIELD) {
304
            	    pData.setItemInUse(m);
305
                    data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
306
                    return;
307
            	}
308
            }
309
            else if (MaterialUtil.isSword(m) && (ServerVersion.isLowerThan("1.9") || pData.getClientVersion().isAtMost(ClientVersion.V_1_8))) {
310
            	// Legacy server. Or legacy client on a modern server. Blocking is done with swords in both cases.
311
            	pData.setItemInUse(m);
312
            	// (Off hand doesn't exist)
313
            	return;
314
            }
315
            
316
            // Crosswbows...
317
            if (m.toString().equals("CROSSBOW")) {
318
                if (!((CrossbowMeta) item.getItemMeta()).hasChargedProjectiles() && InventoryUtil.hasArrow(p.getInventory(), true)) {
319
                    pData.setItemInUse(m);
320
                    data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
321
                }
322
            }
323
            // Tridents (1.13)... 
324
            if (m == BridgeMaterial.TRIDENT && item.getDurability() < m.getMaxDurability() - 1 && pData.getClientVersion().isAtLeast(ClientVersion.V_1_13)
325
            	&& (
326
                    // 1: If the trident has riptide enchant, it can only be used in rain or water 
327
            		BridgeEnchant.getRiptideLevel(p) > 0.0
328
                    && (
329
                        // 2: In water
330
                        BlockProperties.isInWater(p, p.getLocation(), mCC.yOnGround)
331
                        // 2: Always check raining first, since canSeeSky is a much more expensive call. Needs optimization.
332
                        || p.getLocation().getWorld().hasStorm() && BlockProperties.canSeeSky(p, p.getLocation(), mCC.yOnGround) 
333
                    ) 
334
                    // 1: Otherwise, the trident can be used and thrown anywhere
335
                    || BridgeEnchant.getRiptideLevel(p) <= 0.0
336
                )) {
337
                pData.setItemInUse(m);
338
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
339
                return;
340
            }
341
            // Spyglass (1.17)...
342
            if (BridgeMisc.hasIsFrozen() && m == Material.SPYGLASS) {
343
                pData.setItemInUse(m);
344
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
345
                return;
346
            }
347
            // Lastly, goat horns (1.19)...
348
            if (m.toString().equals("GOAT_HORN")) {
349
                pData.setItemInUse(m);
350
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
351
                return;
352
            }
353
            // 1.21.11: Spears...
354
            if (MaterialUtil.isSpear(m)) {
355
                pData.setItemInUse(m);
356
                data.offHandUse = e.getHand() == EquipmentSlot.OFF_HAND;
357
            }
358
        } 
359
        else {
360
            // No item in hands, no deal.
361
            pData.setItemInUse(null);  
362
        }
363
    }
364
    
365
    // NOTE: Bukkit takes care of invalid slot values (< 0 or > 8. PlayerConnection.java), so we don't need to check for this as well.
366
    private static void onChangeSlot(final PlayerItemHeldEvent e) {
367
        final Player p = e.getPlayer();
368
        final IPlayerData pData = DataManager.getPlayerData(p);
369
        // Switching a slot, so the item use status is reset.
370
        final MovingData mData = pData.getGenericInstance(MovingData.class);
371
        final CombinedData cData = pData.getGenericInstance(CombinedData.class);
372
        if (e.getPreviousSlot() != e.getNewSlot()) {
373
            /*if ((pData.getItemInUse() != null || p.isBlocking()) && mData.playerMoves.getCurrentMove() != null) {
374
                p.getInventory().setHeldItemSlot(e.getPreviousSlot());
375
                cData.invalidItemUse = true;
376
            }*/
377
            // To avoid any more potential bypasses, let Minecraft forcibly release the item.
378
            pData.requestItemUseResync();
379
        }
380
    }
381
382
    private void handleBlockPlacePacket(PacketEvent event) {
383
        final Player p = event.getPlayer();
384
        final IPlayerData pData = DataManager.getPlayerData(p);
385
        final CombinedData data = pData.getGenericInstance(CombinedData.class);
386
        final PacketContainer packet = event.getPacket();
387
        final StructureModifier<Integer> ints = packet.getIntegers();
388
        // Legacy: pre 1.9
389
        if (ints.size() > 0 && !ServerVersion.isAtLeast("1.9")) {
390
            final int faceIndex = ints.read(0); // arg 3 if 1.7.10 below
391
            if (faceIndex <= 5) {
392
                data.mightUseItem = false;
393
                return;
394
            }
395
        }
396
        // Player sends a block-placement item when right-clicking, so they might be actually using an item. Set the flag.
397
        if (!event.isCancelled()) data.mightUseItem = true;
398
    }
399
400
    private void handleDiggingPacket(PacketEvent event) {
401
        Player p = event.getPlayer();       
402
        final IPlayerData pData = DataManager.getPlayerDataSafe(p);
403
        final CombinedData data = pData.getGenericInstance(CombinedData.class);
404
        PlayerDigType digtype = event.getPacket().getPlayerDigTypes().read(0);
405
        if (!BridgeMisc.hasGetItemInUseMethod()) {
406
            // DROP_ALL_ITEMS when dead?
407
            if (digtype == PlayerDigType.DROP_ALL_ITEMS || digtype == PlayerDigType.DROP_ITEM) {
408
                pData.setItemInUse(null);
409
            }
410
        }
411
        
412
        if (digtype == PlayerDigType.RELEASE_USE_ITEM) {
413
            pData.setItemInUse(null);
414
            long now = System.currentTimeMillis();
415
            if (data.releaseItemTime != 0) {
416
                if (now < data.releaseItemTime) {
417
                    data.releaseItemTime = now;
418
                    return;
419
                }
420
                if (data.releaseItemTime + timeBetweenRL > now) {
421
                    data.isHackingRI = true;
422
                }
423
            }
424
            data.releaseItemTime = now;
425
        }
426
    }
427
428
    /**
429
     * Set Minimum time between RELEASE_USE_ITEM packet is sent.
430
     * If time lower this value, A check will flag
431
     * Should be set from 51-100. Larger number, more protection more false-positive
432
     * 
433
     * @param time milliseconds
434
     */ 
435
    public static void setuseRLThreshold(int time) {
436
        timeBetweenRL = time;
437
    }   
438
}

How it counteracts this module

The item-use side of the accelerated stream is classified by the protocol adapter. handleBlockPlacePacket reads the C08's facing integer and, for the pre-1.9 format, treats faceIndex 5 or below as a real placement (mightUseItem set false) and anything else as a potential item use (mightUseItem set true); handleDiggingPacket stamps releaseItemTime on every RELEASE_USE_ITEM and sets isHackingRI when a second release arrives within timeBetweenRL (default 70ms) of the first. The isHackingRI flag then routes through SurvivalFly's noslow penalty path.

The mixin accelerates item use exactly like placement when the player holds anything but a block, so holding right click on food or a bow produces the use-item C08 form plus per-tick C07 releases inside the 70ms window, which trips isHackingRI from the second release. The honest boundary: with a block in hand the adapter sees the placement form and stays inert, so the placement-only configuration is countered by the rate window rather than by this adapter.

anticheat Reach (blockplace distance)

Reach.java85 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.blockplace;
16
17
import org.bukkit.GameMode;
18
import org.bukkit.Location;
19
import org.bukkit.block.Block;
20
import org.bukkit.entity.Player;
21
22
import fr.neatmonster.nocheatplus.actions.ParameterName;
23
import fr.neatmonster.nocheatplus.checks.Check;
24
import fr.neatmonster.nocheatplus.checks.CheckType;
25
import fr.neatmonster.nocheatplus.checks.ViolationData;
26
import fr.neatmonster.nocheatplus.utilities.StringUtil;
27
import fr.neatmonster.nocheatplus.utilities.math.TrigUtil;
28
29
/**
30
 * The Reach check will find out if a player places a block too far away.
31
 */
32
public class Reach extends Check {
33
34
    /** The maximum distance allowed to interact with a block in creative mode. */
35
    public static final double CREATIVE_DISTANCE = 5.6D;
36
37
    /** The maximum distance allowed to interact with a block in survival mode. */
38
    public static final double SURVIVAL_DISTANCE = 5.2D;
39
40
    /** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */
41
    private final Location useLoc = new Location(null, 0, 0, 0);
42
43
    /**
44
     * Instantiates a new reach check.
45
     */
46
    public Reach() {
47
        super(CheckType.BLOCKPLACE_REACH);
48
    }
49
50
    /**
51
     * Checks a player.
52
     * 
53
     * @param player
54
     *            the player
55
     * @param eyeHeight 
56
     * @param block 
57
     * @param data
58
     * @param cc
59
     * @return true, if successful
60
     */
61
    public boolean check(final Player player, final double eyeHeight, final Block block, final BlockPlaceData data, final BlockPlaceConfig cc) {
62
    	// TODO: Ray tracing-based?
63
        boolean cancel = false;
64
        final double distanceLimit = player.getGameMode() == GameMode.CREATIVE ? CREATIVE_DISTANCE : SURVIVAL_DISTANCE;
65
        // Distance is calculated from eye location to center of targeted block.
66
        final Location eyeLoc = player.getLocation(useLoc);
67
        eyeLoc.setY(eyeLoc.getY() + eyeHeight);
68
        final double distance = TrigUtil.distance(eyeLoc, block) - distanceLimit;
69
70
        if (distance > distanceLimit) {
71
            // They failed, increment violation level.
72
            data.reachVL += distance - distanceLimit;
73
            // Execute whatever actions are associated with this check and the violation level and find out if we should
74
            // cancel the event.
75
            final ViolationData vd = new ViolationData(this, player, data.reachVL, distance, cc.reachActions);
76
            vd.setParameter(ParameterName.REACH_DISTANCE, StringUtil.fdec3.format(distance));
77
            cancel = executeActions(vd).willCancel();
78
        } 
79
        // Player passed the check, reward them
80
        else data.reachVL *= 0.9D;
81
        // Cleanup.
82
        useLoc.setWorld(null);
83
        return cancel;
84
    }
85
}

How it counteracts this module

The blockplace reach check bounds the placement distance at 5.2 blocks in survival and 5.6 in creative, measured from the eye to the center of the targeted block, and decays the violation level on every in-range placement. The module changes nothing about the player's geometry: the accelerated clicks place inside the existing interaction range, so the check constrains the module the same way it constrains a manual builder.

Its role in the set is to close the geometry side: a fastplace cannot extend the placement distance, so the rate stream is bounded to whatever blocks sit within vanilla reach, and a player who stacks the fastplace with a placement-reach hack surfaces here.

← Back to Analysis Hub