Spicy FastBreak module 2 files, 705 lines

Spicy FastBreak: Full Source Analysis

Spicy's FastBreak accelerates block breaking by writing a fixed amount into the client-side damage accumulator every update tick: curBlockDamageMP gains speed/100 (speed 1-20, default 20), so…

info/spicyclient/modules/world/FastBreak.java · GitHub source ↗

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

Packets This Module Uses

Analysis

Overview

Spicy's FastBreak accelerates block breaking by writing a fixed amount into the client-side damage accumulator every update tick: curBlockDamageMP gains speed/100 (speed 1-20, default 20), so at the default the accumulator climbs 0.2 per tick on top of vanilla's hardness-based contribution and any block crosses the 1.0 break threshold in about five ticks of holding, regardless of how hard it is. The handler clamps the accumulator at 1.0 and returns once the break threshold is reached. Unlike other clients it never touches blockHitDelay, so the 5-tick post-break pause stays vanilla and chained breaks keep their normal gap. An older EventAddBlockDamage approach that set the damage directly sits in the source commented out.

Fixed-rate damage accumulation

PlayerControllerMP.onPlayerDamageBlock adds the block's relative hardness to curBlockDamageMP on each damage tick and sends C07 STOP_DIGGING when the accumulator reaches 1.0 (Spicy PlayerControllerMP lines 289-330). The module runs on every EventUpdate: while the accumulator is below 1.0 it adds speed/100 (0.01 to 0.2), and once at or above 1.0 it pins the accumulator to exactly 1.0 and returns, letting the vanilla break path fire on the current damage tick. Because the added term dominates the hardness term for hard blocks, the effective break time converges to about five ticks at default speed for any block that would otherwise take longer; soft blocks that vanilla breaks in one or two ticks are barely affected, since their own hardness term already crosses the threshold.

Wire fingerprint

The module sends no packets of its own; it changes the controller state that drives vanilla C07 emission. The per-block window shrinks from the hardness-based duration (stone by hand is about 45 ticks) to roughly five ticks at default speed, so the server sees START_DIGGING followed by STOP_DIGGING after a fraction of the expected time. blockHitDelay is untouched, so the 250ms inter-block pause remains, which distinguishes this implementation from the zero-delay variants and means the chained-break signature is weaker than in clients that also zero the delay.

Detection surface

The counters split across the two effects. NCP blockbreak FastBreak and Hawk BlockBreakSpeedSurvival compare the measured break time against an expected time derived from the block's hardness and the player's tool, which is the direct counter to the collapsed window; NCP blockbreak Frequency caps breaks per time frame and bites in creative-mode chains. The Arc lineage offers nothing here: Vrekt-Arc's block-break check is creative-gated, and Vrekt-Arc v2 dropped the block package entirely, its PacketListener subscribing only to FLYING, POSITION, USE_ENTITY, ARM_ANIMATION, HELD_ITEM_SLOT and BLOCK_PLACE.

source FastBreak.java

FastBreak.java63 lines · JavaOriginal ↗
1
package info.spicyclient.modules.world;
2
3
import org.lwjgl.input.Keyboard;
4
5
import info.spicyclient.events.Event;
6
import info.spicyclient.events.listeners.EventAddBlockDamage;
7
import info.spicyclient.events.listeners.EventUpdate;
8
import info.spicyclient.modules.Module;
9
import info.spicyclient.settings.NumberSetting;
10
import net.minecraft.network.play.client.C03PacketPlayer;
11
12
public class FastBreak extends Module {
13
	
14
	private NumberSetting speed = new NumberSetting("Speed", 20, 1, 20, 1);
15
	
16
	public FastBreak() {
17
		super("Fast Break", Keyboard.KEY_NONE, Category.WORLD);
18
		resetSettings();
19
	}
20
	
21
	@Override
22
	public void resetSettings() {
23
		settings.clear();
24
		addSettings(speed);
25
	}
26
	
27
	public void onEnable() {
28
		
29
	}
30
	
31
	public void onDisable() {
32
		
33
	}
34
	
35
	public void onEvent(Event e) {
36
		
37
		if (e instanceof EventUpdate && e.isPre()) {
38
			
39
			if (mc.playerController.curBlockDamageMP >= 1.0) {
40
				mc.playerController.curBlockDamageMP = 1.0f;
41
				return;
42
			}
43
			
44
	        mc.playerController.curBlockDamageMP += speed.getValue() / 100;
45
	        
46
		}
47
		
48
		// Removed
49
		/*
50
		if (e instanceof EventAddBlockDamage) {
51
			
52
			if (e.isPre()) {
53
				
54
				EventAddBlockDamage blockDamage = (EventAddBlockDamage) e;
55
				blockDamage.setDamage((int) speed.getValue());
56
				
57
			}
58
			
59
		}
60
		*/
61
	}
62
	
63
}

What this file does

The module is a single EventUpdate handler with one NumberSetting. The speed setting spans 1-20 with a 20 default, and each pre-update either adds speed/100 to mc.playerController.curBlockDamageMP or, once the accumulator has reached 1.0, pins it there and returns. The pin matters: without it the accumulator could ride above 1.0 while the vanilla break path waits for its own damage tick, and with it the break fires on the first damage tick after the threshold.

The commented-out EventAddBlockDamage block shows the previous design, which set the damage directly from the speed value inside the block-damage event; the shipped build moved the mutation to the update tick instead, which spreads the acceleration over the damage controller's own cadence. The class carries no other logic: no blockHitDelay manipulation, no packet interception, no onEnable/onDisable behavior.

source PlayerControllerMP.java (damage controller)

