Sigma 4.11 KeepSprint module 2 files, 2203 lines

Sigma 4.11 KeepSprint: Full Source Analysis

Sigma 4.11's KeepSprint is a one-branch packet filter that tries to cancel every C0B STOP_SPRINTING entity-action so the sprint state survives hits.

info/sigmaclient/module/impl/movement/KeepSprint.java · GitHub source ↗

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

Packets This Module Uses

Analysis

Overview

Sigma 4.11's KeepSprint is a one-branch packet filter that tries to cancel every C0B STOP_SPRINTING entity-action so the sprint state survives hits. The intended mechanism is standard for 1.8 keep-sprint modules, but this port is doubly inert. First, the guard is e.isIncoming() && packet instanceof C0BPacketEntityAction: EventPacket.isIncoming() returns the negation of the outgoing flag, which NetworkManager sets true only on the receive path (channelRead0) and false on the send path (sendPacket), and C0B is a serverbound-only class, so no packet can ever satisfy both halves of the guard and the cancel branch is unreachable code. Second, the fork has already removed the vanilla sprint-stop-on-hit: EntityPlayer.attackTargetEntityWithCurrentItem carries the commented-out //this.setSprinting(false); inside its knockback block, so the client never emits the STOP this module exists to suppress. The module's wire footprint is zero: it sends nothing, cancels nothing, and leaves the fork's sprint-state diff in motionUpdates() untouched.

The inverted event guard

EventPacket is the fork's single packet event, fired from NetworkManager.sendPacket with the outgoing flag true and from channelRead0 with false; isIncoming() returns !outgoing. KeepSprint's guard therefore only admits packets the client received, but C0BPacketEntityAction is a client-to-server class that the server never sends, so the instanceof can never be true on the receive path. The branch that would cancel STOP_SPRINTING is unreachable in exactly the same way as FakeHacker's REACH and FLY branches, which are gated on the same isIncoming() predicate. The try/catch around the handler swallows nothing relevant; the ClassCastException guard is defensive noise.

The fork already removed the sprint-stop-on-hit

In vanilla 1.8.9, landing a hit while sprinting stops the sprint: EntityPlayer.attackTargetEntityWithCurrentItem calls setSprinting(false) inside the knockback block after a successful attack, which the fork's motionUpdates() state diff would turn into a C0B STOP_SPRINTING packet. In this fork those lines are commented out: //this.motionX *= 0.6D, //this.motionZ *= 0.6D and //this.setSprinting(false) sit dead inside the hasDamaged branch. The client therefore keeps sprinting through hits on its own, and the sprint-state diff in motionUpdates() (lines 185-193) never sees the false transition that would produce the STOP. The module's intended function is already performed by the fork itself.

Wire fingerprint

There is no fingerprint because there is no behavior. The C0B stream is the vanilla one produced by motionUpdates(): one START_SPRINTING when the flag rises, one STOP_SPRINTING when it falls, exactly as an unmodified client emits them. The module consumes EventPacket instances and cancels nothing; the only trace of its existence is the empty handler in the bytecode. As with FakeHacker, the honest conclusion is that the module's effect is nil and every anticheat observation of the module is an observation of nothing.

source KeepSprint.java

KeepSprint.java33 lines · JavaOriginal ↗
1
package info.sigmaclient.module.impl.movement;
2
3
import info.sigmaclient.event.Event;
4
import info.sigmaclient.event.RegisterEvent;
5
import info.sigmaclient.event.impl.EventPacket;
6
import info.sigmaclient.module.Module;
7
import info.sigmaclient.module.data.ModuleData;
8
import net.minecraft.network.play.client.C0BPacketEntityAction;
9
10
/**
11
 * Created by Arithmo on 5/1/2017 at 4:51 PM.
12
 */
13
public class KeepSprint extends Module {
14
15
    public KeepSprint(ModuleData data) {
16
        super(data);
17
    }
18
19
    @RegisterEvent(events = EventPacket.class)
20
    public void onEvent(Event event) {
21
        EventPacket e = (EventPacket) event;
22
        try {
23
            if (e.isIncoming() && e.getPacket() instanceof C0BPacketEntityAction) {
24
                C0BPacketEntityAction packet = (C0BPacketEntityAction) e.getPacket();
25
                if (packet.getAction() == C0BPacketEntityAction.Action.STOP_SPRINTING) {
26
                    e.setCancelled(true);
27
                }
28
            }
29
        } catch (ClassCastException exception) {
30
        }
31
    }
32
33
}

What this file does

The module is this file alone, authored by Arithmo in the same 2017 batch as WorldTime. The single handler registers for EventPacket, casts the event, and in a try/catch checks e.isIncoming() with the packet being a C0BPacketEntityAction whose action is STOP_SPRINTING, cancelling the event if so. The class never touches the player, never writes motion, and never constructs a packet; its entire surface is the one cancel. The isIncoming() predicate is the fatal flaw: NetworkManager fires the event for outgoing packets with the outgoing flag true (sendPacket) and for received packets with false (channelRead0), and isIncoming() returns the negation of that flag, so the guard admits only received packets, while C0B is a packet class that only travels client-to-server. The conjunction is unsatisfiable and the cancel is dead code. A working port would either drop the direction check or use isOutgoing().

source EntityPlayer.java (fork attack path)

EntityPlayer.java2170 lines · JavaOriginal ↗
1
package net.minecraft.entity.player;
2
3
import java.util.Collection;
4
import java.util.Iterator;
5
import java.util.List;
6
import java.util.UUID;
7
8
import com.google.common.base.Charsets;
9
import com.google.common.collect.Lists;
10
import com.mojang.authlib.GameProfile;
11
12
import info.sigmaclient.Client;
13
import info.sigmaclient.event.Event;
14
import info.sigmaclient.event.EventSystem;
15
import info.sigmaclient.event.impl.EventDeath;
16
import info.sigmaclient.event.impl.EventTick;
17
import info.sigmaclient.module.impl.combat.Criticals;
18
import info.sigmaclient.module.impl.combat.Killaura;
19
import info.sigmaclient.module.impl.player.Scaffold;
20
import info.sigmaclient.util.misc.ChatUtil;
21
import net.minecraft.block.Block;
22
import net.minecraft.block.BlockBed;
23
import net.minecraft.block.BlockDirectional;
24
import net.minecraft.block.material.Material;
25
import net.minecraft.block.state.IBlockState;
26
import net.minecraft.client.Minecraft;
27
import net.minecraft.command.server.CommandBlockLogic;
28
import net.minecraft.enchantment.EnchantmentHelper;
29
import net.minecraft.entity.Entity;
30
import net.minecraft.entity.EntityList;
31
import net.minecraft.entity.EntityLiving;
32
import net.minecraft.entity.EntityLivingBase;
33
import net.minecraft.entity.EnumCreatureAttribute;
34
import net.minecraft.entity.IEntityMultiPart;
35
import net.minecraft.entity.IMerchant;
36
import net.minecraft.entity.SharedMonsterAttributes;
37
import net.minecraft.entity.ai.attributes.IAttributeInstance;
38
import net.minecraft.entity.boss.EntityDragonPart;
39
import net.minecraft.entity.item.EntityBoat;
40
import net.minecraft.entity.item.EntityItem;
41
import net.minecraft.entity.item.EntityMinecart;
42
import net.minecraft.entity.monster.EntityMob;
43
import net.minecraft.entity.monster.IMob;
44
import net.minecraft.entity.passive.EntityHorse;
45
import net.minecraft.entity.passive.EntityPig;
46
import net.minecraft.entity.projectile.EntityArrow;
47
import net.minecraft.entity.projectile.EntityFishHook;
48
import net.minecraft.event.ClickEvent;
49
import net.minecraft.init.Blocks;
50
import net.minecraft.init.Items;
51
import net.minecraft.inventory.Container;
52
import net.minecraft.inventory.ContainerPlayer;
53
import net.minecraft.inventory.IInventory;
54
import net.minecraft.inventory.InventoryEnderChest;
55
import net.minecraft.item.EnumAction;
56
import net.minecraft.item.Item;
57
import net.minecraft.item.ItemArmor;
58
import net.minecraft.item.ItemBlock;
59
import net.minecraft.item.ItemStack;
60
import net.minecraft.nbt.NBTTagCompound;
61
import net.minecraft.nbt.NBTTagList;
62
import net.minecraft.network.play.client.C03PacketPlayer;
63
import net.minecraft.network.play.server.S12PacketEntityVelocity;
64
import net.minecraft.potion.Potion;
65
import net.minecraft.scoreboard.IScoreObjectiveCriteria;
66
import net.minecraft.scoreboard.Score;
67
import net.minecraft.scoreboard.ScoreObjective;
68
import net.minecraft.scoreboard.ScorePlayerTeam;
69
import net.minecraft.scoreboard.Scoreboard;
70
import net.minecraft.scoreboard.Team;
71
import net.minecraft.server.MinecraftServer;
72
import net.minecraft.stats.AchievementList;
73
import net.minecraft.stats.StatBase;
74
import net.minecraft.stats.StatList;
75
import net.minecraft.tileentity.TileEntitySign;
76
import net.minecraft.util.AxisAlignedBB;
77
import net.minecraft.util.BlockPos;
78
import net.minecraft.util.ChatComponentText;
79
import net.minecraft.util.DamageSource;
80
import net.minecraft.util.EnumFacing;
81
import net.minecraft.util.EnumParticleTypes;
82
import net.minecraft.util.FoodStats;
83
import net.minecraft.util.IChatComponent;
84
import net.minecraft.util.MathHelper;
85
import net.minecraft.util.Vec3;
86
import net.minecraft.world.EnumDifficulty;
87
import net.minecraft.world.IInteractionObject;
88
import net.minecraft.world.LockCode;
89
import net.minecraft.world.World;
90
import net.minecraft.world.WorldSettings;
91
92
public abstract class EntityPlayer extends EntityLivingBase {
93
    /**
94
     * Inventory of the player
95
     */
96
	protected final static Minecraft mc = Minecraft.getMinecraft();
97
    public InventoryPlayer inventory = new InventoryPlayer(this);
98
    private InventoryEnderChest theInventoryEnderChest = new InventoryEnderChest();
99
    public boolean isMurderer;
100
    public int onGroundTicks;
101
    /**
102
     * The Container for the player's inventory (which opens when they press E)
103
     */
104
    public Container inventoryContainer;
105
106
    /**
107
     * The Container the player has open.
108
     */
109
    public Container openContainer;
110
111
    /**
112
     * The food object of the player, the general hunger logic.
113
     */
114
    protected FoodStats foodStats = new FoodStats();
115
116
    /**
117
     * Used to tell if the player pressed jump twice. If this is at 0 and it's
118
     * pressed (And they are allowed to fly, as defined in the player's
119
     * movementInput) it sets this to 7. If it's pressed and it's greater than 0
120
     * enable fly.
121
     */
122
    protected int flyToggleTimer;
123
    public float prevCameraYaw;
124
    public float cameraYaw;
125
126
    /**
127
     * Used by EntityPlayer to prevent too many xp orbs from getting absorbed at
128
     * once.
129
     */
130
    public int xpCooldown;
131
    public double field_71091_bM;
132
    public double field_71096_bN;
133
    public double field_71097_bO;
134
    public double field_71094_bP;
135
    public double field_71095_bQ;
136
    public double field_71085_bR;
137
138
    /**
139
     * Boolean value indicating weather a player is sleeping or not
140
     */
141
    protected boolean sleeping;
142
143
    /**
144
     * the current location of the player
145
     */
146
    public BlockPos playerLocation;
147
    private int sleepTimer;
148
    public float field_71079_bU;
149
    public float field_71082_cx;
150
    public float field_71089_bV;
151
152
    /**
153
     * holds the spawn chunk of the player
154
     */
155
    private BlockPos spawnChunk;
156
157
    /**
158
     * Whether this player's spawn point is forced, preventing execution of bed
159
     * checks.
160
     */
161
    private boolean spawnForced;
162
163
    /**
164
     * Holds the coordinate of the player when enter a minecraft to ride.
165
     */
166
    private BlockPos startMinecartRidingCoordinate;
167
168
    /**
169
     * The player's capabilities. (See class PlayerCapabilities)
170
     */
171
    public PlayerCapabilities capabilities = new PlayerCapabilities();
172
173
    /**
174
     * The current experience level the player is on.
175
     */
176
    public int experienceLevel;
177
178
    /**
179
     * The total amount of experience the player has. This also includes the
180
     * amount of experience within their Experience Bar.
181
     */
182
    public int experienceTotal;
183
184
    /**
185
     * The current amount of experience the player has within their Experience
186
     * Bar.
187
     */
188
    public float experience;
189
    private int field_175152_f;
190
191
    /**
192
     * This is the item that is in use when the player is holding down the
193
     * useItemButton (e.g., bow, food, sword)
194
     */
195
    private ItemStack itemInUse;
196
197
    /**
198
     * This field starts off equal to getMaxItemUseDuration and is decremented
199
     * on each tick
200
     */
201
    public int itemInUseCount;
202
    protected float speedOnGround = 0.1F;
203
    protected float speedInAir = 0.02F;
204
    private int field_82249_h;
205
206
    /**
207
     * The player's unique game profile
208
     */
209
    private final GameProfile gameProfile;
210
    private boolean field_175153_bG = false;
211
212
    /**
213
     * An instance of a fishing rod's hook. If this isn't null, the icon image
214
     * of the fishing rod is slightly different
215
     */
216
    public EntityFishHook fishEntity;
217
    private static final String __OBFID = "CL_00001711";
218
219
    public EntityPlayer(World worldIn, GameProfile p_i45324_2_) {
220
        super(worldIn);
221
        this.entityUniqueID = getUUID(p_i45324_2_);
222
        this.gameProfile = p_i45324_2_;
223
        this.inventoryContainer = new ContainerPlayer(this.inventory, !worldIn.isRemote, this);
224
        this.openContainer = this.inventoryContainer;
225
        BlockPos var3 = worldIn.getSpawnPoint();
226
        this.setLocationAndAngles((double) var3.getX() + 0.5D, (double) (var3.getY() + 1), (double) var3.getZ() + 0.5D, 0.0F, 0.0F);
227
        this.field_70741_aB = 180.0F;
228
        this.fireResistance = 20;
229
    }
230
231
    protected void applyEntityAttributes() {
232
        super.applyEntityAttributes();
233
        this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(1.0D);
234
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.10000000149011612D);
235
    }
