EntityPlayer

Shared player base: inventory, food, capabilities, sleep, XP, attack pipeline inherited by SP and MP.

net/minecraft/entity/player/EntityPlayer.java

Updated 2026-09-12

Packets Referenced (1)

Deep Analysis

Living player with inventory, ender chest, food, XP, sleep, and combat state. Extends EntityLivingBase with DataWatcher skin/score/absorption fields. Implements item use, attack pipeline with enchant/crit/knockback, bed logic, NBT persistence, and score/team helpers.

Key Methods (8)

onUpdate

Ticks item use, sleep, food, stats, and container validity.

Decrements itemInUseCount to onItemUseFinish, advances sleepTimer, updates FoodStats server-side, clamps world border, closes invalid openContainer.

attackTargetEntityWithCurrentItem

Melee pipeline for damage, knockback, fire, and durability.

Computes attackDamage plus enchant modifier, crit multiplier, knockback and fire aspect. Calls attackEntityFrom, sends S12 velocity sync for MP victims, applies thorns and stats.

attackEntityFrom/damageEntity

Applies difficulty scaling, blocking, armor, and potion reduction.

Respects creative disableDamage, wakes sleeper, scales by difficulty, halves blocked damage, applies armor/potion/absorption then health and exhaustion.

trySleep/wakeUpPlayer

Validates bed use and manages sleep state and spawn.

Checks dimension, daytime, distance, and nearby mobs; shrinks box and positions in bed. Wake restores size, clears occupied flag, optionally sets spawn. Maps to S0A bed.

onItemUseFinish/updateItemUse

Completes eating/drinking and spawns consumption particles.

Plays drink/eat sounds, spawns ITEM_CRACK particles, calls onItemUseFinish to replace held stack and clear itemInUse. Status 9 mirrors it client-side.

addExperience/xpBarCap

Accumulates XP and levels with cap curve.

Adds score, converts amount via xpBarCap thresholds 7/37/112 formulas, loops level-ups with levelup sound. Server pushes via S1F experience.

dropItem/joinEntityItemWithWorld

Spawns EntityItem with throw physics and pickup delay.

Offsets from eye height, sets motion from yaw/pitch plus randomness, sets thrower for stats. World.spawnEntityInWorld replicates via S0E.

readEntityFromNBT/writeEntityToNBT

Persists inventory, XP, spawn, food, and ender chest.

Stores Inventory list, SelectedItemSlot, Sleeping/SleepTimer, XpP/Level/Total/Seed, Score, SpawnXYZ, FoodStats, capabilities, EnderItems. Restores on login/respawn.

Packet Usage

PacketDirTrigger
S12sentMelee knockback on EntityPlayerMP victim; restores motion after velocity packet

Internal State

inventory/openContainerMain inventory plus active window driving slot packets
foodStatsHunger/exhaustion ticked server-side, synced via health packet
experience/Level/TotalXP bar state synced via S1F set experience
sleeping/playerLocationBed occupancy driving S0A use-bed broadcast
capabilitiesFly/speed/edit flags synced via abilities packet

Related Vanilla Internals

Full Source

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

Deobfuscated MCP 1.8.9 source of EntityPlayer from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/player/EntityPlayer.java), stored verbatim.