PlayerControllerMP.java642 lines · JavaOriginal ↗
1
package net.minecraft.client.multiplayer;
2
3
import info.spicyclient.SpicyClient;
4
import info.spicyclient.events.EventType;
5
import info.spicyclient.events.listeners.EventAddBlockDamage;
6
import info.spicyclient.events.listeners.EventGetBlockReach;
7
import net.minecraft.block.Block;
8
import net.minecraft.block.material.Material;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.client.Minecraft;
11
import net.minecraft.client.audio.PositionedSoundRecord;
12
import net.minecraft.client.entity.EntityPlayerSP;
13
import net.minecraft.client.network.NetHandlerPlayClient;
14
import net.minecraft.entity.Entity;
15
import net.minecraft.entity.passive.EntityHorse;
16
import net.minecraft.entity.player.EntityPlayer;
17
import net.minecraft.item.ItemBlock;
18
import net.minecraft.item.ItemStack;
19
import net.minecraft.item.ItemSword;
20
import net.minecraft.network.play.client.C02PacketUseEntity;
21
import net.minecraft.network.play.client.C07PacketPlayerDigging;
22
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
23
import net.minecraft.network.play.client.C09PacketHeldItemChange;
24
import net.minecraft.network.play.client.C0EPacketClickWindow;
25
import net.minecraft.network.play.client.C10PacketCreativeInventoryAction;
26
import net.minecraft.network.play.client.C11PacketEnchantItem;
27
import net.minecraft.stats.StatFileWriter;
28
import net.minecraft.util.BlockPos;
29
import net.minecraft.util.EnumFacing;
30
import net.minecraft.util.MovingObjectPosition;
31
import net.minecraft.util.ResourceLocation;
32
import net.minecraft.util.Vec3;
33
import net.minecraft.world.World;
34
import net.minecraft.world.WorldSettings;
35
36
public class PlayerControllerMP
37
{
38
    /** The Minecraft instance. */
39
    private final Minecraft mc;
40
    private final NetHandlerPlayClient netClientHandler;
41
    private BlockPos currentBlock = new BlockPos(-1, -1, -1);
42
43
    /** The Item currently being used to destroy a block */
44
    private ItemStack currentItemHittingBlock;
45
46
    /** Current block damage (MP) */
47
    public float curBlockDamageMP;
48
49
    /**
50
     * Tick counter, when it hits 4 it resets back to 0 and plays the step sound
51
     */
52
    private float stepSoundTickCounter;
53
54
    /**
55
     * Delays the first damage on the block after the first click on the block
56
     */
57
    public int blockHitDelay;
58
59
    /** Tells if the player is hitting a block */
60
    private boolean isHittingBlock;
61
62
    /** Current game type for the player */
63
    public WorldSettings.GameType currentGameType = WorldSettings.GameType.SURVIVAL;
64
65
    /** Index of the current item held by the player in the inventory hotbar */
66
    private int currentPlayerItem;
67
68
    public PlayerControllerMP(Minecraft mcIn, NetHandlerPlayClient p_i45062_2_)
69
    {
70
        this.mc = mcIn;
71
        this.netClientHandler = p_i45062_2_;
72
    }
73
74
    public static void clickBlockCreative(Minecraft mcIn, PlayerControllerMP p_178891_1_, BlockPos p_178891_2_, EnumFacing p_178891_3_)
75
    {
76
        if (!mcIn.theWorld.extinguishFire(mcIn.thePlayer, p_178891_2_, p_178891_3_))
77
        {
78
            p_178891_1_.onPlayerDestroyBlock(p_178891_2_, p_178891_3_);
79
        }
80
    }
81
82
    /**
83
     * Sets player capabilities depending on current gametype. params: player
84
     */
85
    public void setPlayerCapabilities(EntityPlayer p_78748_1_)
86
    {
87
        this.currentGameType.configurePlayerCapabilities(p_78748_1_.capabilities);
88
    }
89
90
    /**
91
     * None
92
     */
93
    public boolean isSpectator()
94
    {
95
        return this.currentGameType == WorldSettings.GameType.SPECTATOR;
96
    }
97
98
    /**
99
     * Sets the game type for the player.
100
     */
101
    public void setGameType(WorldSettings.GameType p_78746_1_)
102
    {
103
        this.currentGameType = p_78746_1_;
104
        this.currentGameType.configurePlayerCapabilities(this.mc.thePlayer.capabilities);
105
    }
106
107
    /**
108
     * Flips the player around.
109
     */
110
    public void flipPlayer(EntityPlayer playerIn)
111
    {
112
        playerIn.rotationYaw = -180.0F;
113
    }
114
115
    public boolean shouldDrawHUD()
116
    {
117
        return this.currentGameType.isSurvivalOrAdventure();
118
    }
119
120
    /**
121
     * Called when a player completes the destruction of a block
122
     */
123
    public boolean onPlayerDestroyBlock(BlockPos pos, EnumFacing side)
124
    {
125
        if (this.currentGameType.isAdventure())
126
        {
127
            if (this.currentGameType == WorldSettings.GameType.SPECTATOR)
128
            {
129
                return false;
130
            }
131
132
            if (!this.mc.thePlayer.isAllowEdit())
133
            {
134
                Block block = this.mc.theWorld.getBlockState(pos).getBlock();
135
                ItemStack itemstack = this.mc.thePlayer.getCurrentEquippedItem();
136
137
                if (itemstack == null)
138
                {
139
                    return false;
140
                }
141
142
                if (!itemstack.canDestroy(block))
143
                {
144
                    return false;
145
                }
146
            }
147
        }
148
149
        if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItem() != null && this.mc.thePlayer.getHeldItem().getItem() instanceof ItemSword)
150
        {
151
            return false;
152
        }
153
        else
154
        {
155
            World world = this.mc.theWorld;
156
            IBlockState iblockstate = world.getBlockState(pos);
157
            Block block1 = iblockstate.getBlock();
158
159
            if (block1.getMaterial() == Material.air)
160
            {
161
                return false;
162
            }
163
            else
164
            {
165
                world.playAuxSFX(2001, pos, Block.getStateId(iblockstate));
166
                boolean flag = world.setBlockToAir(pos);
167
168
                if (flag)
169
                {
170
                    block1.onBlockDestroyedByPlayer(world, pos, iblockstate);
171
                }
172
173
                this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
174
175
                if (!this.currentGameType.isCreative())
176
                {
177
                    ItemStack itemstack1 = this.mc.thePlayer.getCurrentEquippedItem();
178
179
                    if (itemstack1 != null)
180
                    {
181
                        itemstack1.onBlockDestroyed(world, block1, pos, this.mc.thePlayer);
182
183
                        if (itemstack1.stackSize == 0)
184
                        {
185
                            this.mc.thePlayer.destroyCurrentEquippedItem();
186
                        }
187
                    }
188
                }
189
190
                return flag;
191
            }
192
        }
193
    }
194
195
    /**
196
     * Called when the player is hitting a block with an item.
197
     */
198
    public boolean clickBlock(BlockPos loc, EnumFacing face)