236
237
    protected void entityInit() {
238
        super.entityInit();
239
        this.dataWatcher.addObject(16, Byte.valueOf((byte) 0));
240
        this.dataWatcher.addObject(17, Float.valueOf(0.0F));
241
        this.dataWatcher.addObject(18, Integer.valueOf(0));
242
        this.dataWatcher.addObject(10, Byte.valueOf((byte) 0));
243
    }
244
245
    /**
246
     * returns the ItemStack containing the itemInUse
247
     */
248
    public ItemStack getItemInUse() {
249
        return this.itemInUse;
250
    }
251
252
    /**
253
     * Returns the item in use count
254
     */
255
    public int getItemInUseCount() {
256
        return this.itemInUseCount;
257
    }
258
259
    /**
260
     * Checks if the entity is currently using an item (e.g., bow, food, sword)
261
     * by holding down the useItemButton
262
     */
263
    public boolean isUsingItem() {
264
        return this.itemInUse != null;
265
    }
266
267
    /**
268
     * gets the duration for how long the current itemInUse has been in use
269
     */
270
    public int getItemInUseDuration() {
271
        return this.isUsingItem() ? this.itemInUse.getMaxItemUseDuration() - this.itemInUseCount : 0;
272
    }
273
274
    public void stopUsingItem() {
275
        if (this.itemInUse != null) {
276
            this.itemInUse.onPlayerStoppedUsing(this.worldObj, this, this.itemInUseCount);
277
        }
278
279
        this.clearItemInUse();
280
    }
281
282
    public void clearItemInUse() {
283
        this.itemInUse = null;
284
        this.itemInUseCount = 0;
285
286
        if (!this.worldObj.isRemote) {
287
            this.setEating(false);
288
        }
289
    }
290
291
    public boolean isBlocking() {
292
        return this.isUsingItem() && this.itemInUse.getItem().getItemUseAction(this.itemInUse) == EnumAction.BLOCK;
293
    }
294
295
    /**
296
     * Called to update the entity's position/logic.
297
     */
298
    public void onUpdate() {
299
        Event e = EventSystem.getInstance(EventTick.class);
300
        e.fire();
301
        if (e.isCancelled()) {
302
            return;
303
        }
304
        this.noClip = this.func_175149_v();
305
306
        if (this.func_175149_v()) {
307
            this.onGround = false;
308
        }
309
310
        if (this.itemInUse != null) {
311
            ItemStack var1 = this.inventory.getCurrentItem();
312
313
            if (var1 == this.itemInUse) {
314
                if (this.itemInUseCount <= 25 && this.itemInUseCount % 4 == 0) {
315
                    this.updateItemUse(var1, 5);
316
                }
317
318
                if (--this.itemInUseCount == 0 && !this.worldObj.isRemote) {
319
                    this.onItemUseFinish();
320
                }
321
            } else {
322
                this.clearItemInUse();
323
            }
324
        }
325
326
        if (this.xpCooldown > 0) {
327
            --this.xpCooldown;
328
        }
329
330
        if (this.isPlayerSleeping()) {
331
            ++this.sleepTimer;
332
333
            if (this.sleepTimer > 100) {
334
                this.sleepTimer = 100;
335
            }
336
337
            if (!this.worldObj.isRemote) {
338
                if (!this.func_175143_p()) {
339
                    this.wakeUpPlayer(true, true, false);
340
                } else if (this.worldObj.isDaytime()) {
341
                    this.wakeUpPlayer(false, true, true);
342
                }
343
            }
344
        } else if (this.sleepTimer > 0) {
345
            ++this.sleepTimer;
346
347
            if (this.sleepTimer >= 110) {
348
                this.sleepTimer = 0;
349
            }
350
        }
351
352
        super.onUpdate();
353
354
        if (!this.worldObj.isRemote && this.openContainer != null && !this.openContainer.canInteractWith(this)) {
355
            this.closeScreen();
356
            this.openContainer = this.inventoryContainer;
357
        }
358
359
        if (this.isBurning() && this.capabilities.disableDamage) {
360
            this.extinguish();
361
        }
362
363
        this.field_71091_bM = this.field_71094_bP;
364
        this.field_71096_bN = this.field_71095_bQ;
365
        this.field_71097_bO = this.field_71085_bR;
366
        double var14 = this.posX - this.field_71094_bP;
367
        double var3 = this.posY - this.field_71095_bQ;
368
        double var5 = this.posZ - this.field_71085_bR;
369
        double var7 = 10.0D;
370
371
        if (var14 > var7) {
372
            this.field_71091_bM = this.field_71094_bP = this.posX;
373
        }
374
375
        if (var5 > var7) {
376
            this.field_71097_bO = this.field_71085_bR = this.posZ;
377
        }
378
379
        if (var3 > var7) {
380
            this.field_71096_bN = this.field_71095_bQ = this.posY;
381
        }
382
383
        if (var14 < -var7) {
384
            this.field_71091_bM = this.field_71094_bP = this.posX;
385
        }
386
387
        if (var5 < -var7) {
388
            this.field_71097_bO = this.field_71085_bR = this.posZ;
389
        }
390
391
        if (var3 < -var7) {
392
            this.field_71096_bN = this.field_71095_bQ = this.posY;
393
        }
394
395
        this.field_71094_bP += var14 * 0.25D;
396
        this.field_71085_bR += var5 * 0.25D;
397
        this.field_71095_bQ += var3 * 0.25D;
398
399
        if (this.ridingEntity == null) {
400
            this.startMinecartRidingCoordinate = null;
401
        }
402
403
        if (!this.worldObj.isRemote) {
404
            this.foodStats.onUpdate(this);
405
            this.triggerAchievement(StatList.minutesPlayedStat);
406
407
            if (this.isEntityAlive()) {
408
                this.triggerAchievement(StatList.timeSinceDeathStat);
409
            }
410
        }
411
412
        int var9 = 29999999;
413
        double var10 = MathHelper.clamp_double(this.posX, -2.9999999E7D, 2.9999999E7D);
414
        double var12 = MathHelper.clamp_double(this.posZ, -2.9999999E7D, 2.9999999E7D);
415
416
        if (var10 != this.posX || var12 != this.posZ) {
417
            this.setPosition(var10, this.posY, var12);
418
        }
419
    }
420
421
    /**
422
     * Return the amount of time this entity should stay in a portal before
423
     * being transported.
424
     */
425
    public int getMaxInPortalTime() {
426
        return this.capabilities.disableDamage ? 0 : 80;
427
    }
428
429
    protected String getSwimSound() {
430
        return "game.player.swim";
431
    }
432
433
    protected String getSplashSound() {
434
        return "game.player.swim.splash";
435
    }
436
437
    /**
438
     * Return the amount of cooldown before this entity can use a portal again.
439
     */
440
    public int getPortalCooldown() {
441
        return 10;
442
    }
443
444
    public void playSound(String name, float volume, float pitch) {
445
        this.worldObj.playSoundToNearExcept(this, name, volume, pitch);
446
    }
447
448
    /**
449
     * Plays sounds and makes particles for item in use state
450
     */
451
    protected void updateItemUse(ItemStack itemStackIn, int p_71010_2_) {
452
        if (itemStackIn.getItemUseAction() == EnumAction.DRINK) {
453
            this.playSound("random.drink", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
454
        }
455
456
        if (itemStackIn.getItemUseAction() == EnumAction.EAT) {
457
            for (int var3 = 0; var3 < p_71010_2_; ++var3) {
458
                Vec3 var4 = new Vec3(((double) this.rand.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
459
                var4 = var4.rotatePitch(-this.rotationPitch * (float) Math.PI / 180.0F);
460
                var4 = var4.rotateYaw(-this.rotationYaw * (float) Math.PI / 180.0F);
461
                double var5 = (double) (-this.rand.nextFloat()) * 0.6D - 0.3D;
462
                Vec3 var7 = new Vec3(((double) this.rand.nextFloat() - 0.5D) * 0.3D, var5, 0.6D);
463
                var7 = var7.rotatePitch(-this.rotationPitch * (float) Math.PI / 180.0F);
464
                var7 = var7.rotateYaw(-this.rotationYaw * (float) Math.PI / 180.0F);
465
                var7 = var7.addVector(this.posX, this.posY + (double) this.getEyeHeight(), this.posZ);
466
467
                if (itemStackIn.getHasSubtypes()) {
468
                    this.worldObj.spawnParticle(EnumParticleTypes.ITEM_CRACK, var7.xCoord, var7.yCoord, var7.zCoord, var4.xCoord, var4.yCoord + 0.05D, var4.zCoord, new int[]{Item.getIdFromItem(itemStackIn.getItem()), itemStackIn.getMetadata()});
469
                } else {
470
                    this.worldObj.spawnParticle(EnumParticleTypes.ITEM_CRACK, var7.xCoord, var7.yCoord, var7.zCoord, var4.xCoord, var4.yCoord + 0.05D, var4.zCoord, new int[]{Item.getIdFromItem(itemStackIn.getItem())});
471
                }
472
            }
473
474
            this.playSound("random.eat", 0.5F + 0.5F * (float) this.rand.nextInt(2), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
475
        }
476
    }
477
478
    /**
479
     * Used for when item use count runs out, ie: eating completed
480
     */
481
    protected void onItemUseFinish() {
482
        if (this.itemInUse != null) {
483
            this.updateItemUse(this.itemInUse, 16);
484
            int var1 = this.itemInUse.stackSize;
485
            ItemStack var2 = this.itemInUse.onItemUseFinish(this.worldObj, this);
486
487
            if (var2 != this.itemInUse || var2 != null && var2.stackSize != var1) {
488
                this.inventory.mainInventory[this.inventory.currentItem] = var2;
489
490
                if (var2.stackSize == 0) {
491
                    this.inventory.mainInventory[this.inventory.currentItem] = null;
492
                }
493
            }
494
495
            this.clearItemInUse();
496
        }
497
    }
498
499
    public void handleHealthUpdate(byte p_70103_1_) {
500
        if (p_70103_1_ == 9) {
501
            this.onItemUseFinish();
502
        } else if (p_70103_1_ == 23) {
503
            this.field_175153_bG = false;
504
        } else if (p_70103_1_ == 22) {
505
            this.field_175153_bG = true;
506
        } else {
507
            super.handleHealthUpdate(p_70103_1_);
508
        }
509
    }
510
511
    /**
512
     * Dead and sleeping entities cannot move
513
     */
514
    protected boolean isMovementBlocked() {
515
        return this.getHealth() <= 0.0F || this.isPlayerSleeping();
516
    }
517
518
    /**
519
     * set current crafting inventory back to the 2x2 square
520
     */
521
    protected void closeScreen() {
522
        this.openContainer = this.inventoryContainer;
523
    }
524
525
    /**
526
     * Handles updating while being ridden by an entity
527
     */
528
    public void updateRidden() {
529
        if (!this.worldObj.isRemote && this.isSneaking()) {
530
            this.mountEntity((Entity) null);
531
            this.setSneaking(false);
532
        } else {
533
            double var1 = this.posX;
534
            double var3 = this.posY;
535
            double var5 = this.posZ;
536
            float var7 = this.rotationYaw;
537
            float var8 = this.rotationPitch;
538
            super.updateRidden();
539
            this.prevCameraYaw = this.cameraYaw;
540
            this.cameraYaw = 0.0F;
541
            this.addMountedMovementStat(this.posX - var1, this.posY - var3, this.posZ - var5);
542
543
            if (this.ridingEntity instanceof EntityPig) {
544
                this.rotationPitch = var8;
545
                this.rotationYaw = var7;
546
                this.renderYawOffset = ((EntityPig) this.ridingEntity).renderYawOffset;
547
            }
548
        }
549
    }
550
551
    /**
552
     * Keeps moving the entity up so it isn't colliding with blocks and other
553
     * requirements for this entity to be spawned (only actually used on players
554
     * though its also on Entity)
555
     */
556
    public void preparePlayerToSpawn() {
557
        this.setSize(0.6F, 1.8F);
558
        super.preparePlayerToSpawn();
559
        this.setHealth(this.getMaxHealth());
560
        this.deathTime = 0;
561
    }
562
563
    protected void updateEntityActionState() {
564
        super.updateEntityActionState();
565
        this.updateArmSwingProgress();
566
        this.rotationYawHead = this.rotationYaw;
567
    }
568
569
    /**
570
     * Called frequently so the entity can update its state every tick as
571
     * required. For example, zombies and skeletons use this to react to
572
     * sunlight and start to burn.
573
     */
574
    public void onLivingUpdate() {
575
        if (this.flyToggleTimer > 0) {
576
            --this.flyToggleTimer;
577
        }
578
579
        if (this.worldObj.getDifficulty() == EnumDifficulty.PEACEFUL && this.worldObj.getGameRules().getGameRuleBooleanValue("naturalRegeneration")) {
580
            if (this.getHealth() < this.getMaxHealth() && this.ticksExisted % 20 == 0) {
581
                this.heal(1.0F);
582
            }
583
584
            if (this.foodStats.needFood() && this.ticksExisted % 10 == 0) {
585
                this.foodStats.setFoodLevel(this.foodStats.getFoodLevel() + 1);
586
            }
587
        }
588
589
        this.inventory.decrementAnimations();
590
        this.prevCameraYaw = this.cameraYaw;
591
        super.onLivingUpdate();
592
        IAttributeInstance var1 = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
593
594
        if (!this.worldObj.isRemote) {
595
            var1.setBaseValue((double) this.capabilities.getWalkSpeed());
596
        }
597
598
        this.jumpMovementFactor = this.speedInAir;
599
600
        if (this.isSprinting()) {
601
            this.jumpMovementFactor = (float) ((double) this.jumpMovementFactor + (double) this.speedInAir * 0.3D);
602
        }
603
604
        this.setAIMoveSpeed((float) var1.getAttributeValue());
605
        float var2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
606
        float var3 = (float) (Math.atan(-this.motionY * 0.20000000298023224D) * 15.0D);
607
608
        if (var2 > 0.1F) {
609
            var2 = 0.1F;
610
        }
611
612
        if (!this.onGround || this.getHealth() <= 0.0F) {
613
            var2 = 0.0F;
614
        }
615
616
        if (this.onGround || this.getHealth() <= 0.0F) {
617
            var3 = 0.0F;
618
        }
619
620
        this.cameraYaw += (var2 - this.cameraYaw) * 0.4F;
621
        this.cameraPitch += (var3 - this.cameraPitch) * 0.8F;
622
623
        if (this.getHealth() > 0.0F && !this.func_175149_v()) {
624
            AxisAlignedBB var4 = null;
625
626
            if (this.ridingEntity != null && !this.ridingEntity.isDead) {
627
                var4 = this.getEntityBoundingBox().union(this.ridingEntity.getEntityBoundingBox()).expand(1.0D, 0.0D, 1.0D);
628
            } else {
629
                var4 = this.getEntityBoundingBox().expand(1.0D, 0.5D, 1.0D);
630
            }
631
632
            List var5 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, var4);
633
634
            for (int var6 = 0; var6 < var5.size(); ++var6) {
635
                Entity var7 = (Entity) var5.get(var6);
636
637
                if (!var7.isDead) {
638
                    this.collideWithPlayer(var7);
639
                }
640
            }
641
        }
642
    }
643
644
    private void collideWithPlayer(Entity p_71044_1_) {
645
        p_71044_1_.onCollideWithPlayer(this);
646
    }
647
648
    public int getScore() {
649
        return this.dataWatcher.getWatchableObjectInt(18);
650
    }
651
652
    /**
653
     * Set player's score
654
     */
655
    public void setScore(int p_85040_1_) {
656
        this.dataWatcher.updateObject(18, Integer.valueOf(p_85040_1_));
657
    }
658
659
    /**
660
     * Add to player's score
661
     */
662
    public void addScore(int p_85039_1_) {
663
        int var2 = this.getScore();
664
        this.dataWatcher.updateObject(18, Integer.valueOf(var2 + p_85039_1_));
665
    }
666
667
    /**
668
     * Called when the mob's health reaches 0.
669
     */
670
    public void onDeath(DamageSource cause) {
671
        Event event = EventSystem.getInstance(EventDeath.class);
672
        event.fire();
673
        if (event.isCancelled()) {
674
            return;
675
        }
676
        super.onDeath(cause);
677
        this.setSize(0.2F, 0.2F);
678
        this.setPosition(this.posX, this.posY, this.posZ);
679
        this.motionY = 0.10000000149011612D;
680
681
        if (this.getName().equals("Notch")) {
682
            this.func_146097_a(new ItemStack(Items.apple, 1), true, false);
683
        }
684
685
        if (!this.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) {
686
            this.inventory.dropAllItems();
687
        }
688
689
        if (cause != null) {
690
            this.motionX = (double) (-MathHelper.cos((this.attackedAtYaw + this.rotationYaw) * (float) Math.PI / 180.0F) * 0.1F);
691
            this.motionZ = (double) (-MathHelper.sin((this.attackedAtYaw + this.rotationYaw) * (float) Math.PI / 180.0F) * 0.1F);
692
        } else {
693
            this.motionX = this.motionZ = 0.0D;
694
        }
695
696
        this.triggerAchievement(StatList.deathsStat);
697
        this.func_175145_a(StatList.timeSinceDeathStat);
698
    }
699
700
    /**
701
     * Returns the sound this mob makes when it is hurt.
702
     */
703
    protected String getHurtSound() {
704
        return "game.player.hurt";
705
    }
706
707
    /**
708
     * Returns the sound this mob makes on death.
709
     */
710
    protected String getDeathSound() {
711
        return "game.player.die";
712
    }
713
714
    /**
715
     * Adds a value to the player score. Currently not actually used and the
716
     * entity passed in does nothing. Args: entity, scoreToAdd
717
     */
718
    public void addToPlayerScore(Entity entityIn, int amount) {
719
        this.addScore(amount);
720
        Collection var3 = this.getWorldScoreboard().func_96520_a(IScoreObjectiveCriteria.totalKillCount);
721
722
        if (entityIn instanceof EntityPlayer) {
723
            this.triggerAchievement(StatList.playerKillsStat);
724
            var3.addAll(this.getWorldScoreboard().func_96520_a(IScoreObjectiveCriteria.playerKillCount));
725
            var3.addAll(this.func_175137_e(entityIn));
726
        } else {
727
            this.triggerAchievement(StatList.mobKillsStat);
728
        }
729
730
        Iterator var4 = var3.iterator();
731
732
        while (var4.hasNext()) {
733
            ScoreObjective var5 = (ScoreObjective) var4.next();
734
            Score var6 = this.getWorldScoreboard().getValueFromObjective(this.getName(), var5);
735
            var6.func_96648_a();
736
        }
737
    }
738
739
    private Collection func_175137_e(Entity p_175137_1_) {
740
        ScorePlayerTeam var2 = this.getWorldScoreboard().getPlayersTeam(this.getName());
741
742
        if (var2 != null) {
743
            int var3 = var2.func_178775_l().func_175746_b();
744
745
            if (var3 >= 0 && var3 < IScoreObjectiveCriteria.field_178793_i.length) {
746
                Iterator var4 = this.getWorldScoreboard().func_96520_a(IScoreObjectiveCriteria.field_178793_i[var3]).iterator();
747
748
                while (var4.hasNext()) {
749
                    ScoreObjective var5 = (ScoreObjective) var4.next();
750
                    Score var6 = this.getWorldScoreboard().getValueFromObjective(p_175137_1_.getName(), var5);
751
                    var6.func_96648_a();
752
                }
753
            }
754
        }
755
756
        ScorePlayerTeam var7 = this.getWorldScoreboard().getPlayersTeam(p_175137_1_.getName());
757
758
        if (var7 != null) {
759
            int var8 = var7.func_178775_l().func_175746_b();
760
761
            if (var8 >= 0 && var8 < IScoreObjectiveCriteria.field_178792_h.length) {
762
                return this.getWorldScoreboard().func_96520_a(IScoreObjectiveCriteria.field_178792_h[var8]);
763
            }
764
        }
765
766
        return Lists.newArrayList();
767
    }
768
769
    /**
770
     * Called when player presses the drop item key
771
     */
772
    public EntityItem dropOneItem(boolean p_71040_1_) {
773
        return this.func_146097_a(this.inventory.decrStackSize(this.inventory.currentItem, p_71040_1_ && this.inventory.getCurrentItem() != null ? this.inventory.getCurrentItem().stackSize : 1), false, true);
774
    }
775
776
    /**
777
     * Args: itemstack, flag
778
     */
779
    public EntityItem dropPlayerItemWithRandomChoice(ItemStack itemStackIn, boolean p_71019_2_) {
780
        return this.func_146097_a(itemStackIn, false, false);
781
    }
782
783
    public EntityItem func_146097_a(ItemStack p_146097_1_, boolean p_146097_2_, boolean p_146097_3_) {
784
        if (p_146097_1_ == null) {
785
            return null;
786
        } else if (p_146097_1_.stackSize == 0) {
787
            return null;
788
        } else {
789
            double var4 = this.posY - 0.30000001192092896D + (double) this.getEyeHeight();
790
            EntityItem var6 = new EntityItem(this.worldObj, this.posX, var4, this.posZ, p_146097_1_);
791
            var6.setPickupDelay(40);
792
793
            if (p_146097_3_) {
794
                var6.setThrower(this.getName());
795
            }
796
797
            float var7;
798
            float var8;
799
800
            if (p_146097_2_) {
801
                var7 = this.rand.nextFloat() * 0.5F;
802
                var8 = this.rand.nextFloat() * (float) Math.PI * 2.0F;
803
                var6.motionX = (double) (-MathHelper.sin(var8) * var7);
804
                var6.motionZ = (double) (MathHelper.cos(var8) * var7);
805
                var6.motionY = 0.20000000298023224D;
806
            } else {
807
                var7 = 0.3F;
808
                var6.motionX = (double) (-MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float) Math.PI) * var7);
809
                var6.motionZ = (double) (MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float) Math.PI) * var7);
810
                var6.motionY = (double) (-MathHelper.sin(this.rotationPitch / 180.0F * (float) Math.PI) * var7 + 0.1F);
811
                var8 = this.rand.nextFloat() * (float) Math.PI * 2.0F;
812
                var7 = 0.02F * this.rand.nextFloat();
813
                var6.motionX += Math.cos((double) var8) * (double) var7;
814
                var6.motionY += (double) ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F);
815
                var6.motionZ += Math.sin((double) var8) * (double) var7;
816
            }
817
818
            this.joinEntityItemWithWorld(var6);
819
820
            if (p_146097_3_) {
821
                this.triggerAchievement(StatList.dropStat);
822
            }
823
824
            return var6;
825
        }
826
    }
827
828
    /**
829
     * Joins the passed in entity item with the world. Args: entityItem
830
     */
831
    protected void joinEntityItemWithWorld(EntityItem p_71012_1_) {
832
        this.worldObj.spawnEntityInWorld(p_71012_1_);
833
    }
834
835
    public float func_180471_a(Block p_180471_1_) {
836
        float var2 = this.inventory.getStrVsBlock(p_180471_1_);
837
838
        if (var2 > 1.0F) {
839
            int var3 = EnchantmentHelper.getEfficiencyModifier(this);
840
            ItemStack var4 = this.inventory.getCurrentItem();
841
842
            if (var3 > 0 && var4 != null) {
843
                var2 += (float) (var3 * var3 + 1);
844
            }
845
        }
846
847
        if (this.isPotionActive(Potion.digSpeed)) {
848
            var2 *= 1.0F + (float) (this.getActivePotionEffect(Potion.digSpeed).getAmplifier() + 1) * 0.2F;
849
        }
850
851
        if (this.isPotionActive(Potion.digSlowdown)) {
852
            float var5 = 1.0F;
853
854
            switch (this.getActivePotionEffect(Potion.digSlowdown).getAmplifier()) {
855
                case 0:
856
                    var5 = 0.3F;
857
                    break;
858
859
                case 1:
860
                    var5 = 0.09F;
861
                    break;
862
863
                case 2:
864
                    var5 = 0.0027F;
865
                    break;
866
867
                case 3:
868
                default:
869
                    var5 = 8.1E-4F;
870
            }
871
872
            var2 *= var5;
873
        }
874
875
        if (this.isInsideOfMaterial(Material.water) && !EnchantmentHelper.getAquaAffinityModifier(this)) {
876
            var2 /= 5.0F;
877
        }
878
879
        if (!this.onGround) {
880
            var2 /= 5.0F;
881
        }
882
883
        return var2;
884
    }
885
886
    /**
887
     * Checks if the player has the ability to harvest a block (checks current
888
     * inventory item for a tool if necessary)
889
     */
890
    public boolean canHarvestBlock(Block p_146099_1_) {
891
        return this.inventory.func_146025_b(p_146099_1_);
892
    }
893
894
    /**
895
     * (abstract) Protected helper method to read subclass entity data from NBT.
896
     */