199
    {
200
        if (this.currentGameType.isAdventure())
201
        {
202
            if (this.currentGameType == WorldSettings.GameType.SPECTATOR)
203
            {
204
                return false;
205
            }
206
207
            if (!this.mc.thePlayer.isAllowEdit())
208
            {
209
                Block block = this.mc.theWorld.getBlockState(loc).getBlock();
210
                ItemStack itemstack = this.mc.thePlayer.getCurrentEquippedItem();
211
212
                if (itemstack == null)
213
                {
214
                    return false;
215
                }
216
217
                if (!itemstack.canDestroy(block))
218
                {
219
                    return false;
220
                }
221
            }
222
        }
223
224
        if (!this.mc.theWorld.getWorldBorder().contains(loc))
225
        {
226
            return false;
227
        }
228
        else
229
        {
230
            if (this.currentGameType.isCreative())
231
            {
232
                this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
233
                clickBlockCreative(this.mc, this, loc, face);
234
                this.blockHitDelay = 5;
235
            }
236
            else if (!this.isHittingBlock || !this.isHittingPosition(loc))
237
            {
238
                if (this.isHittingBlock)
239
                {
240
                    this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, face));
241
                }
242
243
                this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
244
                Block block1 = this.mc.theWorld.getBlockState(loc).getBlock();
245
                boolean flag = block1.getMaterial() != Material.air;
246
247
                if (flag && this.curBlockDamageMP == 0.0F)
248
                {
249
                    block1.onBlockClicked(this.mc.theWorld, loc, this.mc.thePlayer);
250
                }
251
252
                if (flag && block1.getPlayerRelativeBlockHardness(this.mc.thePlayer, this.mc.thePlayer.worldObj, loc) >= 1.0F)
253
                {
254
                    this.onPlayerDestroyBlock(loc, face);
255
                }
256
                else
257
                {
258
                    this.isHittingBlock = true;
259
                    this.currentBlock = loc;
260
                    this.currentItemHittingBlock = this.mc.thePlayer.getHeldItem();
261
                    this.curBlockDamageMP = 0.0F;
262
                    this.stepSoundTickCounter = 0.0F;
263
                    this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
264
                }
265
            }
266
267
            return true;
268
        }
269
    }
270
271
    /**
272
     * Resets current block damage and isHittingBlock
273
     */
274
    public void resetBlockRemoving()
275
    {
276
        if (this.isHittingBlock)
277
        {
278
            this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, EnumFacing.DOWN));
279
            this.isHittingBlock = false;
280
            this.curBlockDamageMP = 0.0F;
281
            this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, -1);
282
        }
283
    }
284
285
    public boolean onPlayerDamageBlock(BlockPos posBlock, EnumFacing directionFacing)
286
    {
287
        this.syncCurrentPlayItem();
288
289
        if (this.blockHitDelay > 0)
290
        {
291
            --this.blockHitDelay;
292
            return true;
293
        }
294
        else if (this.currentGameType.isCreative() && this.mc.theWorld.getWorldBorder().contains(posBlock))
295
        {
296
            this.blockHitDelay = 5;
297
            this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.START_DESTROY_BLOCK, posBlock, directionFacing));
298
            clickBlockCreative(this.mc, this, posBlock, directionFacing);
299
            return true;
300
        }
301
        else if (this.isHittingPosition(posBlock))
302
        {
303
            Block block = this.mc.theWorld.getBlockState(posBlock).getBlock();
304
305
            if (block.getMaterial() == Material.air)
306
            {
307
                this.isHittingBlock = false;
308
                return false;
309
            }
310
            else
311
            {
312
            	
313
            	EventAddBlockDamage event = new EventAddBlockDamage();
314
            	event.Damage = 1;
315
            	event.setType(EventType.PRE);
316
            	SpicyClient.onEvent(event);
317
            	for (int i = 0; i < event.getDamage(); i++) {
318
            		
319
            		this.curBlockDamageMP += block.getPlayerRelativeBlockHardness(this.mc.thePlayer, this.mc.thePlayer.worldObj, posBlock);
320
            		
321
            	}
322
            	
323
                if (this.stepSoundTickCounter % 4.0F == 0.0F)
324
                {
325
                    this.mc.getSoundHandler().playSound(new PositionedSoundRecord(new ResourceLocation(block.stepSound.getStepSound()), (block.stepSound.getVolume() + 1.0F) / 8.0F, block.stepSound.getFrequency() * 0.5F, (float)posBlock.getX() + 0.5F, (float)posBlock.getY() + 0.5F, (float)posBlock.getZ() + 0.5F));
326
                }
327
328
                ++this.stepSoundTickCounter;
329
330
                if (this.curBlockDamageMP >= 1.0F)
331
                {
332
                    this.isHittingBlock = false;
333
                    this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.STOP_DESTROY_BLOCK, posBlock, directionFacing));
334
                    this.onPlayerDestroyBlock(posBlock, directionFacing);
335
                    this.curBlockDamageMP = 0.0F;
336
                    this.stepSoundTickCounter = 0.0F;
337
                    this.blockHitDelay = 5;
338
                }
339
340
                this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
341
                return true;
342
            }
343
        }
344
        else
345
        {
346
            return this.clickBlock(posBlock, directionFacing);
347
        }
348
    }
349
350
    /**
351
     * player reach distance = 4F
352
     */
353
    public float getBlockReachDistance()
354
    {
355
    	
356
    	EventGetBlockReach event = new EventGetBlockReach();
357
    	event.setType(EventType.PRE);
358
    	SpicyClient.onEvent(event);
359
    	
360
    	if (event.reach != -1) {
361
    		return event.reach;
362
    	}else {
363
    		return this.currentGameType.isCreative() ? 5.0F : 4.5F;
364
    	}
365
    }
366
367
    public void updateController()
368
    {
369
        this.syncCurrentPlayItem();
370
371
        if (this.netClientHandler.getNetworkManager().isChannelOpen())
372
        {
373
            this.netClientHandler.getNetworkManager().processReceivedPackets();
374
        }
375
        else
376
        {
377
            this.netClientHandler.getNetworkManager().checkDisconnected();
378
        }
379
    }
380
381
    private boolean isHittingPosition(BlockPos pos)
382
    {
383
        ItemStack itemstack = this.mc.thePlayer.getHeldItem();
384
        boolean flag = this.currentItemHittingBlock == null && itemstack == null;
385
386
        if (this.currentItemHittingBlock != null && itemstack != null)
387
        {
388
            flag = itemstack.getItem() == this.currentItemHittingBlock.getItem() && ItemStack.areItemStackTagsEqual(itemstack, this.currentItemHittingBlock) && (itemstack.isItemStackDamageable() || itemstack.getMetadata() == this.currentItemHittingBlock.getMetadata());
389
        }
390
391
        return pos.equals(this.currentBlock) && flag;
392
    }
393
394
    /**
395
     * Syncs the current player item with the server
396
     */
397
    public void syncCurrentPlayItem()
398
    {
399
        int i = this.mc.thePlayer.inventory.currentItem;
400
401
        if (i != this.currentPlayerItem)
402
        {
403
            this.currentPlayerItem = i;
404
            this.netClientHandler.addToSendQueue(new C09PacketHeldItemChange(this.currentPlayerItem));
405
        }
406
    }
407
408
    public boolean onPlayerRightClick(EntityPlayerSP player, WorldClient worldIn, ItemStack heldStack, BlockPos hitPos, EnumFacing side, Vec3 hitVec)
409
    {
410
        this.syncCurrentPlayItem();
411
        float f = (float)(hitVec.xCoord - (double)hitPos.getX());
412
        float f1 = (float)(hitVec.yCoord - (double)hitPos.getY());
413
        float f2 = (float)(hitVec.zCoord - (double)hitPos.getZ());
414
        boolean flag = false;
415
416
        if (!this.mc.theWorld.getWorldBorder().contains(hitPos))
417
        {
418
            return false;
419
        }
420
        else
421
        {
422
            if (this.currentGameType != WorldSettings.GameType.SPECTATOR)
423
            {
424
                IBlockState iblockstate = worldIn.getBlockState(hitPos);
425
426
                if ((!player.isSneaking() || player.getHeldItem() == null) && iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2))
427
                {
428
                    flag = true;
429
                }
430
431
                if (!flag && heldStack != null && heldStack.getItem() instanceof ItemBlock)
432
                {
433
                    ItemBlock itemblock = (ItemBlock)heldStack.getItem();
434
435
                    if (!itemblock.canPlaceBlockOnSide(worldIn, hitPos, side, player, heldStack))
436
                    {
437
                        return false;
438
                    }
439
                }
440
            }
441
            
442
            this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));
443
444
            if (!flag && this.currentGameType != WorldSettings.GameType.SPECTATOR)
445
            {
446
                if (heldStack == null)
447
                {
448
                    return false;
449
                }
450
                else if (this.currentGameType.isCreative())
451
                {
452
                    int i = heldStack.getMetadata();
453
                    int j = heldStack.stackSize;
454
                    boolean flag1 = heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
455
                    heldStack.setItemDamage(i);
456
                    heldStack.stackSize = j;
457
                    return flag1;
458
                }
459
                else
460
                {
461
                    return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
462
                }
463
            }
464
            else
465
            {
466
                return true;
467
            }
468
        }
469
    }
470
471
    /**
472
     * Notifies the server of things like consuming food, etc...
473
     */
474
    public boolean sendUseItem(EntityPlayer playerIn, World worldIn, ItemStack itemStackIn)
475
    {
476
        if (this.currentGameType == WorldSettings.GameType.SPECTATOR)
477
        {
478
            return false;
479
        }
480
        else
481
        {
482
            this.syncCurrentPlayItem();
483
            this.netClientHandler.addToSendQueue(new C08PacketPlayerBlockPlacement(playerIn.inventory.getCurrentItem()));
484
            int i = itemStackIn.stackSize;
485
            ItemStack itemstack = itemStackIn.useItemRightClick(worldIn, playerIn);
486
487
            if (itemstack != itemStackIn || itemstack != null && itemstack.stackSize != i)
488
            {
489
                playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = itemstack;
490
491
                if (itemstack.stackSize == 0)
492
                {
493
                    playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
494
                }
495
496
                return true;
497
            }
498
            else
499
            {
500
                return false;
501
            }
502
        }
503
    }
504
505
    public EntityPlayerSP func_178892_a(World worldIn, StatFileWriter p_178892_2_)
506
    {
507
        return new EntityPlayerSP(this.mc, worldIn, this.netClientHandler, p_178892_2_);
508
    }
509
510
    /**
511
     * Attacks an entity
512
     */
513
    public void attackEntity(EntityPlayer playerIn, Entity targetEntity)
514
    {
515
        this.syncCurrentPlayItem();
516
        this.netClientHandler.addToSendQueue(new C02PacketUseEntity(targetEntity, C02PacketUseEntity.Action.ATTACK));
517
518
        if (this.currentGameType != WorldSettings.GameType.SPECTATOR)
519
        {
520
            playerIn.attackTargetEntityWithCurrentItem(targetEntity);
521
        }
522
    }
523
524
    /**
525
     * Send packet to server - player is interacting with another entity (left click)
526
     */
527
    public boolean interactWithEntitySendPacket(EntityPlayer playerIn, Entity targetEntity)
528
    {
529
        this.syncCurrentPlayItem();
530
        this.netClientHandler.addToSendQueue(new C02PacketUseEntity(targetEntity, C02PacketUseEntity.Action.INTERACT));
531
        return this.currentGameType != WorldSettings.GameType.SPECTATOR && playerIn.interactWith(targetEntity);
532
    }
533
534
    public boolean func_178894_a(EntityPlayer p_178894_1_, Entity p_178894_2_, MovingObjectPosition p_178894_3_)
535
    {
536
        this.syncCurrentPlayItem();
537
        Vec3 vec3 = new Vec3(p_178894_3_.hitVec.xCoord - p_178894_2_.posX, p_178894_3_.hitVec.yCoord - p_178894_2_.posY, p_178894_3_.hitVec.zCoord - p_178894_2_.posZ);
538
        this.netClientHandler.addToSendQueue(new C02PacketUseEntity(p_178894_2_, vec3));
539
        return this.currentGameType != WorldSettings.GameType.SPECTATOR && p_178894_2_.interactAt(p_178894_1_, vec3);
540
    }
541
542
    /**
543
     * Handles slot clicks sends a packet to the server.
544
     */
545
    public ItemStack windowClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityPlayer playerIn)
546
    {
547
        short short1 = playerIn.openContainer.getNextTransactionID(playerIn.inventory);
548
        ItemStack itemstack = playerIn.openContainer.slotClick(slotId, mouseButtonClicked, mode, playerIn);
549
        this.netClientHandler.addToSendQueue(new C0EPacketClickWindow(windowId, slotId, mouseButtonClicked, mode, itemstack, short1));
550
        return itemstack;
551
    }
552
553
    /**
554
     * GuiEnchantment uses this during multiplayer to tell PlayerControllerMP to send a packet indicating the
555
     * enchantment action the player has taken.
556
     */
557
    public void sendEnchantPacket(int p_78756_1_, int p_78756_2_)
558
    {
559
        this.netClientHandler.addToSendQueue(new C11PacketEnchantItem(p_78756_1_, p_78756_2_));
560
    }
561
562
    /**
563
     * Used in PlayerControllerMP to update the server with an ItemStack in a slot.
564
     */
565
    public void sendSlotPacket(ItemStack itemStackIn, int slotId)
566
    {
567
        if (this.currentGameType.isCreative())
568
        {
569
            this.netClientHandler.addToSendQueue(new C10PacketCreativeInventoryAction(slotId, itemStackIn));
570
        }
571
    }
572
573
    /**
574
     * Sends a Packet107 to the server to drop the item on the ground
575
     */
576
    public void sendPacketDropItem(ItemStack itemStackIn)