897
    public void readEntityFromNBT(NBTTagCompound tagCompund) {
898
        super.readEntityFromNBT(tagCompund);
899
        this.entityUniqueID = getUUID(this.gameProfile);
900
        NBTTagList var2 = tagCompund.getTagList("Inventory", 10);
901
        this.inventory.readFromNBT(var2);
902
        this.inventory.currentItem = tagCompund.getInteger("SelectedItemSlot");
903
        this.sleeping = tagCompund.getBoolean("Sleeping");
904
        this.sleepTimer = tagCompund.getShort("SleepTimer");
905
        this.experience = tagCompund.getFloat("XpP");
906
        this.experienceLevel = tagCompund.getInteger("XpLevel");
907
        this.experienceTotal = tagCompund.getInteger("XpTotal");
908
        this.field_175152_f = tagCompund.getInteger("XpSeed");
909
910
        if (this.field_175152_f == 0) {
911
            this.field_175152_f = this.rand.nextInt();
912
        }
913
914
        this.setScore(tagCompund.getInteger("Score"));
915
916
        if (this.sleeping) {
917
            this.playerLocation = new BlockPos(this);
918
            this.wakeUpPlayer(true, true, false);
919
        }
920
921
        if (tagCompund.hasKey("SpawnX", 99) && tagCompund.hasKey("SpawnY", 99) && tagCompund.hasKey("SpawnZ", 99)) {
922
            this.spawnChunk = new BlockPos(tagCompund.getInteger("SpawnX"), tagCompund.getInteger("SpawnY"), tagCompund.getInteger("SpawnZ"));
923
            this.spawnForced = tagCompund.getBoolean("SpawnForced");
924
        }
925
926
        this.foodStats.readNBT(tagCompund);
927
        this.capabilities.readCapabilitiesFromNBT(tagCompund);
928
929
        if (tagCompund.hasKey("EnderItems", 9)) {
930
            NBTTagList var3 = tagCompund.getTagList("EnderItems", 10);
931
            this.theInventoryEnderChest.loadInventoryFromNBT(var3);
932
        }
933
    }
934
935
    /**
936
     * (abstract) Protected helper method to write subclass entity data to NBT.
937
     */
938
    public void writeEntityToNBT(NBTTagCompound tagCompound) {
939
        super.writeEntityToNBT(tagCompound);
940
        tagCompound.setTag("Inventory", this.inventory.writeToNBT(new NBTTagList()));
941
        tagCompound.setInteger("SelectedItemSlot", this.inventory.currentItem);
942
        tagCompound.setBoolean("Sleeping", this.sleeping);
943
        tagCompound.setShort("SleepTimer", (short) this.sleepTimer);
944
        tagCompound.setFloat("XpP", this.experience);
945
        tagCompound.setInteger("XpLevel", this.experienceLevel);
946
        tagCompound.setInteger("XpTotal", this.experienceTotal);
947
        tagCompound.setInteger("XpSeed", this.field_175152_f);
948
        tagCompound.setInteger("Score", this.getScore());
949
950
        if (this.spawnChunk != null) {
951
            tagCompound.setInteger("SpawnX", this.spawnChunk.getX());
952
            tagCompound.setInteger("SpawnY", this.spawnChunk.getY());
953
            tagCompound.setInteger("SpawnZ", this.spawnChunk.getZ());
954
            tagCompound.setBoolean("SpawnForced", this.spawnForced);
955
        }
956
957
        this.foodStats.writeNBT(tagCompound);
958
        this.capabilities.writeCapabilitiesToNBT(tagCompound);
959
        tagCompound.setTag("EnderItems", this.theInventoryEnderChest.saveInventoryToNBT());
960
        ItemStack var2 = this.inventory.getCurrentItem();
961
962
        if (var2 != null && var2.getItem() != null) {
963
            tagCompound.setTag("SelectedItem", var2.writeToNBT(new NBTTagCompound()));
964
        }
965
    }
966
967
    /**
968
     * Called when the entity is attacked.
969
     */
970
    public boolean attackEntityFrom(DamageSource source, float amount) {
971
        if (this.func_180431_b(source)) {
972
            return false;
973
        } else if (this.capabilities.disableDamage && !source.canHarmInCreative()) {
974
            return false;
975
        } else {
976
            this.entityAge = 0;
977
978
            if (this.getHealth() <= 0.0F) {
979
                return false;
980
            } else {
981
                if (this.isPlayerSleeping() && !this.worldObj.isRemote) {
982
                    this.wakeUpPlayer(true, true, false);
983
                }
984
985
                if (source.isDifficultyScaled()) {
986
                    if (this.worldObj.getDifficulty() == EnumDifficulty.PEACEFUL) {
987
                        amount = 0.0F;
988
                    }
989
990
                    if (this.worldObj.getDifficulty() == EnumDifficulty.EASY) {
991
                        amount = amount / 2.0F + 1.0F;
992
                    }
993
994
                    if (this.worldObj.getDifficulty() == EnumDifficulty.HARD) {
995
                        amount = amount * 3.0F / 2.0F;
996
                    }
997
                }
998
999
                if (amount == 0.0F) {
1000
                    return false;
1001
                } else {
1002
                    Entity var3 = source.getEntity();
1003
1004
                    if (var3 instanceof EntityArrow && ((EntityArrow) var3).shootingEntity != null) {
1005
                        var3 = ((EntityArrow) var3).shootingEntity;
1006
                    }
1007
1008
                    return super.attackEntityFrom(source, amount);
1009
                }
1010
            }
1011
        }
1012
    }
1013
1014
    public boolean canAttackPlayer(EntityPlayer other) {
1015
        Team var2 = this.getTeam();
1016
        Team var3 = other.getTeam();
1017
        return var2 == null ? true : (!var2.isSameTeam(var3) ? true : var2.getAllowFriendlyFire());
1018
    }
1019
1020
    protected void damageArmor(float p_70675_1_) {
1021
        this.inventory.damageArmor(p_70675_1_);
1022
    }
1023
1024
    /**
1025
     * Returns the current armor value as determined by a call to
1026
     * InventoryPlayer.getTotalArmorValue
1027
     */
1028
    public int getTotalArmorValue() {
1029
        return this.inventory.getTotalArmorValue();
1030
    }
1031
1032
    /**
1033
     * When searching for vulnerable players, if a player is invisible, the
1034
     * return value of this is the chance of seeing them anyway.
1035
     */
1036
    public float getArmorVisibility() {
1037
        int var1 = 0;
1038
        ItemStack[] var2 = this.inventory.armorInventory;
1039
        int var3 = var2.length;
1040
1041
        for (int var4 = 0; var4 < var3; ++var4) {
1042
            ItemStack var5 = var2[var4];
1043
1044
            if (var5 != null) {
1045
                ++var1;
1046
            }
1047
        }
1048
1049
        return (float) var1 / (float) this.inventory.armorInventory.length;
1050
    }
1051
1052
    /**
1053
     * Deals damage to the entity. If its a EntityPlayer then will take damage
1054
     * from the armor first and then health second with the reduced value. Args:
1055
     * damageAmount
1056
     */
1057
    protected void damageEntity(DamageSource p_70665_1_, float p_70665_2_) {
1058
        if (!this.func_180431_b(p_70665_1_)) {
1059
            if (!p_70665_1_.isUnblockable() && this.isBlocking() && p_70665_2_ > 0.0F) {
1060
                p_70665_2_ = (1.0F + p_70665_2_) * 0.5F;
1061
            }
1062
1063
            p_70665_2_ = this.applyArmorCalculations(p_70665_1_, p_70665_2_);
1064
            p_70665_2_ = this.applyPotionDamageCalculations(p_70665_1_, p_70665_2_);
1065
            float var3 = p_70665_2_;
1066
            p_70665_2_ = Math.max(p_70665_2_ - this.getAbsorptionAmount(), 0.0F);
1067
            this.setAbsorptionAmount(this.getAbsorptionAmount() - (var3 - p_70665_2_));
1068
1069
            if (p_70665_2_ != 0.0F) {
1070
                this.addExhaustion(p_70665_1_.getHungerDamage());
1071
                float var4 = this.getHealth();
1072
                this.setHealth(this.getHealth() - p_70665_2_);
1073
                this.getCombatTracker().func_94547_a(p_70665_1_, var4, p_70665_2_);
1074
1075
                if (p_70665_2_ < 3.4028235E37F) {
1076
                    this.addStat(StatList.damageTakenStat, Math.round(p_70665_2_ * 10.0F));
1077
                }
1078
            }
1079
        }
1080
    }
1081
1082
    public void func_175141_a(TileEntitySign p_175141_1_) {
1083
    }
1084
1085
    public void func_146095_a(CommandBlockLogic p_146095_1_) {
1086
    }
1087
1088
    public void displayVillagerTradeGui(IMerchant villager) {
1089
    }
1090
1091
    /**
1092
     * Displays the GUI for interacting with a chest inventory. Args:
1093
     * chestInventory
1094
     */
1095
    public void displayGUIChest(IInventory chestInventory) {
1096
    }
1097
1098
    public void displayGUIHorse(EntityHorse p_110298_1_, IInventory p_110298_2_) {
1099
    }
1100
1101
    public void displayGui(IInteractionObject guiOwner) {
1102
    }
1103
1104
    /**
1105
     * Displays the GUI for interacting with a book.
1106
     */
1107
    public void displayGUIBook(ItemStack bookStack) {
1108
    }
1109
1110
    public boolean interactWith(Entity p_70998_1_) {
1111
        if (this.func_175149_v()) {
1112
            if (p_70998_1_ instanceof IInventory) {
1113
                this.displayGUIChest((IInventory) p_70998_1_);
1114
            }
1115
1116
            return false;
1117
        } else {
1118
            ItemStack var2 = this.getCurrentEquippedItem();
1119
            ItemStack var3 = var2 != null ? var2.copy() : null;
1120
1121
            if (!p_70998_1_.interactFirst(this)) {
1122
                if (var2 != null && p_70998_1_ instanceof EntityLivingBase) {
1123
                    if (this.capabilities.isCreativeMode) {
1124
                        var2 = var3;
1125
                    }
1126
1127
                    if (var2.interactWithEntity(this, (EntityLivingBase) p_70998_1_)) {
1128
                        if (var2.stackSize <= 0 && !this.capabilities.isCreativeMode) {
1129
                            this.destroyCurrentEquippedItem();
1130
                        }
1131
1132
                        return true;
1133
                    }
1134
                }
1135
1136
                return false;
1137
            } else {
1138
                if (var2 != null && var2 == this.getCurrentEquippedItem()) {
1139
                    if (var2.stackSize <= 0 && !this.capabilities.isCreativeMode) {
1140
                        this.destroyCurrentEquippedItem();
1141
                    } else if (var2.stackSize < var3.stackSize && this.capabilities.isCreativeMode) {
1142
                        var2.stackSize = var3.stackSize;
1143
                    }
1144
                }
1145
1146
                return true;
1147
            }
1148
        }
1149
    }
1150
1151
    /**
1152
     * Returns the currently being used item by the player.
1153
     */
1154
    public ItemStack getCurrentEquippedItem() {
1155
        return this.inventory.getCurrentItem();
1156
    }
1157
1158
    /**
1159
     * Destroys the currently equipped item from the player's inventory.
1160
     */
1161
    public void destroyCurrentEquippedItem() {
1162
        this.inventory.setInventorySlotContents(this.inventory.currentItem, (ItemStack) null);
1163
    }
1164
1165
    /**
1166
     * Returns the Y Offset of this entity.
1167
     */
1168
    public double getYOffset() {
1169
        return -0.35D;
1170
    }
1171
1172
    /**
1173
     * Attacks for the player the targeted entity with the currently equipped
1174
     * item. The equipped item has hitEntity called on it. Args: targetEntity
1175
     */