577
    {
578
        if (this.currentGameType.isCreative() && itemStackIn != null)
579
        {
580
            this.netClientHandler.addToSendQueue(new C10PacketCreativeInventoryAction(-1, itemStackIn));
581
        }
582
    }
583
584
    public void onStoppedUsingItem(EntityPlayer playerIn)
585
    {
586
        this.syncCurrentPlayItem();
587
        this.netClientHandler.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN));
588
        playerIn.stopUsingItem();
589
    }
590
591
    public boolean gameIsSurvivalOrAdventure()
592
    {
593
        return this.currentGameType.isSurvivalOrAdventure();
594
    }
595
596
    /**
597
     * Checks if the player is not creative, used for checking if it should break a block instantly
598
     */
599
    public boolean isNotCreative()
600
    {
601
        return !this.currentGameType.isCreative();
602
    }
603
604
    /**
605
     * returns true if player is in creative mode
606
     */
607
    public boolean isInCreativeMode()
608
    {
609
        return this.currentGameType.isCreative();
610
    }
611
612
    /**
613
     * true for hitting entities far away.
614
     */
615
    public boolean extendedReach()
616
    {
617
        return this.currentGameType.isCreative();
618
    }
619
620
    /**
621
     * Checks if the player is riding a horse, used to chose the GUI to open
622
     */
623
    public boolean isRidingHorse()
624
    {
625
        return this.mc.thePlayer.isRiding() && this.mc.thePlayer.ridingEntity instanceof EntityHorse;
626
    }
627
628
    public boolean isSpectatorMode()
629
    {
630
        return this.currentGameType == WorldSettings.GameType.SPECTATOR;
631
    }
632
633
    public WorldSettings.GameType getCurrentGameType()
634
    {
635
        return this.currentGameType;
636
    }
637
638
    public boolean func_181040_m()
639
    {
640
        return this.isHittingBlock;
641
    }
642
}

What this file does

This is the vanilla class the module mutates. The relevant state is curBlockDamageMP (line 47) and blockHitDelay (line 57). onPlayerDamageBlock decrements blockHitDelay and returns without damaging while it is positive, sets blockHitDelay to 5 when a new block is first targeted (line 234), resets the accumulator on a block change, adds getPlayerRelativeBlockHardness to curBlockDamageMP each damage tick (line 319), and when the accumulator reaches 1.0 sends the break and resets both fields (lines 289-330).

Embedding the controller makes the module's single write legible: the fixed speed/100 addition substitutes a constant per-tick term for the hardness-derived one, and the 1.0 clamp in the module lines up exactly with the line-330 break threshold. The file also shows what the module deliberately does not touch: blockHitDelay keeps its 5-tick assignment on every break, which is why chained blocks still carry the vanilla gap.

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 FastBreak (break-time differential)

FastBreak.java135 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.blockbreak;
16
17
import org.bukkit.Material;
18
import org.bukkit.block.Block;
19
import org.bukkit.entity.Player;
20
import org.bukkit.inventory.ItemStack;
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.compat.AlmostBoolean;
27
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
28
import fr.neatmonster.nocheatplus.compat.bukkit.BridgePotionEffect;
29
import fr.neatmonster.nocheatplus.permissions.Permissions;
30
import fr.neatmonster.nocheatplus.players.IPlayerData;
31
import fr.neatmonster.nocheatplus.utilities.TickTask;
32
import fr.neatmonster.nocheatplus.utilities.entity.PotionUtil;
33
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
34
35
/**
36
 * A check used to verify if the player is breaking blocks faster than possible.
37
 */
38
public class FastBreak extends Check {
39
40
    /**
41
     * Instantiates a new fast break check.
42
     */
43
    public FastBreak() {
44
        super(CheckType.BLOCKBREAK_FASTBREAK);
45
    }
46
47
    /**
48
     * Checks a player for fastbreak. This is NOT for creative mode.
49
     * @return true, if successful
50
     */
51
    public boolean check(final Player player, final Block block, final AlmostBoolean isInstaBreak, final BlockBreakConfig cc, final BlockBreakData data, final IPlayerData pData) {
52
        final long now = System.currentTimeMillis();
53
        boolean cancel = false;
54
        // Determine expected breaking time by block type.
55
        final Material blockType = block.getType();
56
        final long expectedBreakingTime = Math.max(0, Math.round((double) BlockProperties.getBreakingDuration(blockType, player) * (double) cc.fastBreakModSurvival / 100D));
57
        final long elapsedTime;
58
        // Counting interact...break.
59
        // TODO: Concept for unbreakable blocks? Context: extreme VL.
60
        // TODO: Should it be breakingTime instead of 0 for inconsistencies?
61
        elapsedTime = cc.fastBreakStrict ? (data.fastBreakBreakTime > data.fastBreakfirstDamage) ? 0 : now - data.fastBreakfirstDamage
62
                                         // Counting break...break.
63
                                         : (data.fastBreakBreakTime > now) ? 0 : now - data.fastBreakBreakTime;
64
65
        // Check if the time spent is lower than expected.
66
        if (isInstaBreak.decideOptimistically()) {
67
            // Ignore these for now.
68
            // TODO: Find out why this was commented out long ago a) did not fix mcMMO b) exploits.
69
            // TODO: Maybe adjust time to min(time, SOMETHING) for MAYBE/YES.
70
        }
71
        else if (elapsedTime < 0) {
72
            // Ignore it. TODO: ?
73
        }
74
        else if (elapsedTime + cc.fastBreakDelay < expectedBreakingTime) {
75
            // Lag or cheat or Minecraft.
76
            // Count in server side lag, if desired.
77
            final float serverLagFactor = pData.getCurrentWorldDataSafe().shouldAdjustToLag(type) ? TickTask.getLag(expectedBreakingTime, true) : 1f;
78
            final long missingTime = expectedBreakingTime - (long)(serverLagFactor * elapsedTime);
79
            if (missingTime > 0) {
80
                // Add as penalty
81
                data.fastBreakPenalties.add(now, (float) missingTime);
82
                // Only raise a violation, if the total penalty score exceeds the contention duration (for lag, delay).
83
                if (data.fastBreakPenalties.score(cc.fastBreakBucketFactor) > cc.fastBreakGrace) {
84
                    // TODO: maybe add one absolute penalty time for big amounts to stop breaking until then
85
                    final double violation = (double) missingTime / 1000.0;
86
                    data.fastBreakVL += violation;
87
                    final ViolationData vd = new ViolationData(this, player, data.fastBreakVL, violation, cc.fastBreakActions);
88
                    if (vd.needsParameters()) {
89
                        vd.setParameter(ParameterName.BLOCK_TYPE, blockType.toString());
90
                    }
91
                    cancel = executeActions(vd).willCancel();
92
                }
93
                // else: still within contention limits.
94
            }
95
        }
96
        else if (expectedBreakingTime > cc.fastBreakDelay) {
97
            // Fast breaking does not decrease violation level.
98
            data.fastBreakVL *= 0.9D;
99
        }
100
101
        // TODO: Rework to use (then hopefully completed) BlockBreakKey.
102
        if (pData.isDebugActive(type)) {
103
            detailDebugStats(player, isInstaBreak, blockType, elapsedTime, expectedBreakingTime, data, pData);
104
        }
105
        else {
106
            data.stats = null;
107
        }
108
        // (The break time is set in the listener).
109
        return cancel;
110
    }
111
112
    private void detailDebugStats(final Player player, final AlmostBoolean isInstaBreak,
113
                                  final Material blockType, final long elapsedTime, final long expectedBreakingTime,
114
                                  final BlockBreakData data, final IPlayerData pData) {
115
        if (pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
116
            // General stats:
117
            // TODO: Replace stats by new system (BlockBreakKey once complete), commands to inspect / auto-config.
118
            data.setStats();
119
            data.stats.addStats(data.stats.getId(blockType+ "/u", true), elapsedTime);
120
            data.stats.addStats(data.stats.getId(blockType + "/r", true), expectedBreakingTime);
121
            player.sendMessage(data.stats.getStatsStr(true));
122
            // Send info about current break:
123
            final ItemStack stack = Bridge1_9.getItemInMainHand(player);
124
            final boolean isValidTool = BlockProperties.isValidTool(blockType, stack);
125
            final double haste = PotionUtil.getPotionEffectAmplifier(player, BridgePotionEffect.HASTE);
126
            String msg = (isInstaBreak.decideOptimistically() ? ("[Insta=" + isInstaBreak + "]") : "[Normal]") + "[" + blockType + "] "+ elapsedTime + "u / " + expectedBreakingTime +"r (" + (isValidTool?"tool":"no-tool") + ")" + (Double.isInfinite(haste) ? "" : " haste=" + ((int) haste + 1));
127
            player.sendMessage(msg);
128
            //          net.minecraft.server.Item mcItem = net.minecraft.server.Item.byId[stack.getTypeId()];
129
            //          if (mcItem != null) {
130
            //              double x = mcItem.getDestroySpeed(((CraftItemStack) stack).getHandle(), net.minecraft.server.Block.byId[blockId]);
131
            //              player.sendMessage("mc speed: " + x);
132
            //          }
133
        }
134
    }
135
}

How it counteracts this module

NCP's blockbreak FastBreak validates the measured break time against the block's expected breaking time. The expected value is round(getBreakingDuration(blockType, player) * fastBreakModSurvival / 100) (line 56; the survival modifier defaults to 100, DefaultConfig line 126), and the elapsed time is now minus the first damage time in strict mode (lines 61-63; strict defaults to true, DefaultConfig line 124). When elapsed plus the fastBreakDelay (default 10ms) falls short of the expected time, the missing time is added as a penalty to a bucket (lines 74-81) and a violation fires once the bucket score exceeds the grace (default 2000, DefaultConfig line 128), with the violation level scaled by the missing time in seconds (lines 85-87). Insta-break blocks are skipped (line 66).

The module's fixed five-tick window cuts every hard block's measured time short by most of its expected duration: stone by hand expects about 45 ticks and completes in five, so each stone block adds roughly 2 seconds of missing time to the penalty bucket, and the 2000ms grace is exhausted after a single block. Soft blocks that already break in one or two ticks add almost nothing, because the module's 0.2-per-tick term does not shorten their window, so the check punishes the module's hard-block use specifically and accumulates nothing on sand or gravel.

anticheat Frequency (break-rate cap)

Frequency.java95 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.blockbreak;
16
17
import org.bukkit.GameMode;
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
 * This checks just limits the number of blocks broken per time frame.
27
 * @author asofold
28
 *
29
 */
30
public class Frequency extends Check {
31
32
    public Frequency() {
33
        super(CheckType.BLOCKBREAK_FREQUENCY);
34
    }
35
    
36
    /**
37
     * Checks a player
38
     * @param player
39
     * @param tick
40
     * @param cc
41
     * @param data
42
     * @param pData
43
     * @return true if cancelled.
44
     * 
45
     */
46
    public boolean check(final Player player, final int tick, final BlockBreakConfig cc, final BlockBreakData data, final IPlayerData pData) {
47
        final float interval = player.getGameMode() == GameMode.CREATIVE ? cc.frequencyIntervalCreative : cc.frequencyIntervalSurvival;
48
        data.frequencyBuckets.add(System.currentTimeMillis(), (float)interval);
49
        // Full period frequency.
50
        final float fullScore = data.frequencyBuckets.score(cc.frequencyBucketFactor);
51
        final long fullTime = cc.frequencyBucketDur * cc.frequencyBuckets;
52
        final boolean lag = pData.getCurrentWorldData().shouldAdjustToLag(type);
53
54
        // Short term limit.
55
        if (tick < data.frequencyShortTermTick) {
56
            // Tick task got reset.
57
            data.frequencyShortTermTick = tick;
58
            data.frequencyShortTermCount = 1;
59
        }
60
        else if (tick - data.frequencyShortTermTick < cc.frequencyShortTermTicks) {
61
            // Account for server side lag.
62
            if (!lag || TickTask.getLag(50L * (tick - data.frequencyShortTermTick), true) < 1.5f) {
63
                // Within range, add.
64
                data.frequencyShortTermCount ++;
65
            }
66
            else {
67
                // Too much lag, reset.
68
                data.frequencyShortTermTick = tick;
69
                data.frequencyShortTermCount = 1;
70
            }
71
        }
72
        else {
73
            data.frequencyShortTermTick = tick;
74
            data.frequencyShortTermCount = 1;
75
        }
76
77
        // Account for server side lag for the medium term check
78
        final float fullLag = lag ? TickTask.getLag(fullTime, true) : 1f;
79
        // Find if one or both are violations:
80
        final float fullViolation = (fullScore > fullTime * fullLag) ? (fullScore - fullTime * fullLag) : 0;
81
        final float shortTermWeight = 50f * cc.frequencyShortTermTicks / (float) cc.frequencyShortTermLimit; 
82
        final float shortTermViolation = data.frequencyShortTermCount > cc.frequencyShortTermLimit ? (data.frequencyShortTermCount - cc.frequencyShortTermLimit) * shortTermWeight : 0; 
83
        final float violation = Math.max(fullViolation, shortTermViolation);
84
        boolean cancel = false;
85
        if (violation > 0.0) {
86
            final double change = violation / 1000;
87
            data.frequencyVL += change;
88
            cancel = executeActions(player, data.frequencyVL, change, cc.frequencyActions).willCancel();
89
        }
90
        else if (data.frequencyVL > 0d && fullScore < fullTime * .75) {
91
            data.frequencyVL *= 0.95;
92
        }
93
        return cancel;
94
    }
95
}