1176
    public void attackTargetEntityWithCurrentItem(Entity targetEntity) {
1177
        if (targetEntity.canAttackWithItem()) {
1178
            if (!targetEntity.hitByEntity(this)) {
1179
                float var2 = (float) this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
1180
                byte var3 = 0;
1181
                float enchantedCrit = 0.0F;
1182
                if (targetEntity instanceof EntityLivingBase) {
1183
                    enchantedCrit = EnchantmentHelper.func_152377_a(this.getHeldItem(), ((EntityLivingBase) targetEntity).getCreatureAttribute());
1184
                } else {
1185
                    enchantedCrit = EnchantmentHelper.func_152377_a(this.getHeldItem(), EnumCreatureAttribute.UNDEFINED);
1186
                }
1187
                int knockback = var3 + EnchantmentHelper.getRespiration(this);
1188
                if (this.isSprinting()) {
1189
                    ++knockback;
1190
                }
1191
                if (var2 > 0.0F || enchantedCrit > 0.0F) {
1192
                    boolean shouldCrit = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Potion.blindness) && this.ridingEntity == null && targetEntity instanceof EntityLivingBase;
1193
                    if (shouldCrit && var2 > 0.0F) {
1194
                        var2 *= 1.5F;
1195
                    }
1196
                    var2 += enchantedCrit;
1197
                    boolean var6 = false;
1198
                    int fire = EnchantmentHelper.getFireAspectModifier(this);
1199
                    if (targetEntity instanceof EntityLivingBase && fire > 0 && !targetEntity.isBurning()) {
1200
                        var6 = true;
1201
                        targetEntity.setFire(1);
1202
                    }
1203
                    double targetMotionX = targetEntity.motionX;
1204
                    double targetMotionY = targetEntity.motionY;
1205
                    double targetMotionZ = targetEntity.motionZ;
1206
                    boolean hasDamaged = targetEntity.attackEntityFrom(DamageSource.causePlayerDamage(this), var2);
1207
                    if (hasDamaged) {
1208
                        if (knockback > 0) {
1209
                            targetEntity.addVelocity((double) (-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F) * (float) knockback * 0.5F), 0.1D, (double) (MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F) * (float) knockback * 0.5F));
1210
                            //this.motionX *= 0.6D;
1211
                            //this.motionZ *= 0.6D;
1212
                            //this.setSprinting(false);
1213
                        }
1214
                        if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) {
1215
                            ((EntityPlayerMP) targetEntity).playerNetServerHandler.sendPacket(new S12PacketEntityVelocity(targetEntity));
1216
                            targetEntity.velocityChanged = false;
1217
                            targetEntity.motionX = targetMotionX;
1218
                            targetEntity.motionY = targetMotionY;
1219
                            targetEntity.motionZ = targetMotionZ;
1220
                        }
1221
                        if (shouldCrit) {
1222
                            this.onCriticalHit(targetEntity);
1223
                        }
1224
                        if (enchantedCrit > 0.0F) {
1225
                            this.onEnchantmentCritical(targetEntity);
1226
                        }
1227
                        if (var2 >= 18.0F) {
1228
                            this.triggerAchievement(AchievementList.overkill);
1229
                        }
1230
                        this.setLastAttacker(targetEntity);
1231
                        if (targetEntity instanceof EntityLivingBase) {
1232
                            EnchantmentHelper.func_151384_a((EntityLivingBase) targetEntity, this);
1233
                        }
1234
                        EnchantmentHelper.func_151385_b(this, targetEntity);
1235
                        ItemStack currentItem = this.getCurrentEquippedItem();
1236
                        Object targetEntityObject = targetEntity;
1237
                        if (targetEntity instanceof EntityDragonPart) {
1238
                            IEntityMultiPart var17 = ((EntityDragonPart) targetEntity).entityDragonObj;
1239
                            if (var17 instanceof EntityLivingBase) {
1240
                                targetEntityObject = (EntityLivingBase) var17;
1241
                            }
1242
                        }
1243
                        if (currentItem != null && targetEntityObject instanceof EntityLivingBase) {
1244
                            currentItem.hitEntity((EntityLivingBase) targetEntityObject, this);
1245
1246
                            if (currentItem.stackSize <= 0) {
1247
                                this.destroyCurrentEquippedItem();
1248
                            }
1249
                        }
1250
                        if (targetEntity instanceof EntityLivingBase) {
1251
                            this.addStat(StatList.damageDealtStat, Math.round(var2 * 10.0F));
1252
                            if (fire > 0) {
1253
                                targetEntity.setFire(fire * 4);
1254
                            }
1255
                        }
1256
                        this.addExhaustion(0.3F);
1257
                    } else if (var6) {
1258
                        targetEntity.extinguish();
1259
                    }
1260
                }
1261
            }
1262
        }
1263
    }
1264
1265
    /**
1266
     * Called when the player performs a critical hit on the Entity. Args:
1267
     * entity that was hit critically
1268
     */
1269
    public void onCriticalHit(Entity p_71009_1_) {
1270
    }
1271
1272
    public void onEnchantmentCritical(Entity p_71047_1_) {
1273
    }
1274
1275
    public void respawnPlayer() {
1276
    }
1277
1278
    /**
1279
     * Will get destroyed next tick.
1280
     */
1281
    public void setDead() {
1282
        super.setDead();
1283
        this.inventoryContainer.onContainerClosed(this);
1284
1285
        if (this.openContainer != null) {
1286
            this.openContainer.onContainerClosed(this);
1287
        }
1288
    }
1289
1290
    /**
1291
     * Checks if this entity is inside of an opaque block
1292
     */
1293
    public boolean isEntityInsideOpaqueBlock() {
1294
        return !this.sleeping && super.isEntityInsideOpaqueBlock();
1295
    }
1296
1297
    public boolean func_175144_cb() {
1298
        return false;
1299
    }
1300
1301
    /**
1302
     * Returns the GameProfile for this player
1303
     */
1304
    public GameProfile getGameProfile() {
1305
        return this.gameProfile;
1306
    }
1307
1308
    public EntityPlayer.EnumStatus func_180469_a(BlockPos p_180469_1_) {
1309
        if (!this.worldObj.isRemote) {
1310
            if (this.isPlayerSleeping() || !this.isEntityAlive()) {
1311
                return EntityPlayer.EnumStatus.OTHER_PROBLEM;
1312
            }
1313
1314
            if (!this.worldObj.provider.isSurfaceWorld()) {
1315
                return EntityPlayer.EnumStatus.NOT_POSSIBLE_HERE;
1316
            }
1317
1318
            if (this.worldObj.isDaytime()) {
1319
                return EntityPlayer.EnumStatus.NOT_POSSIBLE_NOW;
1320
            }
1321
1322
            if (Math.abs(this.posX - (double) p_180469_1_.getX()) > 3.0D || Math.abs(this.posY - (double) p_180469_1_.getY()) > 2.0D || Math.abs(this.posZ - (double) p_180469_1_.getZ()) > 3.0D) {
1323
                return EntityPlayer.EnumStatus.TOO_FAR_AWAY;
1324
            }
1325
1326
            double var2 = 8.0D;
1327
            double var4 = 5.0D;
1328
            List var6 = this.worldObj.getEntitiesWithinAABB(EntityMob.class, new AxisAlignedBB((double) p_180469_1_.getX() - var2, (double) p_180469_1_.getY() - var4, (double) p_180469_1_.getZ() - var2, (double) p_180469_1_.getX() + var2, (double) p_180469_1_.getY() + var4, (double) p_180469_1_.getZ() + var2));
1329
1330
            if (!var6.isEmpty()) {
1331
                return EntityPlayer.EnumStatus.NOT_SAFE;
1332
            }
1333
        }
1334
1335
        if (this.isRiding()) {
1336
            this.mountEntity((Entity) null);
1337
        }
1338
1339
        this.setSize(0.2F, 0.2F);
1340
1341
        if (this.worldObj.isBlockLoaded(p_180469_1_)) {
1342
            EnumFacing var7 = (EnumFacing) this.worldObj.getBlockState(p_180469_1_).getValue(BlockDirectional.AGE);
1343
            float var3 = 0.5F;
1344
            float var8 = 0.5F;
1345
1346
            switch (EntityPlayer.SwitchEnumFacing.field_179420_a[var7.ordinal()]) {
1347
                case 1:
1348
                    var8 = 0.9F;
1349
                    break;
1350
1351
                case 2:
1352
                    var8 = 0.1F;
1353
                    break;
1354
1355
                case 3:
1356
                    var3 = 0.1F;
1357
                    break;
1358
1359
                case 4:
1360
                    var3 = 0.9F;
1361
            }
1362
1363
            this.func_175139_a(var7);
1364
            this.setPosition((double) ((float) p_180469_1_.getX() + var3), (double) ((float) p_180469_1_.getY() + 0.6875F), (double) ((float) p_180469_1_.getZ() + var8));
1365
        } else {
1366
            this.setPosition((double) ((float) p_180469_1_.getX() + 0.5F), (double) ((float) p_180469_1_.getY() + 0.6875F), (double) ((float) p_180469_1_.getZ() + 0.5F));
1367
        }
1368
1369
        this.sleeping = true;
1370
        this.sleepTimer = 0;
1371
        this.playerLocation = p_180469_1_;
1372
        this.motionX = this.motionZ = this.motionY = 0.0D;
1373
1374
        if (!this.worldObj.isRemote) {
1375
            this.worldObj.updateAllPlayersSleepingFlag();
1376
        }
1377
1378
        return EntityPlayer.EnumStatus.OK;
1379
    }
1380
1381
    private void func_175139_a(EnumFacing p_175139_1_) {
1382
        this.field_71079_bU = 0.0F;
1383
        this.field_71089_bV = 0.0F;
1384
1385
        switch (EntityPlayer.SwitchEnumFacing.field_179420_a[p_175139_1_.ordinal()]) {
1386
            case 1:
1387
                this.field_71089_bV = -1.8F;
1388
                break;
1389
1390
            case 2:
1391
                this.field_71089_bV = 1.8F;
1392
                break;
1393
1394
            case 3:
1395
                this.field_71079_bU = 1.8F;
1396
                break;
1397
1398
            case 4:
1399
                this.field_71079_bU = -1.8F;
1400
        }
1401
    }
1402
1403
    /**
1404
     * Wake up the player if they're sleeping.
1405
     */
1406
    public void wakeUpPlayer(boolean p_70999_1_, boolean updateWorldFlag, boolean setSpawn) {
1407
        this.setSize(0.6F, 1.8F);
1408
        IBlockState var4 = this.worldObj.getBlockState(this.playerLocation);
1409
1410
        if (this.playerLocation != null && var4.getBlock() == Blocks.bed) {
1411
            this.worldObj.setBlockState(this.playerLocation, var4.withProperty(BlockBed.OCCUPIED_PROP, Boolean.valueOf(false)), 4);
1412
            BlockPos var5 = BlockBed.getSafeExitLocation(this.worldObj, this.playerLocation, 0);
1413
1414
            if (var5 == null) {
1415
                var5 = this.playerLocation.offsetUp();
1416
            }
1417
1418
            this.setPosition((double) ((float) var5.getX() + 0.5F), (double) ((float) var5.getY() + 0.1F), (double) ((float) var5.getZ() + 0.5F));
1419
        }
1420
1421
        this.sleeping = false;
1422
1423
        if (!this.worldObj.isRemote && updateWorldFlag) {
1424
            this.worldObj.updateAllPlayersSleepingFlag();
1425
        }
1426
1427
        this.sleepTimer = p_70999_1_ ? 0 : 100;
1428
1429
        if (setSpawn) {
1430
            this.func_180473_a(this.playerLocation, false);
1431
        }
1432
    }
1433
1434
    private boolean func_175143_p() {
1435
        return this.worldObj.getBlockState(this.playerLocation).getBlock() == Blocks.bed;
1436
    }
1437
1438
    public static BlockPos func_180467_a(World worldIn, BlockPos p_180467_1_, boolean p_180467_2_) {
1439
        if (worldIn.getBlockState(p_180467_1_).getBlock() != Blocks.bed) {
1440
            if (!p_180467_2_) {
1441
                return null;
1442
            } else {
1443
                Material var3 = worldIn.getBlockState(p_180467_1_).getBlock().getMaterial();
1444
                Material var4 = worldIn.getBlockState(p_180467_1_.offsetUp()).getBlock().getMaterial();
1445
                boolean var5 = !var3.isSolid() && !var3.isLiquid();
1446
                boolean var6 = !var4.isSolid() && !var4.isLiquid();
1447
                return var5 && var6 ? p_180467_1_ : null;
1448
            }
1449
        } else {
1450
            return BlockBed.getSafeExitLocation(worldIn, p_180467_1_, 0);
1451
        }
1452
    }
1453
1454
    /**
1455
     * Returns the orientation of the bed in degrees.
1456
     */
1457
    public float getBedOrientationInDegrees() {
1458
        if (this.playerLocation != null) {
1459
            EnumFacing var1 = (EnumFacing) this.worldObj.getBlockState(this.playerLocation).getValue(BlockDirectional.AGE);
1460
1461
            switch (EntityPlayer.SwitchEnumFacing.field_179420_a[var1.ordinal()]) {
1462
                case 1:
1463
                    return 90.0F;
1464
1465
                case 2:
1466
                    return 270.0F;
1467
1468
                case 3:
1469
                    return 0.0F;
1470
1471
                case 4:
1472
                    return 180.0F;
1473
            }
1474
        }
1475
1476
        return 0.0F;
1477
    }
1478
1479
    /**
1480
     * Returns whether player is sleeping or not
1481
     */
1482
    public boolean isPlayerSleeping() {
1483
        return this.sleeping;
1484
    }
1485
1486
    /**
1487
     * Returns whether or not the player is asleep and the screen has fully
1488
     * faded.
1489
     */
1490
    public boolean isPlayerFullyAsleep() {
1491
        return this.sleeping && this.sleepTimer >= 100;
1492
    }
1493
1494
    public int getSleepTimer() {
1495
        return this.sleepTimer;
1496
    }
1497
1498
    public void addChatComponentMessage(IChatComponent p_146105_1_) {
1499
    }
1500
1501
    public BlockPos func_180470_cg() {
1502
        return this.spawnChunk;
1503
    }
1504
1505
    public boolean isSpawnForced() {
1506
        return this.spawnForced;
1507
    }
1508
1509
    public void func_180473_a(BlockPos p_180473_1_, boolean p_180473_2_) {
1510
        if (p_180473_1_ != null) {
1511
            this.spawnChunk = p_180473_1_;
1512
            this.spawnForced = p_180473_2_;
1513
        } else {
1514
            this.spawnChunk = null;
1515
            this.spawnForced = false;
1516
        }
1517
    }