How it counteracts this module

NCP's blockbreak Frequency limits breaks per time frame with two windows: a full-window bucket score (2 buckets of 1000ms each, BlockBreakConfig lines 81-82) where each break adds the interval modifier (45 in survival, 95 in creative, DefaultConfig lines 132-133) and a violation fires when the score passes the window duration, plus a short-term counter that flags when more than 7 breaks land inside 5 ticks (frequencyShortTermTicks 5, frequencyShortTermLimit 7, DefaultConfig lines 134-135; check lines 55-75). The default actions cancel at vl > 5.

The thresholds are tuned for instant-break chains. In survival, a block still takes about five ticks even with the module, so the chained rate of roughly 3.6 breaks per second stays far below the 7-in-5-ticks short-term limit, and the full-window score of 45 per break needs over 44 breaks in two seconds to exceed the 2000ms window, which the five-tick break time makes impossible. In creative mode the story flips: insta-breaks chained at one per tick flood both windows, and the 7-in-5-ticks limit trips within a few ticks. This check therefore only bites the module's creative-mode use, while survival hard-block mining is left to the FastBreak time differential.

anticheat BlockBreakSpeedSurvival (expected damage accumulation)

BlockBreakSpeedSurvival.java246 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.interaction.terrain;
20
21
import me.islandscout.hawk.Hawk;
22
import me.islandscout.hawk.HawkPlayer;
23
import me.islandscout.hawk.check.CustomCheck;
24
import me.islandscout.hawk.event.BlockDigEvent;
25
import me.islandscout.hawk.event.Event;
26
import me.islandscout.hawk.event.MoveEvent;
27
import me.islandscout.hawk.util.MathPlus;
28
import me.islandscout.hawk.util.Placeholder;
29
import me.islandscout.hawk.util.ServerUtils;
30
import me.islandscout.hawk.wrap.block.WrappedBlock;
31
import me.islandscout.hawk.wrap.itemstack.WrappedItemStack;
32
import org.bukkit.GameMode;
33
import org.bukkit.Location;
34
import org.bukkit.Material;
35
import org.bukkit.block.Block;
36
import org.bukkit.enchantments.Enchantment;
37
import org.bukkit.entity.Player;
38
import org.bukkit.potion.PotionEffectType;
39
import org.bukkit.util.Vector;
40
41
import java.util.HashMap;
42
import java.util.Map;
43
import java.util.UUID;
44
45
public class BlockBreakSpeedSurvival extends CustomCheck {
46
47
    private final Map<UUID, Long> interactTick;
48
    private final Map<UUID, Block> targetBlockMap;
49
    private final Map<UUID, Float> blockDamageCumulativeMap;
50
    private boolean CHECK_ON_GROUND;
51
    private final boolean PREVENT_SAME_TICK;
52
53
    public BlockBreakSpeedSurvival() {
54
        super("blockbreakspeedsurvival", true, 5, 10, 0.99, 5000, "%player% failed block break speed. Block: %block%, Speed: %speed%, VL: %vl%", null);
55
        interactTick = new HashMap<>();
56
        targetBlockMap = new HashMap<>();
57
        blockDamageCumulativeMap = new HashMap<>();
58
        CHECK_ON_GROUND = (boolean) customSetting("checkOnGround", "", false);
59
        PREVENT_SAME_TICK = (boolean)customSetting("flagSameTick", "", true);
60
    }
61
62
    @Override
63
    protected void check(Event event) {
64
        if(event instanceof MoveEvent && event.getHawkPlayer().isDigging())
65
            tickDig(event.getHawkPlayer());
66
        else if(event instanceof BlockDigEvent)
67
            checkEvent((BlockDigEvent) event);
68
    }
69
70
    private void tickDig(HawkPlayer pp) {
71
        Block target = targetBlockMap.get(pp.getUuid());
72
        if(target != null && pp.getPlayer().getGameMode() == GameMode.SURVIVAL) {
73
            float accumulatedDamage = blockDamageCumulativeMap.getOrDefault(pp.getUuid(), 0F);
74
            float damage = getDamage(target, pp);
75
            blockDamageCumulativeMap.put(pp.getUuid(), accumulatedDamage + damage);
76
        }
77
    }
78
79
    private void checkEvent(BlockDigEvent e) {
80
        Player p = e.getPlayer();
81
        HawkPlayer pp = e.getHawkPlayer();
82
        if(p.getGameMode() == GameMode.CREATIVE)
83
            return;
84
85
        if (e.getDigAction() == BlockDigEvent.DigAction.START) {
86
            targetBlockMap.put(p.getUniqueId(), e.getBlock());
87
            blockDamageCumulativeMap.put(p.getUniqueId(), 0F);
88
            interactTick.put(p.getUniqueId(), pp.getCurrentTick());
89
            tickDig(pp);
90
            return;
91
        }
92
93
        if (e.getDigAction() == BlockDigEvent.DigAction.COMPLETE) {
94
            float totalDamage = blockDamageCumulativeMap.getOrDefault(p.getUniqueId(), 0F);
95
96
            if(totalDamage < 1 || (PREVENT_SAME_TICK && pp.getCurrentTick() == interactTick.getOrDefault(p.getUniqueId(), 0L))) {
97
                double speedFactor = 1 / totalDamage;
98
                double vl = Math.min((speedFactor - 1) * 10, 10);
99
                Block b = e.getBlock();
100
                punish(pp, vl, true, e, new Placeholder("block", b.getType()), new Placeholder("speed", MathPlus.round(speedFactor, 2) + "x"));
101
                e.resync();
102
            }
103
            else {
104
                reward(pp);
105
            }
106
107
            targetBlockMap.put(p.getUniqueId(), null);
108
            blockDamageCumulativeMap.put(p.getUniqueId(), 0F);
109
        }
110
    }
111
112
    @Override
113
    public void removeData(Player p) {
114
        UUID uuid = p.getUniqueId();
115
        targetBlockMap.remove(uuid);
116
        blockDamageCumulativeMap.remove(uuid);
117
        interactTick.remove(uuid);
118
    }
119
120
    //Yes, I skidded this from NMS. plz don't sue me ;-;
121
    //I'm only trying to make this game more enjoyable for us players.
122
    //I'm pasting a bunch of methods here because I can't be bothered
123
    //to abstract AND synchronize all of this with the network thread
124
    //(and no, I'm not talking about the "synchronized" keyword).
125
126
    private float getDamage(Block block, HawkPlayer pp) {
127
        if(block == null || ServerUtils.getBlockAsync(block.getLocation()) == null)
128
            return 0;
129
        WrappedBlock wBlock = WrappedBlock.getWrappedBlock(block, pp.getClientVersion());
130
        float strength = wBlock.getStrength();
131
        return strength < 0.0F ? 0.0F : (!isDestroyableByHeldItem(wBlock, pp) ? getCurrentPlayerStrVsBlock(wBlock, false, pp) / strength / 100.0F : getCurrentPlayerStrVsBlock(wBlock, true, pp) / strength / 30.0F);
132
    }
133
134
    private boolean isDestroyableByHeldItem(WrappedBlock wBlock, HawkPlayer pp) {
135
        if (wBlock.isMaterialAlwaysDestroyable()) {
136
            return true;
137
        } else {
138
            WrappedItemStack itemstack = WrappedItemStack.getWrappedItemStack(pp.getHeldItem());
139
            return itemstack.canDestroySpecialBlock(wBlock.getBukkitBlock());
140
        }
141
    }
142
143
    private float getCurrentPlayerStrVsBlock(WrappedBlock wBlock, boolean flag, HawkPlayer pp) {
144
        float destroySpeed = getDestroySpeedOfHeldItem(wBlock, pp);
145
        if (destroySpeed > 1.0F && pp.getHeldItem() != null) {
146
            int enchLvl = pp.getHeldItem().getEnchantmentLevel(Enchantment.DIG_SPEED);
147
            WrappedItemStack itemstack = WrappedItemStack.getWrappedItemStack(pp.getHeldItem());
148
            if (enchLvl > 0) {
149
                float f1 = (float)(enchLvl * enchLvl + 1);
150
                if (!itemstack.canDestroySpecialBlock(wBlock.getBukkitBlock()) && destroySpeed <= 1.0F) {
151
                    destroySpeed += f1 * 0.08F;
152
                } else {
153
                    destroySpeed += f1;
154
                }
155
            }
156
        }
157
158
        for(org.bukkit.potion.PotionEffect potionEffect : pp.getPlayer().getActivePotionEffects()) {
159
160
            if(potionEffect.getType().equals(PotionEffectType.FAST_DIGGING)) {
161
                destroySpeed *= 1.0F + (potionEffect.getAmplifier() + 1) * 0.2F;
162
            }
163
164
            if(Hawk.getServerVersion() == 8) {
165
                if(potionEffect.getType().equals(PotionEffectType.SLOW_DIGGING)) {
166
                    float f1;
167
                    switch(potionEffect.getAmplifier()) {
168
                        case 0:
169
                            f1 = 0.3F;
170
                            break;
171
                        case 1:
172
                            f1 = 0.09F;
173
                            break;
174
                        case 2:
175
                            f1 = 0.0027F;
176
                            break;
177
                        case 3:
178
                        default:
179
                            f1 = 8.1E-4F;
180
                    }
181
182
                    destroySpeed *= f1;
183
                }
184
            }
185
            else {
186
                if(potionEffect.getType().equals(PotionEffectType.SLOW_DIGGING)) {
187
                    destroySpeed *= 1.0F - (potionEffect.getAmplifier() + 1) * 0.2F;
188
                }
189
            }
190
        }
191
192
        boolean waterWorkerEnch = pp.getHeldItem() != null && pp.getHeldItem().getEnchantmentLevel(Enchantment.WATER_WORKER) > 0;
193
        if (this.a(pp) && !waterWorkerEnch) {
194
            destroySpeed /= 5.0F;
195
        }
196
197
        if (CHECK_ON_GROUND && !pp.isOnGround()) {
198
            destroySpeed /= 5.0F;
199
        }
200
201
        return destroySpeed;
202
    }
203
204
    private float getDestroySpeedOfHeldItem(WrappedBlock wBlock, HawkPlayer pp) {
205
        float f = 1.0F;
206
        WrappedItemStack itemStack = WrappedItemStack.getWrappedItemStack(pp.getHeldItem());
207
        f *= itemStack.getDestroySpeed(wBlock.getBukkitBlock());
208
        return f;
209
    }
210
211
    private boolean a(HawkPlayer pp) {
212
        Vector position = pp.getPosition();
213
        double d0 = position.getY() + 1.62;
214
        int i = floor(position.getX());
215
        int j = (int)d((float)floor(d0));
216
        int k = floor(position.getZ());
217
        Block block = ServerUtils.getBlockAsync(new Location(pp.getWorld(), i, j, k));
218
        if(block == null)
219
            return false;
220
        if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) {
221
            float f = b(block.getData()) - 0.11111111F;
222
            float f1 = (float)(j + 1) - f;
223
            return d0 < (double)f1;
224
        } else {
225
            return false;
226
        }
227
    }