1518
1519
    /**
1520
     * Will trigger the specified trigger.
1521
     */
1522
    public void triggerAchievement(StatBase p_71029_1_) {
1523
        this.addStat(p_71029_1_, 1);
1524
    }
1525
1526
    /**
1527
     * Adds a value to a statistic field.
1528
     */
1529
    public void addStat(StatBase p_71064_1_, int p_71064_2_) {
1530
    }
1531
1532
    public void func_175145_a(StatBase p_175145_1_) {
1533
    }
1534
1535
    /**
1536
     * Causes this entity to do an upwards motion (jumping).
1537
     */
1538
    public void jump() {
1539
1540
        super.jump();
1541
        this.triggerAchievement(StatList.jumpStat);
1542
1543
        if (this.isSprinting()) {
1544
            this.addExhaustion(0.8F);
1545
        } else {
1546
            this.addExhaustion(0.2F);
1547
        }
1548
    }
1549
1550
    /**
1551
     * Moves the entity based on the specified heading. Args: strafe, forward
1552
     */
1553
    public void moveEntityWithHeading(float p_70612_1_, float p_70612_2_) {
1554
        double var3 = this.posX;
1555
        double var5 = this.posY;
1556
        double var7 = this.posZ;
1557
1558
        if (this.capabilities.isFlying && this.ridingEntity == null) {
1559
            double var9 = this.motionY;
1560
            float var11 = this.jumpMovementFactor;
1561
            this.jumpMovementFactor = this.capabilities.getFlySpeed() * (float) (this.isSprinting() ? 2 : 1);
1562
            super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
1563
            this.motionY = var9 * 0.6D;
1564
            this.jumpMovementFactor = var11;
1565
        } else {
1566
            super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
1567
        }
1568
1569
        this.addMovementStat(this.posX - var3, this.posY - var5, this.posZ - var7);
1570
    }
1571
1572
    /**
1573
     * the movespeed used for the new AI system
1574
     */
1575
    public float getAIMoveSpeed() {
1576
        return (float) this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();
1577
    }
1578
1579
    /**
1580
     * Adds a value to a movement statistic field - like run, walk, swin or
1581
     * climb.
1582
     */
1583
    public void addMovementStat(double p_71000_1_, double p_71000_3_, double p_71000_5_) {
1584
        if (this.ridingEntity == null) {
1585
            int var7;
1586
1587
            if (this.isInsideOfMaterial(Material.water)) {
1588
                var7 = Math.round(MathHelper.sqrt_double(p_71000_1_ * p_71000_1_ + p_71000_3_ * p_71000_3_ + p_71000_5_ * p_71000_5_) * 100.0F);
1589
1590
                if (var7 > 0) {
1591
                    this.addStat(StatList.distanceDoveStat, var7);
1592
                    this.addExhaustion(0.015F * (float) var7 * 0.01F);
1593
                }
1594
            } else if (this.isInWater()) {
1595
                var7 = Math.round(MathHelper.sqrt_double(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F);
1596
1597
                if (var7 > 0) {
1598
                    this.addStat(StatList.distanceSwumStat, var7);
1599
                    this.addExhaustion(0.015F * (float) var7 * 0.01F);
1600
                }
1601
            } else if (this.isOnLadder()) {
1602
                if (p_71000_3_ > 0.0D) {
1603
                    this.addStat(StatList.distanceClimbedStat, (int) Math.round(p_71000_3_ * 100.0D));
1604
                }
1605
            } else if (this.onGround) {
1606
                var7 = Math.round(MathHelper.sqrt_double(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F);
1607
1608
                if (var7 > 0) {
1609
                    this.addStat(StatList.distanceWalkedStat, var7);
1610
1611
                    if (this.isSprinting()) {
1612
                        this.addStat(StatList.distanceSprintedStat, var7);
1613
                        this.addExhaustion(0.099999994F * (float) var7 * 0.01F);
1614
                    } else {
1615
                        if (this.isSneaking()) {
1616
                            this.addStat(StatList.distanceCrouchedStat, var7);
1617
                        }
1618
1619
                        this.addExhaustion(0.01F * (float) var7 * 0.01F);
1620
                    }
1621
                }
1622
            } else {
1623
                var7 = Math.round(MathHelper.sqrt_double(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F);
1624
1625
                if (var7 > 25) {
1626
                    this.addStat(StatList.distanceFlownStat, var7);
1627
                }
1628
            }
1629
        }
1630
    }
1631
1632
    /**
1633
     * Adds a value to a mounted movement statistic field - by minecart, boat,
1634
     * or pig.
1635
     */
1636
    private void addMountedMovementStat(double p_71015_1_, double p_71015_3_, double p_71015_5_) {
1637
        if (this.ridingEntity != null) {
1638
            int var7 = Math.round(MathHelper.sqrt_double(p_71015_1_ * p_71015_1_ + p_71015_3_ * p_71015_3_ + p_71015_5_ * p_71015_5_) * 100.0F);
1639
1640
            if (var7 > 0) {
1641
                if (this.ridingEntity instanceof EntityMinecart) {
1642
                    this.addStat(StatList.distanceByMinecartStat, var7);
1643
1644
                    if (this.startMinecartRidingCoordinate == null) {
1645
                        this.startMinecartRidingCoordinate = new BlockPos(this);
1646
                    } else if (this.startMinecartRidingCoordinate.distanceSq((double) MathHelper.floor_double(this.posX), (double) MathHelper.floor_double(this.posY), (double) MathHelper.floor_double(this.posZ)) >= 1000000.0D) {
1647
                        this.triggerAchievement(AchievementList.onARail);
1648
                    }
1649
                } else if (this.ridingEntity instanceof EntityBoat) {
1650
                    this.addStat(StatList.distanceByBoatStat, var7);
1651
                } else if (this.ridingEntity instanceof EntityPig) {
1652
                    this.addStat(StatList.distanceByPigStat, var7);
1653
                } else if (this.ridingEntity instanceof EntityHorse) {
1654
                    this.addStat(StatList.distanceByHorseStat, var7);
1655
                }
1656
            }
1657
        }
1658
    }
1659
1660
    public void fall(float distance, float damageMultiplier) {
1661
        if (!this.capabilities.allowFlying) {
1662
            if (distance >= 2.0F) {
1663
                this.addStat(StatList.distanceFallenStat, (int) Math.round((double) distance * 100.0D));
1664
            }
1665
1666
            super.fall(distance, damageMultiplier);
1667
        }
1668
    }
1669
1670
    /**
1671
     * sets the players height back to normal after doing things like sleeping
1672
     * and dieing
1673
     */
1674
    public void resetHeight() {
1675
        if (!this.func_175149_v()) {
1676
            super.resetHeight();
1677
        }
1678
    }
1679
1680
    protected String func_146067_o(int p_146067_1_) {
1681
        return p_146067_1_ > 4 ? "game.player.hurt.fall.big" : "game.player.hurt.fall.small";
1682
    }
1683
1684
    /**
1685
     * This method gets called when the entity kills another one.
1686
     */
1687
    public void onKillEntity(EntityLivingBase entityLivingIn) {
1688
        if (entityLivingIn instanceof IMob) {
1689
            this.triggerAchievement(AchievementList.killEnemy);
1690
        }
1691
1692
        EntityList.EntityEggInfo var2 = (EntityList.EntityEggInfo) EntityList.entityEggs.get(Integer.valueOf(EntityList.getEntityID(entityLivingIn)));
1693
1694
        if (var2 != null) {
1695
            this.triggerAchievement(var2.field_151512_d);
1696
        }
1697
    }
1698
1699
    /**
1700
     * Sets the Entity inside a web block.
1701
     */
1702
    public void setInWeb() {
1703
        if (!this.capabilities.isFlying) {
1704
            super.setInWeb();
1705
        }
1706
    }
1707
1708
    public ItemStack getCurrentArmor(int p_82169_1_) {
1709
        return this.inventory.armorItemInSlot(p_82169_1_);
1710
    }
1711
1712
    /**
1713
     * Add experience points to player.
1714
     */
1715
    public void addExperience(int p_71023_1_) {
1716
        this.addScore(p_71023_1_);
1717
        int var2 = Integer.MAX_VALUE - this.experienceTotal;
1718
1719
        if (p_71023_1_ > var2) {
1720
            p_71023_1_ = var2;
1721
        }
1722
1723
        this.experience += (float) p_71023_1_ / (float) this.xpBarCap();
1724
1725
        for (this.experienceTotal += p_71023_1_; this.experience >= 1.0F; this.experience /= (float) this.xpBarCap()) {
1726
            this.experience = (this.experience - 1.0F) * (float) this.xpBarCap();
1727
            this.addExperienceLevel(1);
1728
        }
1729
    }
1730
1731
    public int func_175138_ci() {
1732
        return this.field_175152_f;
1733
    }
1734
1735
    public void func_71013_b(int p_71013_1_) {
1736
        this.experienceLevel -= p_71013_1_;
1737
1738
        if (this.experienceLevel < 0) {
1739
            this.experienceLevel = 0;
1740
            this.experience = 0.0F;
1741
            this.experienceTotal = 0;
1742
        }
1743
1744
        this.field_175152_f = this.rand.nextInt();
1745
    }
1746
1747
    /**
1748
     * Add experience levels to this player.
1749
     */
1750
    public void addExperienceLevel(int p_82242_1_) {
1751
        this.experienceLevel += p_82242_1_;
1752
1753
        if (this.experienceLevel < 0) {
1754
            this.experienceLevel = 0;
1755
            this.experience = 0.0F;
1756
            this.experienceTotal = 0;
1757
        }
1758
1759
        if (p_82242_1_ > 0 && this.experienceLevel % 5 == 0 && (float) this.field_82249_h < (float) this.ticksExisted - 100.0F) {
1760
            float var2 = this.experienceLevel > 30 ? 1.0F : (float) this.experienceLevel / 30.0F;
1761
            this.worldObj.playSoundAtEntity(this, "random.levelup", var2 * 0.75F, 1.0F);
1762
            this.field_82249_h = this.ticksExisted;
1763
        }
1764
    }
1765
1766
    /**
1767
     * This method returns the cap amount of experience that the experience bar
1768
     * can hold. With each level, the experience cap on the player's experience
1769
     * bar is raised by 10.
1770
     */
1771
    public int xpBarCap() {
1772
        return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
1773
    }
1774
1775
    /**
1776
     * increases exhaustion level by supplied amount
1777
     */
1778
    public void addExhaustion(float p_71020_1_) {
1779
        if (!this.capabilities.disableDamage) {
1780
            if (!this.worldObj.isRemote) {
1781
                this.foodStats.addExhaustion(p_71020_1_);
1782
            }
1783
        }
1784
    }
1785
1786
    /**
1787
     * Returns the player's FoodStats object.
1788
     */
1789
    public FoodStats getFoodStats() {
1790
        return this.foodStats;
1791
    }
1792
1793
    public boolean canEat(boolean p_71043_1_) {
1794
        return (p_71043_1_ || this.foodStats.needFood()) && !this.capabilities.disableDamage;
1795
    }
1796
1797
    /**
1798
     * Checks if the player's health is not full and not zero.
1799
     */
1800
    public boolean shouldHeal() {
1801
        return this.getHealth() > 0.0F && this.getHealth() < this.getMaxHealth();
1802
    }
1803
1804
    /**
1805
     * sets the itemInUse when the use item button is clicked. Args: itemstack,
1806
     * int maxItemUseDuration
1807
     */
1808
    public void setItemInUse(ItemStack p_71008_1_, int p_71008_2_) {
1809
        if (p_71008_1_ != this.itemInUse) {
1810
            this.itemInUse = p_71008_1_;
1811
            this.itemInUseCount = p_71008_2_;
1812
1813
            if (!this.worldObj.isRemote) {
1814
                this.setEating(true);
1815
            }
1816
        }
1817
    }
1818
1819
    public boolean func_175142_cm() {
1820
        return this.capabilities.allowEdit;
1821
    }
1822
1823
    public boolean func_175151_a(BlockPos p_175151_1_, EnumFacing p_175151_2_, ItemStack p_175151_3_) {
1824
        if (this.capabilities.allowEdit) {
1825
            return true;
1826
        } else if (p_175151_3_ == null) {
1827
            return false;
1828
        } else {
1829
            BlockPos var4 = p_175151_1_.offset(p_175151_2_.getOpposite());
1830
            Block var5 = this.worldObj.getBlockState(var4).getBlock();
1831
            return p_175151_3_.canPlaceOn(var5) || p_175151_3_.canEditBlocks();
1832
        }
1833
    }
1834
1835
    /**
1836
     * Get the experience points the entity currently has.
1837
     */
1838
    protected int getExperiencePoints(EntityPlayer p_70693_1_) {
1839
        if (this.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) {
1840
            return 0;
1841
        } else {
1842
            int var2 = this.experienceLevel * 7;
1843
            return var2 > 100 ? 100 : var2;
1844
        }
1845
    }
1846
1847
    /**
1848
     * Only use is to identify if class is an instance of player for experience
1849
     * dropping
1850
     */
1851
    protected boolean isPlayer() {
1852
        return true;
1853
    }
1854
1855
    public boolean getAlwaysRenderNameTagForRender() {
1856
        return true;
1857
    }
1858
1859
    /**
1860
     * Copies the values from the given player into this player if boolean par2
1861
     * is true. Always clones Ender Chest Inventory.
1862
     */
1863
    public void clonePlayer(EntityPlayer p_71049_1_, boolean p_71049_2_) {
1864
        if (p_71049_2_) {
1865
            this.inventory.copyInventory(p_71049_1_.inventory);
1866
            this.setHealth(p_71049_1_.getHealth());
1867
            this.foodStats = p_71049_1_.foodStats;
1868
            this.experienceLevel = p_71049_1_.experienceLevel;
1869
            this.experienceTotal = p_71049_1_.experienceTotal;
1870
            this.experience = p_71049_1_.experience;
1871
            this.setScore(p_71049_1_.getScore());
1872
            this.teleportDirection = p_71049_1_.teleportDirection;
1873
        } else if (this.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) {
1874
            this.inventory.copyInventory(p_71049_1_.inventory);
1875
            this.experienceLevel = p_71049_1_.experienceLevel;
1876
            this.experienceTotal = p_71049_1_.experienceTotal;
1877
            this.experience = p_71049_1_.experience;
1878
            this.setScore(p_71049_1_.getScore());
1879
        }
1880
1881
        this.theInventoryEnderChest = p_71049_1_.theInventoryEnderChest;
1882
        this.getDataWatcher().updateObject(10, Byte.valueOf(p_71049_1_.getDataWatcher().getWatchableObjectByte(10)));
1883
    }
1884
1885
    /**
1886
     * returns if this entity triggers Block.onEntityWalking on the blocks they
1887
     * walk on. used for spiders and wolves to prevent them from trampling crops
1888
     */
1889
    protected boolean canTriggerWalking() {
1890
        return !this.capabilities.isFlying;
1891
    }
1892
1893
    /**
1894
     * Sends the player's abilities to the server (if there is one).
1895
     */
1896
    public void sendPlayerAbilities() {
1897
    }
1898
1899
    /**
1900
     * Sets the player's game mode and sends it to them.
1901
     */
1902
    public void setGameType(WorldSettings.GameType gameType) {
1903
    }
1904
1905
    /**
1906
     * Gets the name of this command sender (usually username, but possibly
1907
     * "Rcon")
1908
     */
1909
    public String getName() {
1910
        return this.gameProfile.getName();
1911
    }
1912
1913
    /**
1914
     * Returns the InventoryEnderChest of this player.
1915
     */
1916
    public InventoryEnderChest getInventoryEnderChest() {
1917
        return this.theInventoryEnderChest;
1918
    }
1919
1920
    /**
1921
     * 0: Tool in Hand; 1-4: Armor
1922
     */
1923
    public ItemStack getEquipmentInSlot(int p_71124_1_) {
1924
        return p_71124_1_ == 0 ? this.inventory.getCurrentItem() : this.inventory.armorInventory[p_71124_1_ - 1];
1925
    }
1926
1927
    /**
1928
     * Returns the item that this EntityLiving is holding, if any.
1929
     */
1930
    public ItemStack getHeldItem() {
1931
        return this.inventory.getCurrentItem();
1932
    }
1933
1934
    /**
1935
     * Sets the held item, or an armor slot. Slot 0 is held item. Slot 1-4 is
1936
     * armor. Params: Item, slot
1937
     */
1938
    public void setCurrentItemOrArmor(int slotIn, ItemStack itemStackIn) {
1939
        this.inventory.armorInventory[slotIn] = itemStackIn;
1940
    }
1941
1942
    /**
1943
     * Only used by renderer in EntityLivingBase subclasses. Determines if an
1944
     * entity is visible or not to a specfic player, if the entity is normally
1945
     * invisible. For EntityLivingBase subclasses, returning false when
1946
     * invisible will render the entity semitransparent.
1947
     */
1948
    public boolean isInvisibleToPlayer(EntityPlayer playerIn) {
1949
        if (!this.isInvisible()) {
1950
            return false;
1951
        } else if (playerIn.func_175149_v()) {
1952
            return false;
1953
        } else {
1954
            Team var2 = this.getTeam();
1955
            return var2 == null || playerIn == null || playerIn.getTeam() != var2 || !var2.func_98297_h();
1956
        }
1957
    }
1958
1959
    public abstract boolean func_175149_v();
1960
1961
    /**
1962
     * returns the inventory of this entity (only used in EntityPlayerMP it
1963
     * seems)
1964
     */
1965
    public ItemStack[] getInventory() {
1966
        return this.inventory.armorInventory;
1967
    }
1968
1969
    public boolean isPushedByWater() {
1970
        return !this.capabilities.isFlying;
1971
    }
1972
1973
    public Scoreboard getWorldScoreboard() {
1974
        return this.worldObj.getScoreboard();
1975
    }
1976
1977
    public Team getTeam() {
1978
        return this.getWorldScoreboard().getPlayersTeam(this.getName());
1979
    }
1980
1981
    public IChatComponent getDisplayName() {
1982
        ChatComponentText var1 = new ChatComponentText(ScorePlayerTeam.formatPlayerName(this.getTeam(), this.getName()));
1983
        var1.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + this.getName() + " "));
1984
        var1.getChatStyle().setChatHoverEvent(this.func_174823_aP());
1985
        var1.getChatStyle().setInsertion(this.getName());
1986
        return var1;
1987
    }
1988
1989
    public float getEyeHeight() {
1990
        float var1 = 1.62F;
1991
1992
        if (this.isPlayerSleeping()) {
1993
            var1 = 0.2F;
1994
        }
1995
1996
        if (this.isSneaking()) {
1997
            var1 -= 0.08F;
1998
        }
1999
2000
        return var1;
2001
    }
2002
2003
    public void setAbsorptionAmount(float p_110149_1_) {
2004
        if (p_110149_1_ < 0.0F) {
2005
            p_110149_1_ = 0.0F;
2006
        }
2007
2008
        this.getDataWatcher().updateObject(17, Float.valueOf(p_110149_1_));
2009
    }
2010
2011
    public float getAbsorptionAmount() {
2012
        return this.getDataWatcher().getWatchableObjectFloat(17);
2013
    }
2014
2015
    /**
2016
     * Gets a players UUID given their GameProfie
2017
     */
2018
    public static UUID getUUID(GameProfile p_146094_0_) {
2019
        UUID var1 = p_146094_0_.getId();
2020
2021
        if (var1 == null) {
2022
            var1 = func_175147_b(p_146094_0_.getName());
2023
        }
2024
2025
        return var1;
2026
    }
2027
2028
    public static UUID func_175147_b(String p_175147_0_) {
2029
        return UUID.nameUUIDFromBytes(("OfflinePlayer:" + p_175147_0_).getBytes(Charsets.UTF_8));
2030
    }
2031
2032
    public boolean func_175146_a(LockCode p_175146_1_) {
2033
        if (p_175146_1_.isEmpty()) {
2034
            return true;
2035
        } else {
2036
            ItemStack var2 = this.getCurrentEquippedItem();
2037
            return var2 != null && var2.hasDisplayName() ? var2.getDisplayName().equals(p_175146_1_.getLock()) : false;
2038
        }
2039
    }
2040
2041
    public boolean func_175148_a(EnumPlayerModelParts p_175148_1_) {
2042
        return (this.getDataWatcher().getWatchableObjectByte(10) & p_175148_1_.func_179327_a()) == p_175148_1_.func_179327_a();
2043
    }
2044
2045
    public boolean sendCommandFeedback() {
2046
        return MinecraftServer.getServer().worldServers[0].getGameRules().getGameRuleBooleanValue("sendCommandFeedback");
2047
    }
2048
2049
    public boolean func_174820_d(int p_174820_1_, ItemStack p_174820_2_) {
2050
        if (p_174820_1_ >= 0 && p_174820_1_ < this.inventory.mainInventory.length) {
2051
            this.inventory.setInventorySlotContents(p_174820_1_, p_174820_2_);
2052
            return true;
2053
        } else {
2054
            int var3 = p_174820_1_ - 100;
2055
            int var4;
2056
2057
            if (var3 >= 0 && var3 < this.inventory.armorInventory.length) {
2058
                var4 = var3 + 1;
2059
2060
                if (p_174820_2_ != null && p_174820_2_.getItem() != null) {
2061
                    if (p_174820_2_.getItem() instanceof ItemArmor) {
2062
                        if (EntityLiving.getArmorPosition(p_174820_2_) != var4) {
2063
                            return false;
2064
                        }
2065
                    } else if (var4 != 4 || p_174820_2_.getItem() != Items.skull && !(p_174820_2_.getItem() instanceof ItemBlock)) {
2066
                        return false;
2067
                    }
2068
                }
2069
2070
                this.inventory.setInventorySlotContents(var3 + this.inventory.mainInventory.length, p_174820_2_);
2071
                return true;
2072
            } else {
2073
                var4 = p_174820_1_ - 200;
2074
2075
                if (var4 >= 0 && var4 < this.theInventoryEnderChest.getSizeInventory()) {
2076
                    this.theInventoryEnderChest.setInventorySlotContents(var4, p_174820_2_);
2077
                    return true;
2078
                } else {
2079
                    return false;
2080
                }
2081
            }
2082
        }
2083
    }
2084
2085
    public boolean func_175140_cp() {
2086
        return this.field_175153_bG;
2087
    }
2088
2089
    public void func_175150_k(boolean p_175150_1_) {
2090
        this.field_175153_bG = p_175150_1_;
2091
    }
2092
2093
    public static enum EnumChatVisibility {
2094
        FULL("FULL", 0, 0, "options.chat.visibility.full"), SYSTEM("SYSTEM", 1, 1, "options.chat.visibility.system"), HIDDEN("HIDDEN", 2, 2, "options.chat.visibility.hidden");
2095
        private static final EntityPlayer.EnumChatVisibility[] field_151432_d = new EntityPlayer.EnumChatVisibility[values().length];
2096
        private final int chatVisibility;
2097
        private final String resourceKey;
2098
2099
        private static final EntityPlayer.EnumChatVisibility[] $VALUES = new EntityPlayer.EnumChatVisibility[]{FULL, SYSTEM, HIDDEN};
2100
        private static final String __OBFID = "CL_00001714";
2101
2102
        private EnumChatVisibility(String p_i45323_1_, int p_i45323_2_, int p_i45323_3_, String p_i45323_4_) {
2103
            this.chatVisibility = p_i45323_3_;
2104
            this.resourceKey = p_i45323_4_;
2105
        }
2106
2107
        public int getChatVisibility() {
2108
            return this.chatVisibility;
2109
        }
2110
2111
        public static EntityPlayer.EnumChatVisibility getEnumChatVisibility(int p_151426_0_) {
2112
            return field_151432_d[p_151426_0_ % field_151432_d.length];
2113
        }
2114
2115
        public String getResourceKey() {
2116
            return this.resourceKey;
2117
        }
2118
2119
        static {
2120
            EntityPlayer.EnumChatVisibility[] var0 = values();
2121
            int var1 = var0.length;
2122
2123
            for (int var2 = 0; var2 < var1; ++var2) {
2124
                EntityPlayer.EnumChatVisibility var3 = var0[var2];
2125
                field_151432_d[var3.chatVisibility] = var3;
2126
            }
2127
        }
2128
    }
2129
2130
    public static enum EnumStatus {
2131
        OK("OK", 0), NOT_POSSIBLE_HERE("NOT_POSSIBLE_HERE", 1), NOT_POSSIBLE_NOW("NOT_POSSIBLE_NOW", 2), TOO_FAR_AWAY("TOO_FAR_AWAY", 3), OTHER_PROBLEM("OTHER_PROBLEM", 4), NOT_SAFE("NOT_SAFE", 5);
2132
2133
        private static final EntityPlayer.EnumStatus[] $VALUES = new EntityPlayer.EnumStatus[]{OK, NOT_POSSIBLE_HERE, NOT_POSSIBLE_NOW, TOO_FAR_AWAY, OTHER_PROBLEM, NOT_SAFE};
2134
        private static final String __OBFID = "CL_00001712";
2135
2136
        private EnumStatus(String p_i1751_1_, int p_i1751_2_) {
2137
        }
2138
    }
2139
2140
    static final class SwitchEnumFacing {
2141
        static final int[] field_179420_a = new int[EnumFacing.values().length];
2142
        private static final String __OBFID = "CL_00002188";
2143
2144
        static {
2145
            try {
2146
                field_179420_a[EnumFacing.SOUTH.ordinal()] = 1;
2147
            } catch (NoSuchFieldError var4) {
2148
                ;
2149
            }
2150
2151
            try {
2152
                field_179420_a[EnumFacing.NORTH.ordinal()] = 2;
2153
            } catch (NoSuchFieldError var3) {
2154
                ;
2155
            }
2156
2157
            try {
2158
                field_179420_a[EnumFacing.WEST.ordinal()] = 3;
2159
            } catch (NoSuchFieldError var2) {
2160
                ;
2161
            }
2162
2163
            try {
2164
                field_179420_a[EnumFacing.EAST.ordinal()] = 4;
2165
            } catch (NoSuchFieldError var1) {
2166
                ;
2167
            }
2168
        }
2169
    }
2170
}