228
229
    private int floor(double var0) {
230
        int var2 = (int)var0;
231
        return var0 < (double)var2 ? var2 - 1 : var2;
232
    }
233
234
    private long d(double var0) {
235
        long var2 = (long)var0;
236
        return var0 < (double)var2 ? var2 - 1L : var2;
237
    }
238
239
    private float b(int i) {
240
        if (i >= 8) {
241
            i = 0;
242
        }
243
        return (i + 1) / 9.0F;
244
    }
245
246
}

How it counteracts this module

Hawk's BlockBreakSpeedSurvival rebuilds the break server-side and compares expected damage against elapsed time. On START_DIGGING it records the target block and resets the accumulator (lines 85-91), on every MoveEvent while digging it adds the block's expected per-tick damage, computed from the block strength and the player's held item, potion and water state through a copy of the vanilla formula (lines 70-77, 126-202), and on COMPLETE_DIGGING it compares: if the accumulated expected damage is under 1.0, or the break landed in the same tick as the start (the flagSameTick setting), the check computes speedFactor as 1/totalDamage, scores vl as min((speedFactor - 1) * 10, 10), punishes with a resync, and resets (lines 93-108).

For any block that should take more than about five ticks, the module's actual break lands before the server-side accumulator reaches 1.0, so totalDamage is under 1 and every accelerated hard block is flagged with a speed-factor violation: stone by hand, which should accumulate 1.0 over roughly 45 ticks, has accumulated about 0.11 by the fifth tick, so speedFactor is around 9 and the violation is clamped at 10 with a resync that snaps the block back. The same-tick branch catches the pathological case of an insta-break arriving with the dig start. Soft blocks that genuinely break in one or two ticks accumulate their full expected damage and pass, so the check's honest boundary matches the module's own: only the hardness-collapsed breaks are punished.

← Back to Analysis Hub