What this file does

This file proves the fork needs no KeepSprint at all. Inside attackTargetEntityWithCurrentItem, in the block that runs after hasDamaged, vanilla applies the hit penalties: it dampens the attacker's own motion and stops the sprint. The fork ships those three statements commented out: //this.motionX *= 0.6D; //this.motionZ *= 0.6D; and //this.setSprinting(false);. With setSprinting never called on a successful hit, the isSprinting() state the fork's motionUpdates() diffs stays true, so no STOP_SPRINTING C0B is ever emitted from the attack path and the entity-action stream carries only the ordinary START/STOP toggles of manual sprinting. The file also documents the vanilla baseline the module was written against: the commented-out call is exactly the transition a working KeepSprint would have to intercept.

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 ToggleFrequency (entity-action rate)

ToggleFrequency.java61 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;
16
17
import org.bukkit.entity.Player;
18
19
import fr.neatmonster.nocheatplus.checks.Check;
20
import fr.neatmonster.nocheatplus.checks.CheckType;
21
import fr.neatmonster.nocheatplus.players.IPlayerData;
22
import fr.neatmonster.nocheatplus.utilities.TickTask;
23
24
/**
25
 * The ToggleFrequency check is used to detect players who toggle certain actions too quickly (i.e.: sneaking).
26
 */
27
public class ToggleFrequency extends Check {
28
29
    /**
30
     * Instantiates a new toggle frequency check.
31
     */
32
    public ToggleFrequency() {
33
        super(CheckType.NET_TOGGLEFREQUENCY);
34
    }
35
36
    /**
37
     * Checks a player.
38
     * 
39
     * @param player
40
     *            the player
41
     * @param data
42
     * @param cc
43
     * @param pData
44
     * @return true, if successful
45
     */
46
    public boolean check(final Player player, final NetData data, final NetConfig cc, final IPlayerData pData) {
47
        boolean cancel = false;
48
        // (Addition to frequency is done in the listener for each toggle event)
49
        // Full time resolution
50
        final long actionFullTime = data.playerActionFreq.bucketDuration() * data.playerActionFreq.numberOfBuckets();
51
        /** Toggle action events counted */
52
        final float fullActionScore = data.playerActionFreq.score(1f) / TickTask.getLag(actionFullTime);
53
        final double violation = fullActionScore > cc.toggleActionLimit ? fullActionScore - cc.toggleActionLimit : 0.0;
54
        if (violation > 0.0) {
55
            data.toggleFrequencyVL += violation;
56
            cancel = executeActions(player, data.toggleFrequencyVL, violation, cc.toggleFrequencyActions).willCancel();
57
        }
58
        else data.toggleFrequencyVL *= 0.9;
59
        return cancel;
60
    }
61
}

How it counteracts this module

NCP handles the C0B stream through the ProtocolLib EntityActionAdapter, which adds one point to data.playerActionFreq per entity-action packet and runs ToggleFrequency.check on the window, scoring the full window against cc.toggleActionLimit, default 25 actions per second, with the configured actions cancelling at vl above 10. It does not distinguish action types, so sprint, sneak and bed-leave toggles share one bucket.

For KeepSprint the check is doubly moot. The check can only flag an excess of toggles, while the module's intended effect is the absence of one: suppressing a STOP_SPRINTING removes an action from the ledger, which can only push the player further from the limit. And because the shipped module never fires at all, the C0B stream stays the vanilla START/STOP toggles, one or two actions per toggle cycle, far under the 25-per-second ceiling. This entry is the honest baseline: the only NCP check on the module's target packet class cannot observe either the module or its intended behavior.

anticheat SprintDirection (sprint state vs move force)

SprintDirection.java128 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.check.movement.position;
20
21
import me.islandscout.hawk.HawkPlayer;
22
import me.islandscout.hawk.check.MovementCheck;
23
import me.islandscout.hawk.event.MoveEvent;
24
import me.islandscout.hawk.util.Direction;
25
import me.islandscout.hawk.util.MathPlus;
26
import me.islandscout.hawk.wrap.entity.WrappedEntity;
27
import org.bukkit.Material;
28
import org.bukkit.block.Block;
29
import org.bukkit.entity.Player;
30
import org.bukkit.util.Vector;
31
32
import java.util.*;
33
34
public class SprintDirection extends MovementCheck {
35
36
    //TODO If jump and dY is 0, that means they POSSIBLY could have jumped; not always. eg: SprintDirection falses with extreme negative jump boost or jumping into a 2-block-high space.
37
38
    private Map<UUID, Long> lastSprintTickMap;
39
    private Set<UUID> collisionHorizontalSet;
40
41
    public SprintDirection() {
42
        super("sprintdirection", true, 5, 5, 0.999, 5000, "%player% failed sprint direction, VL %vl%", null);
43
        lastSprintTickMap = new HashMap<>();
44
        collisionHorizontalSet = new HashSet<>();
45
    }
46
47
    @Override
48
    protected void check(MoveEvent e) {
49
        HawkPlayer pp = e.getHawkPlayer();
50
51
        boolean collisionHorizontal = collidingHorizontally(e);
52
        Vector moveHoriz = e.getTo().toVector().subtract(e.getFrom().toVector()).setY(0);
53
54
        if(!pp.isSprinting())
55
            lastSprintTickMap.put(pp.getUuid(), pp.getCurrentTick());
56
57
        Set<Material> collidedMats = WrappedEntity.getWrappedEntity(e.getPlayer()).getCollisionBox(e.getFrom().toVector()).getMaterials(pp.getWorld());
58
        if(pp.isSwimming() || e.isTeleportAccept() || e.hasAcceptedKnockback() ||
59
                (collisionHorizontal && !collisionHorizontalSet.contains(pp.getUuid())) ||
60
                pp.getCurrentTick() - lastSprintTickMap.getOrDefault(pp.getUuid(), pp.getCurrentTick()) < 2 ||
61
                moveHoriz.lengthSquared() < 0.04 || collidedMats.contains(Material.LADDER) ||
62
                collidedMats.contains(Material.VINE)) {
63
            return;
64
        }
65
66
        float yaw = e.getTo().getYaw();
67
        Vector prevVelocity = pp.getVelocity().clone();
68
69
        List<Block> activeBlocks = e.getActiveBlocks();
70
        for(Block b : activeBlocks) {
71
            if(b.getType() == Material.SOUL_SAND) {
72
                prevVelocity.multiply(0.4); //which would you prefer: iterative multiplication or using Math.pow()?
73
            }
74
            if(b.getType() == Material.WEB) {
75
                prevVelocity.multiply(0);
76
                break; //Any number times 0 is 0; no reason to continue looping.
77
            }
78
        }
79
80
        if(e.hasHitSlowdown()) {
81
            prevVelocity.multiply(0.6);
82
        }
83
        double dX = e.getTo().getX() - e.getFrom().getX();
84
        double dZ = e.getTo().getZ() - e.getFrom().getZ();
85
        float friction = e.getFriction();
86
        dX /= friction;
87
        dZ /= friction;
88
        if(e.isJump()) {
89
            float yawRadians = yaw * 0.017453292F;
90
            dX += (MathPlus.sin(yawRadians) * 0.2F);
91
            dZ -= (MathPlus.cos(yawRadians) * 0.2F);
92
        }
93
94
        //Div by 1.7948708571637845???? What the hell are these numbers?
95
96
        dX -= prevVelocity.getX();
97
        dZ -= prevVelocity.getZ();
98
99
        Vector moveForce = new Vector(dX, 0, dZ);
100
        Vector yawVec = MathPlus.getDirection(yaw, 0);
101
102
        if(MathPlus.angle(yawVec, moveForce) > Math.PI / 4 + 0.3) { //0.3 is arbitrary. Prevents falses due to silly stuff in game
103
            punishAndTryRubberband(pp, e);
104
        }
105
        else {
106
            reward(pp);
107
        }
108
109
        if(collisionHorizontal)
110
            collisionHorizontalSet.add(pp.getUuid());
111
        else
112
            collisionHorizontalSet.remove(pp.getUuid());
113
    }
114
115
    private boolean collidingHorizontally(MoveEvent e) {
116
        for(Direction dir : e.getBoxSidesTouchingBlocks()) {
117
            if(dir == Direction.EAST || dir == Direction.NORTH || dir == Direction.SOUTH || dir == Direction.WEST)
118
                return true;
119
        }
120
        return false;
121
    }
122
123
    @Override
124
    public void removeData(Player p) {
125
        lastSprintTickMap.remove(p.getUniqueId());
126
        collisionHorizontalSet.remove(p.getUniqueId());
127
    }
128
}

How it counteracts this module

Hawk's SprintDirection validates that a sprinting player's horizontal move force agrees with the facing. For each move while pp.isSprinting(), it reconstructs the force by removing friction, the prior velocity (damped for soul sand and webs), the hit-slowdown factor and the jump impulse, then measures the angle between that force and the yaw vector, punishing when the angle exceeds PI/4 + 0.3. Exemptions cover swimming, teleports, accepted knockback, horizontal collision, moves within two ticks of a sprint toggle, near-zero horizontal distance, and ladder/vine contact.

The check is the closest thing in Hawk to a sprint-state validator, and it is also one the module cannot reach. A player whose sprint is kept alive through hits still has to move in the yaw quadrant for SprintDirection to pass, which has nothing to do with the C0B stream; and since the shipped module never suppresses the STOP, the sprint state Hawk tracks is whatever the vanilla stream says. The entry documents the check that would constrain a working keep-sprint player on the movement axis, and why the module's dead branch means it never interacts with it.

anticheat ActionToggleSpeed (same-tick toggles)

ActionToggleSpeed.java80 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.check.movement;
20
21
import me.islandscout.hawk.HawkPlayer;
22
import me.islandscout.hawk.check.CustomCheck;
23
import me.islandscout.hawk.event.Event;
24
import me.islandscout.hawk.event.PlayerActionEvent;
25
import org.bukkit.entity.Player;
26
27
import java.util.HashMap;
28
import java.util.Map;
29
import java.util.UUID;
30
31
/**
32
 * This check limits clients' sprint and sneak toggle rates to
33
 * prevent exploitation of the speed check and combat mechanics.
34
 */
35
public class ActionToggleSpeed extends CustomCheck {
36
37
    private Map<UUID, Long> lastSneakToggle;
38
    private Map<UUID, Long> lastSprintToggle;
39
40
    public ActionToggleSpeed() {
41
        super("actiontogglespeed", "%player% failed action toggle speed, VL: %vl%");
42
        lastSneakToggle = new HashMap<>();
43
        lastSprintToggle = new HashMap<>();
44
    }
45
46
    @Override
47
    protected void check(Event e) {
48
        if(!(e instanceof PlayerActionEvent))
49
            return;
50
        PlayerActionEvent aE = (PlayerActionEvent)e;
51
        PlayerActionEvent.PlayerAction action = aE.getAction();
52
        HawkPlayer pp = e.getHawkPlayer();
53
        UUID uuid = e.getPlayer().getUniqueId();
54
        if(action == PlayerActionEvent.PlayerAction.SNEAK_START || action == PlayerActionEvent.PlayerAction.SNEAK_STOP) {
55
56
            if(pp.getCurrentTick() - lastSneakToggle.getOrDefault(uuid, 0L) < 1) {
57
                punish(pp, canCancel(), e);
58
            } else {
59
                reward(pp);
60
            }
61
62
            lastSneakToggle.put(uuid, pp.getCurrentTick());
63
        } else if(action == PlayerActionEvent.PlayerAction.SPRINT_START || action == PlayerActionEvent.PlayerAction.SPRINT_STOP) {
64
65
            if(pp.getCurrentTick() - lastSprintToggle.getOrDefault(uuid, 0L) < 1) {
66
                punish(pp, canCancel(), e);
67
            } else {
68
                reward(pp);
69
            }
70
71
            lastSprintToggle.put(uuid, pp.getCurrentTick());
72
        }
73
    }
74
75
    public void removeData(Player p) {
76
        UUID uuid = p.getUniqueId();
77
        lastSneakToggle.remove(uuid);
78
        lastSprintToggle.remove(uuid);
79
    }
80
}

How it counteracts this module

ActionToggleSpeed watches PlayerActionEvents for sneak and sprint toggles and punishes a toggle that lands on the same tick as the previous one of its kind: pp.getCurrentTick() - lastSprintToggle < 1 after a SPRINT_START or SPRINT_STOP, with the same rule for sneak. It exists to catch clients that rapidly re-assert sprint or sneak state, which generate action packets faster than a human or vanilla toggle cycle can.

KeepSprint interacts with this check only by subtraction. The intended behavior suppresses STOP_SPRINTING entirely, which leaves the ledger with the single START from enabling and removes the pairs that rapid re-assertion would produce; a working module would make ActionToggleSpeed even quieter, and the dead shipped branch changes nothing at all. The C0B traffic on the wire stays at vanilla toggle frequency, so the check never sees a same-tick pair. This entry closes the sprint-domain coverage for Hawk: none of its sprint checks can flag a module whose observable output is zero.

← Back to Analysis Hub