EntityLivingBase

Living-entity base: swingItem, potion-effect add/remove and item pickup emit S0B, S1D/S1E and S0D through the tracker.

net/minecraft/entity/EntityLivingBase.java

Updated 2026-09-12

Deep Analysis

Abstract base for all living entities in 1.8.9, owning health, attributes, combat, potions and equipment state. Server-side logic broadcasts visual effects through WorldServer EntityTracker while persistent state syncs via DataWatcher slots. Client mirrors hurt, death, swing, pickup and potion color through status, animation and metadata packets.

Key Methods in Depth (10)

swingItem

Start arm-swing animation and broadcast to trackers

swingItem starts a client-visible arm swing on the server and broadcasts it to all tracking clients. It first checks isSwingInProgress and swingProgressInt against half of getArmSwingAnimationEnd to avoid restarting a swing mid-stroke unless expired or invalid. On start it sets swingProgressInt to -1 and isSwingInProgress to true so updateArmSwingProgress will advance it next tick. It then guards with worldObj instanceof WorldServer to ensure this only runs on the logical server. It obtains the EntityTracker from WorldServer and calls sendToAllTrackingEntity with new S0BPacketAnimation(this, 0) where type 0 means swing arm. Receivers including the attacker itself if tracked and nearby players get S0B and play the swing animation without changing inventory or health. This keeps swings visual-only while combat damage is handled separately by attack logic. No DataWatcher change is made here because animation is transient.

    public void swingItem()
    {
        if (!this.isSwingInProgress || this.swingProgressInt >= this.getArmSwingAnimationEnd() / 2 || this.swingProgressInt < 0)
        {
            this.swingProgressInt = -1;
            this.isSwingInProgress = true;

            if (this.worldObj instanceof WorldServer)
            {
                ((WorldServer)this.worldObj).getEntityTracker().sendToAllTrackingEntity(this, new S0BPacketAnimation(this, 0));
            }
        }
    }

The guard condition prevents overlapping swings by allowing restart only when idle, past half duration, or with invalid counter. Resetting swingProgressInt to -1 and setting isSwingInProgress starts the animation timer consumed by updateArmSwingProgress. The instanceof WorldServer check confines packet sending to the logical server and avoids client double-send. sendToAllTrackingEntity forwards the new S0BPacketAnimation with entity ID and type 0 to every tracking client. Clients then render the arm swing while server logic continues independently.

onItemPickup

Broadcast pickup animation when collecting item, arrow or XP orb

onItemPickup broadcasts the pickup beam animation when a living entity collects an item, arrow, or XP orb. It first rejects dead pickup entities with isDead and rejects client worlds with worldObj.isRemote so only the server emits packets. It fetches EntityTracker from the WorldServer to find all clients tracking the picked-up entity. For EntityItem it sends S0DPacketCollectItem with args picked-up entity ID and collector entity ID so clients can fly the item to the collector. It repeats the same S0D send for EntityArrow and for EntityXPOrb using identical constructor arguments. Receivers hide or remove the ground entity and render it moving into the collector inventory or body. No inventory mutation happens here; actual stack transfer is done by caller logic before or after this visual. This separation keeps visuals in sync even if stack handling differs by subclass.

    public void onItemPickup(Entity p_71001_1_, int p_71001_2_)
    {
        if (!p_71001_1_.isDead && !this.worldObj.isRemote)
        {
            EntityTracker entitytracker = ((WorldServer)this.worldObj).getEntityTracker();

            if (p_71001_1_ instanceof EntityItem)
            {
                entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
            }

            if (p_71001_1_ instanceof EntityArrow)
            {
                entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
            }

            if (p_71001_1_ instanceof EntityXPOrb)
            {
                entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
            }
        }
    }

The method signature takes the picked-up entity and stack size though size is unused for the packet. The isDead plus isRemote guard ensures only live server-side pickups broadcast. Getting EntityTracker from WorldServer provides the audience of tracking clients. Each instanceof branch constructs S0DPacketCollectItem with collected ID first and collector ID second. Tracking clients receive S0D and animate the orb, arrow, or item flying to the collector.

onUpdate

Per-tick equipment diff sync and arrow-count decay

onUpdate runs every tick to decay stuck arrows and sync changed equipment to tracking clients. It calls super.onUpdate first for base entity movement and then gates server-only work with !worldObj.isRemote. It reads arrow count from DataWatcher slot 9 via getArrowCountInEntity and if above zero initializes arrowHitTimer to 20 times 30 minus count. It decrements arrowHitTimer each tick and calls setArrowCountInEntity with count minus one when it expires, which updates DataWatcher slot 9 for S1C metadata sync. It then loops slots 0 to 4 comparing previousEquipment cache to getEquipmentInSlot current value with ItemStack.areItemStacksEqual. On mismatch it sends S04PacketEntityEquipment with args entity ID, slot index j, and new ItemStack so clients update rendered held item and armor. It also removes old attribute modifiers and applies new ones to attributeMap to keep damage, armor, and speed correct. It caches a copy of the new stack in previousEquipment to avoid resending every tick. Every 20 ticks it resets CombatTracker to age out old damage entries.

        if (!this.worldObj.isRemote)
        {
            int i = this.getArrowCountInEntity();

            if (i > 0)
            {
                if (this.arrowHitTimer <= 0)
                {
                    this.arrowHitTimer = 20 * (30 - i);
                }

                --this.arrowHitTimer;

                if (this.arrowHitTimer <= 0)
                {
                    this.setArrowCountInEntity(i - 1);
                }
            }

            for (int j = 0; j < 5; ++j)
            {
                ItemStack itemstack = this.previousEquipment[j];
                ItemStack itemstack1 = this.getEquipmentInSlot(j);

                if (!ItemStack.areItemStacksEqual(itemstack1, itemstack))
                {
                    ((WorldServer)this.worldObj).getEntityTracker().sendToAllTrackingEntity(this, new S04PacketEntityEquipment(this.getEntityId(), j, itemstack1));

The !isRemote branch confines arrow decay and equipment broadcast to the server. Arrow logic reads DataWatcher slot 9 and uses arrowHitTimer as a countdown scaled by remaining arrows before decrementing the visible count. The for loop over five slots diffs cached previousEquipment against live getEquipmentInSlot. On inequality it calls sendToAllTrackingEntity with S04PacketEntityEquipment carrying entity ID, slot, and new stack. Receivers update the rendered equipment slot while the server also swaps attribute modifiers locally.

attackEntityFrom

Apply damage, knockback and hurt broadcast

attackEntityFrom is the server damage pipeline that validates, reduces, applies damage, and broadcasts hurt state. Earlier guards reject invulnerable sources, client worlds, dead entities, and fire damage with fire resistance. Armor, absorption, and potion reductions are applied inside damageEntity before health in DataWatcher slot 6 is lowered. Revenge target, recentlyHit timer, and attackingPlayer fields are set from source.getEntity for loot and AI. If flag remains true meaning full hurt rather than throttled repeat hit, it calls worldObj.setEntityState with byte 2. WorldServer forwards that state as S19PacketEntityStatus with entity ID and op code 2 to all tracking clients. Receivers invoke handleStatusUpdate byte 2 to play hurt sound, set hurtTime to 10, and flash red. Knockback via knockBack and hurt or death sounds follow, with onDeath called if health falls to zero. Throttled hits skip the S19 broadcast and knockback by clearing flag.

                if (flag)
                {
                    this.worldObj.setEntityState(this, (byte)2);

                    if (source != DamageSource.drown)
                    {
                        this.setBeenAttacked();
                    }

                    if (entity != null)
                    {
                        double d1 = entity.posX - this.posX;
                        double d0;

                        for (d0 = entity.posZ - this.posZ; d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D)
                        {
                            d1 = (Math.random() - Math.random()) * 0.01D;
                        }

                        this.attackedAtYaw = (float)(MathHelper.atan2(d0, d1) * 180.0D / Math.PI - (double)this.rotationYaw);
                        this.knockBack(entity, amount, d1, d0);
                    }
                    else
                    {
                        this.attackedAtYaw = (float)((int)(Math.random() * 2.0D) * 180);
                    }
                }

The if flag block runs only for full-strength hits that should be visible and knock back. setEntityState with byte 2 is the packet trigger that WorldServer turns into S19 to tracking clients. setBeenAttacked marks velocityChanged except for drown so motion syncs. The entity-null check computes knockback direction from attacker position with a small random fallback to avoid divide by zero. knockBack then applies motion while attackedAtYaw orients the hurt tilt on receivers.

onDeath

Handle death drops and death animation broadcast

onDeath awards score, drops loot on the server, and broadcasts the death animation. It resolves the killer via getAttackingEntity and source.getEntity, then calls addToPlayerScore if scoreValue is non-negative. It notifies the killer with onKillEntity for achievements and AI. It sets dead to true and resets CombatTracker to close the combat log. Guarded by !worldObj.isRemote it computes looting level from the killer, checks canDropLoot and doMobLoot gamerule, then calls dropFewItems, dropEquipment, and rarely addRandomDrop. These spawn EntityItem and EntityXPOrb which have their own spawn packets. Finally it calls worldObj.setEntityState with byte 3 which WorldServer forwards as S19PacketEntityStatus op 3. Tracking clients receive S19 and play death sound, rotate the corpse, and start the death timer.

        this.dead = true;
        this.getCombatTracker().reset();

        if (!this.worldObj.isRemote)
        {
            int i = 0;

            if (entity instanceof EntityPlayer)
            {
                i = EnchantmentHelper.getLootingModifier((EntityLivingBase)entity);
            }

            if (this.canDropLoot() && this.worldObj.getGameRules().getBoolean("doMobLoot"))
            {
                this.dropFewItems(this.recentlyHit > 0, i);
                this.dropEquipment(this.recentlyHit > 0, i);

                if (this.recentlyHit > 0 && this.rand.nextFloat() < 0.025F + (float)i * 0.01F)
                {
                    this.addRandomDrop();
                }
            }
        }

        this.worldObj.setEntityState(this, (byte)3);

Setting dead and resetting CombatTracker marks the entity as finished on both sides. The !isRemote guard confines looting calculation and dropFewItems plus dropEquipment spawning to the server. Looting level comes from the killer player while doMobLoot and canDropLoot gate drops. The final setEntityState with byte 3 always runs so WorldServer can broadcast S19 death. Clients then run handleStatusUpdate byte 3 to set health zero and invoke onDeath locally.

handleStatusUpdate

Client-side handler for hurt and death status bytes

handleStatusUpdate runs on the client to mirror hurt and death states received as S19PacketEntityStatus. For id 2 it sets limbSwingAmount to 1.5, copies maxHurtResistantTime into hurtResistantTime, and sets hurtTime and maxHurtTime to 10 for the red flash duration. It zeroes attackedAtYaw, plays getHurtSound with randomized pitch, and calls attackEntityFrom with generic zero damage to trigger hurt hooks without changing health. For id 3 it plays getDeathSound with randomized pitch, forces DataWatcher health to zero via setHealth, and calls onDeath with generic source to start client death animation. Both branches rely on the server having sent S19 op 2 from attackEntityFrom or op 3 from onDeath via setEntityState. Unknown IDs delegate to super.handleStatusUpdate for base entity handling like spawn particles. This keeps client visuals driven entirely by server broadcasts rather than local simulation.

    public void handleStatusUpdate(byte id)
    {
        if (id == 2)
        {
            this.limbSwingAmount = 1.5F;
            this.hurtResistantTime = this.maxHurtResistantTime;
            this.hurtTime = this.maxHurtTime = 10;
            this.attackedAtYaw = 0.0F;
            String s = this.getHurtSound();

            if (s != null)
            {
                this.playSound(this.getHurtSound(), this.getSoundVolume(), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
            }

            this.attackEntityFrom(DamageSource.generic, 0.0F);
        }
        else if (id == 3)
        {
            String s1 = this.getDeathSound();

            if (s1 != null)
            {
                this.playSound(this.getDeathSound(), this.getSoundVolume(), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
            }

            this.setHealth(0.0F);
            this.onDeath(DamageSource.generic);

The id 2 branch reconstructs hurt visuals by setting swing, resistance, and hurt timers plus sound. Calling attackEntityFrom with zero generic damage fires client hooks while early isRemote return prevents health change. The id 3 branch plays death sound, zeroes DataWatcher health, and invokes onDeath for corpse animation. Both branches are entered only when S19PacketEntityStatus with matching op arrives. Other IDs fall through to Entity super handler.

addPotionEffect

Add or combine active potion effect

addPotionEffect adds or combines a potion effect and schedules a metadata sync. It first calls isPotionApplicable which rejects regeneration and poison on undead creatures but allows all else. If activePotionsMap already contains the potion ID it calls combine on the existing PotionEffect to merge duration and amplifier, then calls onChangedPotionEffect with reapply true to refresh attribute modifiers. If new it inserts the effect into activePotionsMap and calls onNewPotionEffect to apply attribute modifiers to attributeMap. Both paths set potionsNeedUpdate to true so updatePotionEffects will recompute DataWatcher slots 7 potion color and 8 ambient flag. Those DataWatcher changes are sent by EntityTracker as S1C reflect S1CPacketEntityMetadata to tracking clients. Clients then render particles, tint, and invisibility without receiving a dedicated potion packet. Duration refresh packets at 600-tick intervals also flow through this dirty path.

    public void addPotionEffect(PotionEffect potioneffectIn)
    {
        if (this.isPotionApplicable(potioneffectIn))
        {
            if (this.activePotionsMap.containsKey(Integer.valueOf(potioneffectIn.getPotionID())))
            {
                ((PotionEffect)this.activePotionsMap.get(Integer.valueOf(potioneffectIn.getPotionID()))).combine(potioneffectIn);
                this.onChangedPotionEffect((PotionEffect)this.activePotionsMap.get(Integer.valueOf(potioneffectIn.getPotionID())), true);
            }
            else
            {
                this.activePotionsMap.put(Integer.valueOf(potioneffectIn.getPotionID()), potioneffectIn);
                this.onNewPotionEffect(potioneffectIn);
            }
        }
    }

The isPotionApplicable guard filters invalid undead heals and poisons before mutation. The containsKey branch merges into the existing effect and calls onChangedPotionEffect to reapply speed, damage, or health modifiers. The else branch inserts the new mapping and calls onNewPotionEffect to apply modifiers once. Both set potionsNeedUpdate so the next tick pushes DataWatcher slots 7 and 8 via S1C metadata.

removePotionEffect

Remove potion effect and refresh metadata

removePotionEffect removes a server-side potion and triggers attribute cleanup and resync. It removes the entry from activePotionsMap by integer potion ID and captures the old PotionEffect. If non-null it calls onFinishedPotionEffect which sets potionsNeedUpdate true and on the server removes attribute modifiers from attributeMap via Potion.potionTypes. The dirty flag causes updatePotionEffects to call updatePotionMetadata next tick, recomputing liquid color and ambient flag or clearing slots 7 and 8 if empty. EntityTracker then sends the changed DataWatcher entries as S1C S1CPacketEntityMetadata to all tracking clients. Receivers stop rendering that effect tint and particles and update invisibility. This differs from removePotionEffectClient which only edits the client map without attribute work. If the ID was absent no packet or modifier change occurs.

    public void removePotionEffect(int potionId)
    {
        PotionEffect potioneffect = (PotionEffect)this.activePotionsMap.remove(Integer.valueOf(potionId));

        if (potioneffect != null)
        {
            this.onFinishedPotionEffect(potioneffect);
        }
    }

The map remove by boxed potion ID both unregisters the effect and returns it for cleanup. The null check avoids dirtying metadata when nothing was active. onFinishedPotionEffect sets potionsNeedUpdate and strips server attribute modifiers. The next server tick then emits S1C metadata with updated color, ambient, and invisibility flags.

updatePotionMetadata

Recompute potion color and invisibility flags

updatePotionMetadata recomputes potion-driven DataWatcher state for S1C sync. If activePotionsMap is empty it calls resetPotionEffectMetadata which writes 0 to slot 7 color and 0 to slot 8 ambient, then calls setInvisible false to clear invisibility. If non-empty it calls PotionHelper.calcPotionLiquidColor over all active effects to blend the particle tint integer. It writes slot 8 with 1 if PotionHelper.getAreAmbient returns true else 0 to control ambient versus strong particles. It writes slot 7 with the blended color integer for client spell particles. It calls setInvisible based on isPotionActive for invisibility ID so armor and body render correctly. EntityTracker detects these DataWatcher changes and sends S1C S1CPacketEntityMetadata to tracking clients. Clients read slots 7, 8, and invisibility flag to render potion visuals.

    protected void updatePotionMetadata()
    {
        if (this.activePotionsMap.isEmpty())
        {
            this.resetPotionEffectMetadata();
            this.setInvisible(false);
        }
        else
        {
            int i = PotionHelper.calcPotionLiquidColor(this.activePotionsMap.values());
            this.dataWatcher.updateObject(8, Byte.valueOf((byte)(PotionHelper.getAreAmbient(this.activePotionsMap.values()) ? 1 : 0)));
            this.dataWatcher.updateObject(7, Integer.valueOf(i));
            this.setInvisible(this.isPotionActive(Potion.invisibility.id));
        }
    }

The isEmpty branch clears color and ambient slots and disables invisibility for the clean state. The else branch blends active effects into a single RGB integer and writes ambient flag to slot 8. Writing slot 7 publishes the tint while setInvisible mirrors the invisibility potion. Changed DataWatcher objects are then broadcast as S1C metadata to trackers.

markPotionsDirty

Flag potion metadata for next tick sync

markPotionsDirty flags potion metadata for refresh on the next tick. It sets the private boolean potionsNeedUpdate to true without touching activePotionsMap or DataWatcher immediately. The flag is consumed in updatePotionEffects which on the server calls updatePotionMetadata to rewrite slots 7 and 8 and invisibility. Those DataWatcher deltas are then sent by EntityTracker as S1C S1CPacketEntityMetadata to tracking clients. It is called by onNewPotionEffect, onChangedPotionEffect, and onFinishedPotionEffect after attribute modifiers change. This batches multiple adds or removes in one tick into a single metadata packet. If called on the client it only affects local particle spawning logic. No packet is sent synchronously inside this method itself.

    /**
     * Sends an END_COMBAT packet to the client
     */
    public void sendEndCombat()
    {
    }

    protected void markPotionsDirty()
    {
        this.potionsNeedUpdate = true;
    }

The empty sendEndCombat stub shows combat packets are unused in this version. markPotionsDirty simply sets potionsNeedUpdate to true to defer work. The next updatePotionEffects tick sees the flag and calls updatePotionMetadata on the server. Resulting DataWatcher slot 7 and 8 edits flow as S1C metadata to tracking clients.

Packet Usage

PacketDirTrigger
S0BsentswingItem on WorldServer via EntityTracker
S0DsentonItemPickup for EntityItem, EntityArrow, EntityXPOrb
S04sentonUpdate equipment change detection
S19sentattackEntityFrom byte 2 and onDeath byte 3 via setEntityState
S19handledhandleStatusUpdate bytes 2 hurt and 3 death
S1CsentDataWatcher slots 6 health, 7 potion color, 8 ambient, 9 arrows via tracker

Internal State

activePotionsMapMaps potion ID to PotionEffect for ticking and NBT
potionsNeedUpdateDirty flag driving DataWatcher potion metadata refresh
previousEquipment5-slot cache used to detect S04 equipment changes
attributeMapServersideAttributeMap backing health, speed and modifiers
_combatTrackerTracks recent damage sources for death messages
hurtTime/deathTimeClient-visible hurt and death animation timers

Related Vanilla Internals

Full Source

EntityLivingBase.java2306 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity;
2
3
import com.google.common.base.Predicate;
4
import com.google.common.base.Predicates;
5
import com.google.common.collect.Maps;
6
import java.util.Collection;
7
import java.util.Iterator;
8
import java.util.List;
9
import java.util.Map;
10
import java.util.Random;
11
import java.util.UUID;
12
import net.minecraft.block.Block;
13
import net.minecraft.block.material.Material;
14
import net.minecraft.block.state.IBlockState;
15
import net.minecraft.enchantment.EnchantmentHelper;
16
import net.minecraft.entity.ai.attributes.AttributeModifier;
17
import net.minecraft.entity.ai.attributes.BaseAttributeMap;
18
import net.minecraft.entity.ai.attributes.IAttribute;
19
import net.minecraft.entity.ai.attributes.IAttributeInstance;
20
import net.minecraft.entity.ai.attributes.ServersideAttributeMap;
21
import net.minecraft.entity.item.EntityItem;
22
import net.minecraft.entity.item.EntityXPOrb;
23
import net.minecraft.entity.passive.EntityWolf;
24
import net.minecraft.entity.player.EntityPlayer;
25
import net.minecraft.entity.player.EntityPlayerMP;
26
import net.minecraft.entity.projectile.EntityArrow;
27
import net.minecraft.init.Blocks;
28
import net.minecraft.item.Item;
29
import net.minecraft.item.ItemArmor;
30
import net.minecraft.item.ItemStack;
31
import net.minecraft.nbt.NBTBase;
32
import net.minecraft.nbt.NBTTagCompound;
33
import net.minecraft.nbt.NBTTagFloat;
34
import net.minecraft.nbt.NBTTagList;
35
import net.minecraft.nbt.NBTTagShort;
36
import net.minecraft.network.play.server.S04PacketEntityEquipment;
37
import net.minecraft.network.play.server.S0BPacketAnimation;
38
import net.minecraft.network.play.server.S0DPacketCollectItem;
39
import net.minecraft.potion.Potion;
40
import net.minecraft.potion.PotionEffect;
41
import net.minecraft.potion.PotionHelper;
42
import net.minecraft.scoreboard.Team;
43
import net.minecraft.util.AxisAlignedBB;
44
import net.minecraft.util.BlockPos;
45
import net.minecraft.util.CombatTracker;
46
import net.minecraft.util.DamageSource;
47
import net.minecraft.util.EntitySelectors;
48
import net.minecraft.util.EnumParticleTypes;
49
import net.minecraft.util.MathHelper;
50
import net.minecraft.util.Vec3;
51
import net.minecraft.world.World;
52
import net.minecraft.world.WorldServer;
53
54
public abstract class EntityLivingBase extends Entity
55
{
56
    private static final UUID sprintingSpeedBoostModifierUUID = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
57
    private static final AttributeModifier sprintingSpeedBoostModifier = (new AttributeModifier(sprintingSpeedBoostModifierUUID, "Sprinting speed boost", 0.30000001192092896D, 2)).setSaved(false);
58
    private BaseAttributeMap attributeMap;
59
    private final CombatTracker _combatTracker = new CombatTracker(this);
60
    private final Map<Integer, PotionEffect> activePotionsMap = Maps.<Integer, PotionEffect>newHashMap();
61
62
    /** The equipment this mob was previously wearing, used for syncing. */
63
    private final ItemStack[] previousEquipment = new ItemStack[5];
64
65
    /** Whether an arm swing is currently in progress. */
66
    public boolean isSwingInProgress;
67
    public int swingProgressInt;
68
    public int arrowHitTimer;
69
70
    /**
71
     * The amount of time remaining this entity should act 'hurt'. (Visual appearance of red tint)
72
     */
73
    public int hurtTime;
74
75
    /** What the hurt time was max set to last. */
76
    public int maxHurtTime;
77
78
    /** The yaw at which this entity was last attacked from. */
79
    public float attackedAtYaw;
80
81
    /**
82
     * The amount of time remaining this entity should act 'dead', i.e. have a corpse in the world.
83
     */
84
    public int deathTime;
85
    public float prevSwingProgress;
86
    public float swingProgress;
87
    public float prevLimbSwingAmount;
88
    public float limbSwingAmount;
89
90
    /**
91
     * Only relevant when limbYaw is not 0(the entity is moving). Influences where in its swing legs and arms currently
92
     * are.
93
     */
94
    public float limbSwing;
95
    public int maxHurtResistantTime = 20;
96
    public float prevCameraPitch;
97
    public float cameraPitch;
98
    public float randomUnused2;
99
    public float randomUnused1;
100
    public float renderYawOffset;
101
    public float prevRenderYawOffset;
102
103
    /** Entity head rotation yaw */
104
    public float rotationYawHead;
105
106
    /** Entity head rotation yaw at previous tick */
107
    public float prevRotationYawHead;
108
109
    /**
110
     * A factor used to determine how far this entity will move each tick if it is jumping or falling.
111
     */
112
    public float jumpMovementFactor = 0.02F;
113
114
    /** The most recent player that has attacked this entity */
115
    protected EntityPlayer attackingPlayer;
116
117
    /**
118
     * Set to 60 when hit by the player or the player's wolf, then decrements. Used to determine whether the entity
119
     * should drop items on death.
120
     */
121
    protected int recentlyHit;
122
123
    /**
124
     * This gets set on entity death, but never used. Looks like a duplicate of isDead
125
     */
126
    protected boolean dead;
127
128
    /** The age of this EntityLiving (used to determine when it dies) */
129
    protected int entityAge;
130
    protected float prevOnGroundSpeedFactor;
131
    protected float onGroundSpeedFactor;
132
    protected float movedDistance;
133
    protected float prevMovedDistance;
134
    protected float unused180;
135
136
    /** The score value of the Mob, the amount of points the mob is worth. */
137
    protected int scoreValue;
138
139
    /**
140
     * Damage taken in the last hit. Mobs are resistant to damage less than this for a short time after taking damage.
141
     */
142
    protected float lastDamage;
143
144
    /** used to check whether entity is jumping. */
145
    protected boolean isJumping;
146
    public float moveStrafing;
147
    public float moveForward;
148
    protected float randomYawVelocity;
149
150
    /**
151
     * The number of updates over which the new position and rotation are to be applied to the entity.
152
     */
153
    protected int newPosRotationIncrements;
154
155
    /** The new X position to be applied to the entity. */
156
    protected double newPosX;
157
158
    /** The new Y position to be applied to the entity. */
159
    protected double newPosY;
160
    protected double newPosZ;
161
162
    /** The new yaw rotation to be applied to the entity. */
163
    protected double newRotationYaw;
164
165
    /** The new yaw rotation to be applied to the entity. */
166
    protected double newRotationPitch;
167
168
    /** Whether the DataWatcher needs to be updated with the active potions */
169
    private boolean potionsNeedUpdate = true;
170
171
    /** is only being set, has no uses as of MC 1.1 */
172
    private EntityLivingBase entityLivingToAttack;
173
    private int revengeTimer;
174
    private EntityLivingBase lastAttacker;
175
176
    /** Holds the value of ticksExisted when setLastAttacker was last called. */
177
    private int lastAttackerTime;
178
179
    /**
180
     * A factor used to determine how far this entity will move each tick if it is walking on land. Adjusted by speed,
181
     * and slipperiness of the current block.
182
     */
183
    private float landMovementFactor;
184
185
    /** Number of ticks since last jump */
186
    private int jumpTicks;
187
    private float absorptionAmount;
188
189
    /**
190
     * Called by the /kill command.
191
     */
192
    public void onKillCommand()
193
    {
194
        this.attackEntityFrom(DamageSource.outOfWorld, Float.MAX_VALUE);
195
    }
196
197
    public EntityLivingBase(World worldIn)
198
    {
199
        super(worldIn);
200
        this.applyEntityAttributes();
201
        this.setHealth(this.getMaxHealth());
202
        this.preventEntitySpawning = true;
203
        this.randomUnused1 = (float)((Math.random() + 1.0D) * 0.009999999776482582D);
204
        this.setPosition(this.posX, this.posY, this.posZ);
205
        this.randomUnused2 = (float)Math.random() * 12398.0F;
206
        this.rotationYaw = (float)(Math.random() * Math.PI * 2.0D);
207
        this.rotationYawHead = this.rotationYaw;
208
        this.stepHeight = 0.6F;
209
    }
210
211
    protected void entityInit()
212
    {
213
        this.dataWatcher.addObject(7, Integer.valueOf(0));
214
        this.dataWatcher.addObject(8, Byte.valueOf((byte)0));
215
        this.dataWatcher.addObject(9, Byte.valueOf((byte)0));
216
        this.dataWatcher.addObject(6, Float.valueOf(1.0F));
217
    }
218
219
    protected void applyEntityAttributes()
220
    {
221
        this.getAttributeMap().registerAttribute(SharedMonsterAttributes.maxHealth);
222
        this.getAttributeMap().registerAttribute(SharedMonsterAttributes.knockbackResistance);
223
        this.getAttributeMap().registerAttribute(SharedMonsterAttributes.movementSpeed);
224
    }
225
226
    protected void updateFallState(double y, boolean onGroundIn, Block blockIn, BlockPos pos)
227
    {
228
        if (!this.isInWater())
229
        {
230
            this.handleWaterMovement();
231
        }
232
233
        if (!this.worldObj.isRemote && this.fallDistance > 3.0F && onGroundIn)
234
        {
235
            IBlockState iblockstate = this.worldObj.getBlockState(pos);
236
            Block block = iblockstate.getBlock();
237
            float f = (float)MathHelper.ceiling_float_int(this.fallDistance - 3.0F);
238
239
            if (block.getMaterial() != Material.air)
240
            {
241
                double d0 = (double)Math.min(0.2F + f / 15.0F, 10.0F);
242
243
                if (d0 > 2.5D)
244
                {
245
                    d0 = 2.5D;
246
                }
247
248
                int i = (int)(150.0D * d0);
249
                ((WorldServer)this.worldObj).spawnParticle(EnumParticleTypes.BLOCK_DUST, this.posX, this.posY, this.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, new int[] {Block.getStateId(iblockstate)});
250
            }
251
        }
252
253
        super.updateFallState(y, onGroundIn, blockIn, pos);
254
    }
255
256
    public boolean canBreatheUnderwater()
257
    {
258
        return false;
259
    }
260
261
    /**
262
     * Gets called every tick from main Entity class
263
     */
264
    public void onEntityUpdate()
265
    {
266
        this.prevSwingProgress = this.swingProgress;
267
        super.onEntityUpdate();
268
        this.worldObj.theProfiler.startSection("livingEntityBaseTick");
269
        boolean flag = this instanceof EntityPlayer;
270
271
        if (this.isEntityAlive())
272
        {
273
            if (this.isEntityInsideOpaqueBlock())
274
            {
275
                this.attackEntityFrom(DamageSource.inWall, 1.0F);
276
            }
277
            else if (flag && !this.worldObj.getWorldBorder().contains(this.getEntityBoundingBox()))
278
            {
279
                double d0 = this.worldObj.getWorldBorder().getClosestDistance(this) + this.worldObj.getWorldBorder().getDamageBuffer();
280
281
                if (d0 < 0.0D)
282
                {
283
                    this.attackEntityFrom(DamageSource.inWall, (float)Math.max(1, MathHelper.floor_double(-d0 * this.worldObj.getWorldBorder().getDamageAmount())));
284
                }
285
            }
286
        }
287
288
        if (this.isImmuneToFire() || this.worldObj.isRemote)
289
        {
290
            this.extinguish();
291
        }
292
293
        boolean flag1 = flag && ((EntityPlayer)this).capabilities.disableDamage;
294
295
        if (this.isEntityAlive())
296
        {
297
            if (this.isInsideOfMaterial(Material.water))
298
            {
299
                if (!this.canBreatheUnderwater() && !this.isPotionActive(Potion.waterBreathing.id) && !flag1)
300
                {
301
                    this.setAir(this.decreaseAirSupply(this.getAir()));
302
303
                    if (this.getAir() == -20)
304
                    {
305
                        this.setAir(0);
306
307
                        for (int i = 0; i < 8; ++i)
308
                        {
309
                            float f = this.rand.nextFloat() - this.rand.nextFloat();
310
                            float f1 = this.rand.nextFloat() - this.rand.nextFloat();
311
                            float f2 = this.rand.nextFloat() - this.rand.nextFloat();
312
                            this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX + (double)f, this.posY + (double)f1, this.posZ + (double)f2, this.motionX, this.motionY, this.motionZ, new int[0]);
313
                        }
314
315
                        this.attackEntityFrom(DamageSource.drown, 2.0F);
316
                    }
317
                }
318
319
                if (!this.worldObj.isRemote && this.isRiding() && this.ridingEntity instanceof EntityLivingBase)
320
                {
321
                    this.mountEntity((Entity)null);
322
                }
323
            }
324
            else
325
            {
326
                this.setAir(300);
327
            }
328
        }
329
330
        if (this.isEntityAlive() && this.isWet())
331
        {
332
            this.extinguish();
333
        }
334
335
        this.prevCameraPitch = this.cameraPitch;
336
337
        if (this.hurtTime > 0)
338
        {
339
            --this.hurtTime;
340
        }
341
342
        if (this.hurtResistantTime > 0 && !(this instanceof EntityPlayerMP))
343
        {
344
            --this.hurtResistantTime;
345
        }
346
347
        if (this.getHealth() <= 0.0F)
348
        {
349
            this.onDeathUpdate();
350
        }
351
352
        if (this.recentlyHit > 0)
353
        {
354
            --this.recentlyHit;
355
        }
356
        else
357
        {
358
            this.attackingPlayer = null;
359
        }
360
361
        if (this.lastAttacker != null && !this.lastAttacker.isEntityAlive())
362
        {
363
            this.lastAttacker = null;
364
        }
365
366
        if (this.entityLivingToAttack != null)
367
        {
368
            if (!this.entityLivingToAttack.isEntityAlive())
369
            {
370
                this.setRevengeTarget((EntityLivingBase)null);
371
            }
372
            else if (this.ticksExisted - this.revengeTimer > 100)
373
            {
374
                this.setRevengeTarget((EntityLivingBase)null);
375
            }
376
        }
377
378
        this.updatePotionEffects();
379
        this.prevMovedDistance = this.movedDistance;
380
        this.prevRenderYawOffset = this.renderYawOffset;
381
        this.prevRotationYawHead = this.rotationYawHead;
382
        this.prevRotationYaw = this.rotationYaw;
383
        this.prevRotationPitch = this.rotationPitch;
384
        this.worldObj.theProfiler.endSection();
385
    }
386
387
    /**
388
     * If Animal, checks if the age timer is negative
389
     */
390
    public boolean isChild()
391
    {
392
        return false;
393
    }
394
395
    /**
396
     * handles entity death timer, experience orb and particle creation
397
     */
398
    protected void onDeathUpdate()
399
    {
400
        ++this.deathTime;
401
402
        if (this.deathTime == 20)
403
        {
404
            if (!this.worldObj.isRemote && (this.recentlyHit > 0 || this.isPlayer()) && this.canDropLoot() && this.worldObj.getGameRules().getBoolean("doMobLoot"))
405
            {
406
                int i = this.getExperiencePoints(this.attackingPlayer);
407
408
                while (i > 0)
409
                {
410
                    int j = EntityXPOrb.getXPSplit(i);
411
                    i -= j;
412
                    this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
413
                }
414
            }
415
416
            this.setDead();
417
418
            for (int k = 0; k < 20; ++k)
419
            {
420
                double d2 = this.rand.nextGaussian() * 0.02D;
421
                double d0 = this.rand.nextGaussian() * 0.02D;
422
                double d1 = this.rand.nextGaussian() * 0.02D;
423
                this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d2, d0, d1, new int[0]);
424
            }
425
        }
426
    }
427
428
    /**
429
     * Entity won't drop items or experience points if this returns false
430
     */
431
    protected boolean canDropLoot()
432
    {
433
        return !this.isChild();
434
    }
435
436
    /**
437
     * Decrements the entity's air supply when underwater
438
     */
439
    protected int decreaseAirSupply(int p_70682_1_)
440
    {
441
        int i = EnchantmentHelper.getRespiration(this);
442
        return i > 0 && this.rand.nextInt(i + 1) > 0 ? p_70682_1_ : p_70682_1_ - 1;
443
    }
444
445
    /**
446
     * Get the experience points the entity currently has.
447
     */
448
    protected int getExperiencePoints(EntityPlayer player)
449
    {
450
        return 0;
451
    }
452
453
    /**
454
     * Only use is to identify if class is an instance of player for experience dropping
455
     */
456
    protected boolean isPlayer()
457
    {
458
        return false;
459
    }
460
461
    public Random getRNG()
462
    {
463
        return this.rand;
464
    }
465
466
    public EntityLivingBase getAITarget()
467
    {
468
        return this.entityLivingToAttack;
469
    }
470
471
    public int getRevengeTimer()
472
    {
473
        return this.revengeTimer;
474
    }
475
476
    public void setRevengeTarget(EntityLivingBase livingBase)
477
    {
478
        this.entityLivingToAttack = livingBase;
479
        this.revengeTimer = this.ticksExisted;
480
    }
481
482
    public EntityLivingBase getLastAttacker()
483
    {
484
        return this.lastAttacker;
485
    }
486
487
    public int getLastAttackerTime()
488
    {
489
        return this.lastAttackerTime;
490
    }
491
492
    public void setLastAttacker(Entity entityIn)
493
    {
494
        if (entityIn instanceof EntityLivingBase)
495
        {
496
            this.lastAttacker = (EntityLivingBase)entityIn;
497
        }
498
        else
499
        {
500
            this.lastAttacker = null;
501
        }
502
503
        this.lastAttackerTime = this.ticksExisted;
504
    }
505
506
    public int getAge()
507
    {
508
        return this.entityAge;
509
    }
510
511
    /**
512
     * (abstract) Protected helper method to write subclass entity data to NBT.
513
     */
514
    public void writeEntityToNBT(NBTTagCompound tagCompound)
515
    {
516
        tagCompound.setFloat("HealF", this.getHealth());
517
        tagCompound.setShort("Health", (short)((int)Math.ceil((double)this.getHealth())));
518
        tagCompound.setShort("HurtTime", (short)this.hurtTime);
519
        tagCompound.setInteger("HurtByTimestamp", this.revengeTimer);
520
        tagCompound.setShort("DeathTime", (short)this.deathTime);
521
        tagCompound.setFloat("AbsorptionAmount", this.getAbsorptionAmount());
522
523
        for (ItemStack itemstack : this.getInventory())
524
        {
525
            if (itemstack != null)
526
            {
527
                this.attributeMap.removeAttributeModifiers(itemstack.getAttributeModifiers());
528
            }
529
        }
530
531
        tagCompound.setTag("Attributes", SharedMonsterAttributes.writeBaseAttributeMapToNBT(this.getAttributeMap()));
532
533
        for (ItemStack itemstack1 : this.getInventory())
534
        {
535
            if (itemstack1 != null)
536
            {
537
                this.attributeMap.applyAttributeModifiers(itemstack1.getAttributeModifiers());
538
            }
539
        }
540
541
        if (!this.activePotionsMap.isEmpty())
542
        {
543
            NBTTagList nbttaglist = new NBTTagList();
544
545
            for (PotionEffect potioneffect : this.activePotionsMap.values())
546
            {
547
                nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
548
            }
549
550
            tagCompound.setTag("ActiveEffects", nbttaglist);
551
        }
552
    }
553
554
    /**
555
     * (abstract) Protected helper method to read subclass entity data from NBT.
556
     */
557
    public void readEntityFromNBT(NBTTagCompound tagCompund)
558
    {
559
        this.setAbsorptionAmount(tagCompund.getFloat("AbsorptionAmount"));
560
561
        if (tagCompund.hasKey("Attributes", 9) && this.worldObj != null && !this.worldObj.isRemote)
562
        {
563
            SharedMonsterAttributes.setAttributeModifiers(this.getAttributeMap(), tagCompund.getTagList("Attributes", 10));
564
        }
565
566
        if (tagCompund.hasKey("ActiveEffects", 9))
567
        {
568
            NBTTagList nbttaglist = tagCompund.getTagList("ActiveEffects", 10);
569
570
            for (int i = 0; i < nbttaglist.tagCount(); ++i)
571
            {
572
                NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
573
                PotionEffect potioneffect = PotionEffect.readCustomPotionEffectFromNBT(nbttagcompound);
574
575
                if (potioneffect != null)
576
                {
577
                    this.activePotionsMap.put(Integer.valueOf(potioneffect.getPotionID()), potioneffect);
578
                }
579
            }
580
        }
581
582
        if (tagCompund.hasKey("HealF", 99))
583
        {
584
            this.setHealth(tagCompund.getFloat("HealF"));
585
        }
586
        else
587
        {
588
            NBTBase nbtbase = tagCompund.getTag("Health");
589
590
            if (nbtbase == null)
591
            {
592
                this.setHealth(this.getMaxHealth());
593
            }
594
            else if (nbtbase.getId() == 5)
595
            {
596
                this.setHealth(((NBTTagFloat)nbtbase).getFloat());
597
            }
598
            else if (nbtbase.getId() == 2)
599
            {
600
                this.setHealth((float)((NBTTagShort)nbtbase).getShort());
601
            }
602
        }
603
604
        this.hurtTime = tagCompund.getShort("HurtTime");
605
        this.deathTime = tagCompund.getShort("DeathTime");
606
        this.revengeTimer = tagCompund.getInteger("HurtByTimestamp");
607
    }
608
609
    protected void updatePotionEffects()
610
    {
611
        Iterator<Integer> iterator = this.activePotionsMap.keySet().iterator();
612
613
        while (iterator.hasNext())
614
        {
615
            Integer integer = (Integer)iterator.next();
616
            PotionEffect potioneffect = (PotionEffect)this.activePotionsMap.get(integer);
617
618
            if (!potioneffect.onUpdate(this))
619
            {
620
                if (!this.worldObj.isRemote)
621
                {
622
                    iterator.remove();
623
                    this.onFinishedPotionEffect(potioneffect);
624
                }
625
            }
626
            else if (potioneffect.getDuration() % 600 == 0)
627
            {
628
                this.onChangedPotionEffect(potioneffect, false);
629
            }
630
        }
631
632
        if (this.potionsNeedUpdate)
633
        {
634
            if (!this.worldObj.isRemote)
635
            {
636
                this.updatePotionMetadata();
637
            }
638
639
            this.potionsNeedUpdate = false;
640
        }
641
642
        int i = this.dataWatcher.getWatchableObjectInt(7);
643
        boolean flag1 = this.dataWatcher.getWatchableObjectByte(8) > 0;
644
645
        if (i > 0)
646
        {
647
            boolean flag = false;
648
649
            if (!this.isInvisible())
650
            {
651
                flag = this.rand.nextBoolean();
652
            }
653
            else
654
            {
655
                flag = this.rand.nextInt(15) == 0;
656
            }
657
658
            if (flag1)
659
            {
660
                flag &= this.rand.nextInt(5) == 0;
661
            }
662
663
            if (flag && i > 0)
664
            {
665
                double d0 = (double)(i >> 16 & 255) / 255.0D;
666
                double d1 = (double)(i >> 8 & 255) / 255.0D;
667
                double d2 = (double)(i >> 0 & 255) / 255.0D;
668
                this.worldObj.spawnParticle(flag1 ? EnumParticleTypes.SPELL_MOB_AMBIENT : EnumParticleTypes.SPELL_MOB, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, d0, d1, d2, new int[0]);
669
            }
670
        }
671
    }
672
673
    /**
674
     * Clears potion metadata values if the entity has no potion effects. Otherwise, updates potion effect color,
675
     * ambience, and invisibility metadata values
676
     */
677
    protected void updatePotionMetadata()
678
    {
679
        if (this.activePotionsMap.isEmpty())
680
        {
681
            this.resetPotionEffectMetadata();
682
            this.setInvisible(false);
683
        }
684
        else
685
        {
686
            int i = PotionHelper.calcPotionLiquidColor(this.activePotionsMap.values());
687
            this.dataWatcher.updateObject(8, Byte.valueOf((byte)(PotionHelper.getAreAmbient(this.activePotionsMap.values()) ? 1 : 0)));
688
            this.dataWatcher.updateObject(7, Integer.valueOf(i));
689
            this.setInvisible(this.isPotionActive(Potion.invisibility.id));
690
        }
691
    }
692
693
    /**
694
     * Resets the potion effect color and ambience metadata values
695
     */
696
    protected void resetPotionEffectMetadata()
697
    {
698
        this.dataWatcher.updateObject(8, Byte.valueOf((byte)0));
699
        this.dataWatcher.updateObject(7, Integer.valueOf(0));
700
    }
701
702
    public void clearActivePotions()
703
    {
704
        Iterator<Integer> iterator = this.activePotionsMap.keySet().iterator();
705
706
        while (iterator.hasNext())
707
        {
708
            Integer integer = (Integer)iterator.next();
709
            PotionEffect potioneffect = (PotionEffect)this.activePotionsMap.get(integer);
710
711
            if (!this.worldObj.isRemote)
712
            {
713
                iterator.remove();
714
                this.onFinishedPotionEffect(potioneffect);
715
            }
716
        }
717
    }
718
719
    public Collection<PotionEffect> getActivePotionEffects()
720
    {
721
        return this.activePotionsMap.values();
722
    }
723
724
    public boolean isPotionActive(int potionId)
725
    {
726
        return this.activePotionsMap.containsKey(Integer.valueOf(potionId));
727
    }
728
729
    public boolean isPotionActive(Potion potionIn)
730
    {
731
        return this.activePotionsMap.containsKey(Integer.valueOf(potionIn.id));
732
    }
733
734
    /**
735
     * returns the PotionEffect for the supplied Potion if it is active, null otherwise.
736
     */
737
    public PotionEffect getActivePotionEffect(Potion potionIn)
738
    {
739
        return (PotionEffect)this.activePotionsMap.get(Integer.valueOf(potionIn.id));
740
    }
741
742
    /**
743
     * adds a PotionEffect to the entity
744
     */
745
    public void addPotionEffect(PotionEffect potioneffectIn)
746
    {
747
        if (this.isPotionApplicable(potioneffectIn))
748
        {
749
            if (this.activePotionsMap.containsKey(Integer.valueOf(potioneffectIn.getPotionID())))
750
            {
751
                ((PotionEffect)this.activePotionsMap.get(Integer.valueOf(potioneffectIn.getPotionID()))).combine(potioneffectIn);
752
                this.onChangedPotionEffect((PotionEffect)this.activePotionsMap.get(Integer.valueOf(potioneffectIn.getPotionID())), true);
753
            }
754
            else
755
            {
756
                this.activePotionsMap.put(Integer.valueOf(potioneffectIn.getPotionID()), potioneffectIn);
757
                this.onNewPotionEffect(potioneffectIn);
758
            }
759
        }
760
    }
761
762
    public boolean isPotionApplicable(PotionEffect potioneffectIn)
763
    {
764
        if (this.getCreatureAttribute() == EnumCreatureAttribute.UNDEAD)
765
        {
766
            int i = potioneffectIn.getPotionID();
767
768
            if (i == Potion.regeneration.id || i == Potion.poison.id)
769
            {
770
                return false;
771
            }
772
        }
773
774
        return true;
775
    }
776
777
    /**
778
     * Returns true if this entity is undead.
779
     */
780
    public boolean isEntityUndead()
781
    {
782
        return this.getCreatureAttribute() == EnumCreatureAttribute.UNDEAD;
783
    }
784
785
    /**
786
     * Remove the speified potion effect from this entity.
787
     */
788
    public void removePotionEffectClient(int potionId)
789
    {
790
        this.activePotionsMap.remove(Integer.valueOf(potionId));
791
    }
792
793
    /**
794
     * Remove the specified potion effect from this entity.
795
     */
796
    public void removePotionEffect(int potionId)
797
    {
798
        PotionEffect potioneffect = (PotionEffect)this.activePotionsMap.remove(Integer.valueOf(potionId));
799
800
        if (potioneffect != null)
801
        {
802
            this.onFinishedPotionEffect(potioneffect);
803
        }
804
    }
805
806
    protected void onNewPotionEffect(PotionEffect id)
807
    {
808
        this.potionsNeedUpdate = true;
809
810
        if (!this.worldObj.isRemote)
811
        {
812
            Potion.potionTypes[id.getPotionID()].applyAttributesModifiersToEntity(this, this.getAttributeMap(), id.getAmplifier());
813
        }
814
    }
815
816
    protected void onChangedPotionEffect(PotionEffect id, boolean p_70695_2_)
817
    {
818
        this.potionsNeedUpdate = true;
819
820
        if (p_70695_2_ && !this.worldObj.isRemote)
821
        {
822
            Potion.potionTypes[id.getPotionID()].removeAttributesModifiersFromEntity(this, this.getAttributeMap(), id.getAmplifier());
823
            Potion.potionTypes[id.getPotionID()].applyAttributesModifiersToEntity(this, this.getAttributeMap(), id.getAmplifier());
824
        }
825
    }
826
827
    protected void onFinishedPotionEffect(PotionEffect effect)
828
    {
829
        this.potionsNeedUpdate = true;
830
831
        if (!this.worldObj.isRemote)
832
        {
833
            Potion.potionTypes[effect.getPotionID()].removeAttributesModifiersFromEntity(this, this.getAttributeMap(), effect.getAmplifier());
834
        }
835
    }
836
837
    /**
838
     * Heal living entity (param: amount of half-hearts)
839
     */
840
    public void heal(float healAmount)
841
    {
842
        float f = this.getHealth();
843
844
        if (f > 0.0F)
845
        {
846
            this.setHealth(f + healAmount);
847
        }
848
    }
849
850
    public final float getHealth()
851
    {
852
        return this.dataWatcher.getWatchableObjectFloat(6);
853
    }
854
855
    public void setHealth(float health)
856
    {
857
        this.dataWatcher.updateObject(6, Float.valueOf(MathHelper.clamp_float(health, 0.0F, this.getMaxHealth())));
858
    }
859
860
    /**
861
     * Called when the entity is attacked.
862
     */
863
    public boolean attackEntityFrom(DamageSource source, float amount)
864
    {
865
        if (this.isEntityInvulnerable(source))
866
        {
867
            return false;
868
        }
869
        else if (this.worldObj.isRemote)
870
        {
871
            return false;
872
        }
873
        else
874
        {
875
            this.entityAge = 0;
876
877
            if (this.getHealth() <= 0.0F)
878
            {
879
                return false;
880
            }
881
            else if (source.isFireDamage() && this.isPotionActive(Potion.fireResistance))
882
            {
883
                return false;
884
            }
885
            else
886
            {
887
                if ((source == DamageSource.anvil || source == DamageSource.fallingBlock) && this.getEquipmentInSlot(4) != null)
888
                {
889
                    this.getEquipmentInSlot(4).damageItem((int)(amount * 4.0F + this.rand.nextFloat() * amount * 2.0F), this);
890
                    amount *= 0.75F;
891
                }
892
893
                this.limbSwingAmount = 1.5F;
894
                boolean flag = true;
895
896
                if ((float)this.hurtResistantTime > (float)this.maxHurtResistantTime / 2.0F)
897
                {
898
                    if (amount <= this.lastDamage)
899
                    {
900
                        return false;
901
                    }
902
903
                    this.damageEntity(source, amount - this.lastDamage);
904
                    this.lastDamage = amount;
905
                    flag = false;
906
                }
907
                else
908
                {
909
                    this.lastDamage = amount;
910
                    this.hurtResistantTime = this.maxHurtResistantTime;
911
                    this.damageEntity(source, amount);
912
                    this.hurtTime = this.maxHurtTime = 10;
913
                }
914
915
                this.attackedAtYaw = 0.0F;
916
                Entity entity = source.getEntity();
917
918
                if (entity != null)
919
                {
920
                    if (entity instanceof EntityLivingBase)
921
                    {
922
                        this.setRevengeTarget((EntityLivingBase)entity);
923
                    }
924
925
                    if (entity instanceof EntityPlayer)
926
                    {
927
                        this.recentlyHit = 100;
928
                        this.attackingPlayer = (EntityPlayer)entity;
929
                    }
930
                    else if (entity instanceof EntityWolf)
931
                    {
932
                        EntityWolf entitywolf = (EntityWolf)entity;
933
934
                        if (entitywolf.isTamed())
935
                        {
936
                            this.recentlyHit = 100;
937
                            this.attackingPlayer = null;
938
                        }
939
                    }
940
                }
941
942
                if (flag)
943
                {
944
                    this.worldObj.setEntityState(this, (byte)2);
945
946
                    if (source != DamageSource.drown)
947
                    {
948
                        this.setBeenAttacked();
949
                    }
950
951
                    if (entity != null)
952
                    {
953
                        double d1 = entity.posX - this.posX;
954
                        double d0;
955
956
                        for (d0 = entity.posZ - this.posZ; d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D)
957
                        {
958
                            d1 = (Math.random() - Math.random()) * 0.01D;
959
                        }
960
961
                        this.attackedAtYaw = (float)(MathHelper.atan2(d0, d1) * 180.0D / Math.PI - (double)this.rotationYaw);
962
                        this.knockBack(entity, amount, d1, d0);
963
                    }
964
                    else
965
                    {
966
                        this.attackedAtYaw = (float)((int)(Math.random() * 2.0D) * 180);
967
                    }
968
                }
969
970
                if (this.getHealth() <= 0.0F)
971
                {
972
                    String s = this.getDeathSound();
973
974
                    if (flag && s != null)
975
                    {
976
                        this.playSound(s, this.getSoundVolume(), this.getSoundPitch());
977
                    }
978
979
                    this.onDeath(source);
980
                }
981
                else
982
                {
983
                    String s1 = this.getHurtSound();
984
985
                    if (flag && s1 != null)
986
                    {
987
                        this.playSound(s1, this.getSoundVolume(), this.getSoundPitch());
988
                    }
989
                }
990
991
                return true;
992
            }
993
        }
994
    }
995
996
    /**
997
     * Renders broken item particles using the given ItemStack
998
     */
999
    public void renderBrokenItemStack(ItemStack stack)
1000
    {
1001
        this.playSound("random.break", 0.8F, 0.8F + this.worldObj.rand.nextFloat() * 0.4F);
1002
1003
        for (int i = 0; i < 5; ++i)
1004
        {
1005
            Vec3 vec3 = new Vec3(((double)this.rand.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
1006
            vec3 = vec3.rotatePitch(-this.rotationPitch * (float)Math.PI / 180.0F);
1007
            vec3 = vec3.rotateYaw(-this.rotationYaw * (float)Math.PI / 180.0F);
1008
            double d0 = (double)(-this.rand.nextFloat()) * 0.6D - 0.3D;
1009
            Vec3 vec31 = new Vec3(((double)this.rand.nextFloat() - 0.5D) * 0.3D, d0, 0.6D);
1010
            vec31 = vec31.rotatePitch(-this.rotationPitch * (float)Math.PI / 180.0F);
1011
            vec31 = vec31.rotateYaw(-this.rotationYaw * (float)Math.PI / 180.0F);
1012
            vec31 = vec31.addVector(this.posX, this.posY + (double)this.getEyeHeight(), this.posZ);
1013
            this.worldObj.spawnParticle(EnumParticleTypes.ITEM_CRACK, vec31.xCoord, vec31.yCoord, vec31.zCoord, vec3.xCoord, vec3.yCoord + 0.05D, vec3.zCoord, new int[] {Item.getIdFromItem(stack.getItem())});
1014
        }
1015
    }
1016
1017
    /**
1018
     * Called when the mob's health reaches 0.
1019
     */
1020
    public void onDeath(DamageSource cause)
1021
    {
1022
        Entity entity = cause.getEntity();
1023
        EntityLivingBase entitylivingbase = this.getAttackingEntity();
1024
1025
        if (this.scoreValue >= 0 && entitylivingbase != null)
1026
        {
1027
            entitylivingbase.addToPlayerScore(this, this.scoreValue);
1028
        }
1029
1030
        if (entity != null)
1031
        {
1032
            entity.onKillEntity(this);
1033
        }
1034
1035
        this.dead = true;
1036
        this.getCombatTracker().reset();
1037
1038
        if (!this.worldObj.isRemote)
1039
        {
1040
            int i = 0;
1041
1042
            if (entity instanceof EntityPlayer)
1043
            {
1044
                i = EnchantmentHelper.getLootingModifier((EntityLivingBase)entity);
1045
            }
1046
1047
            if (this.canDropLoot() && this.worldObj.getGameRules().getBoolean("doMobLoot"))
1048
            {
1049
                this.dropFewItems(this.recentlyHit > 0, i);
1050
                this.dropEquipment(this.recentlyHit > 0, i);
1051
1052
                if (this.recentlyHit > 0 && this.rand.nextFloat() < 0.025F + (float)i * 0.01F)
1053
                {
1054
                    this.addRandomDrop();
1055
                }
1056
            }
1057
        }
1058
1059
        this.worldObj.setEntityState(this, (byte)3);
1060
    }
1061
1062
    /**
1063
     * Drop the equipment for this entity.
1064
     *  
1065
     * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
1066
     * or tameable)
1067
     * @param lootingModifier level of enchanment to be applied to this drop
1068
     */
1069
    protected void dropEquipment(boolean wasRecentlyHit, int lootingModifier)
1070
    {
1071
    }
1072
1073
    /**
1074
     * knocks back this entity
1075
     */
1076
    public void knockBack(Entity entityIn, float p_70653_2_, double p_70653_3_, double p_70653_5_)
1077
    {
1078
        if (this.rand.nextDouble() >= this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).getAttributeValue())
1079
        {
1080
            this.isAirBorne = true;
1081
            float f = MathHelper.sqrt_double(p_70653_3_ * p_70653_3_ + p_70653_5_ * p_70653_5_);
1082
            float f1 = 0.4F;
1083
            this.motionX /= 2.0D;
1084
            this.motionY /= 2.0D;
1085
            this.motionZ /= 2.0D;
1086
            this.motionX -= p_70653_3_ / (double)f * (double)f1;
1087
            this.motionY += (double)f1;
1088
            this.motionZ -= p_70653_5_ / (double)f * (double)f1;
1089
1090
            if (this.motionY > 0.4000000059604645D)
1091
            {
1092
                this.motionY = 0.4000000059604645D;
1093
            }
1094
        }
1095
    }
1096
1097
    /**
1098
     * Returns the sound this mob makes when it is hurt.
1099
     */
1100
    protected String getHurtSound()
1101
    {
1102
        return "game.neutral.hurt";
1103
    }
1104
1105
    /**
1106
     * Returns the sound this mob makes on death.
1107
     */
1108
    protected String getDeathSound()
1109
    {
1110
        return "game.neutral.die";
1111
    }
1112
1113
    /**
1114
     * Causes this Entity to drop a random item.
1115
     */
1116
    protected void addRandomDrop()
1117
    {
1118
    }
1119
1120
    /**
1121
     * Drop 0-2 items of this living's type
1122
     *  
1123
     * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
1124
     * or tameable)
1125
     * @param lootingModifier level of enchanment to be applied to this drop
1126
     */
1127
    protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
1128
    {
1129
    }
1130
1131
    /**
1132
     * returns true if this entity is by a ladder, false otherwise
1133
     */
1134
    public boolean isOnLadder()
1135
    {
1136
        int i = MathHelper.floor_double(this.posX);
1137
        int j = MathHelper.floor_double(this.getEntityBoundingBox().minY);
1138
        int k = MathHelper.floor_double(this.posZ);
1139
        Block block = this.worldObj.getBlockState(new BlockPos(i, j, k)).getBlock();
1140
        return (block == Blocks.ladder || block == Blocks.vine) && (!(this instanceof EntityPlayer) || !((EntityPlayer)this).isSpectator());
1141
    }
1142
1143
    /**
1144
     * Checks whether target entity is alive.
1145
     */
1146
    public boolean isEntityAlive()
1147
    {
1148
        return !this.isDead && this.getHealth() > 0.0F;
1149
    }
1150
1151
    public void fall(float distance, float damageMultiplier)
1152
    {
1153
        super.fall(distance, damageMultiplier);
1154
        PotionEffect potioneffect = this.getActivePotionEffect(Potion.jump);
1155
        float f = potioneffect != null ? (float)(potioneffect.getAmplifier() + 1) : 0.0F;
1156
        int i = MathHelper.ceiling_float_int((distance - 3.0F - f) * damageMultiplier);
1157
1158
        if (i > 0)
1159
        {
1160
            this.playSound(this.getFallSoundString(i), 1.0F, 1.0F);
1161
            this.attackEntityFrom(DamageSource.fall, (float)i);
1162
            int j = MathHelper.floor_double(this.posX);
1163
            int k = MathHelper.floor_double(this.posY - 0.20000000298023224D);
1164
            int l = MathHelper.floor_double(this.posZ);
1165
            Block block = this.worldObj.getBlockState(new BlockPos(j, k, l)).getBlock();
1166
1167
            if (block.getMaterial() != Material.air)
1168
            {
1169
                Block.SoundType block$soundtype = block.stepSound;
1170
                this.playSound(block$soundtype.getStepSound(), block$soundtype.getVolume() * 0.5F, block$soundtype.getFrequency() * 0.75F);
1171
            }
1172
        }
1173
    }
1174
1175
    protected String getFallSoundString(int damageValue)
1176
    {
1177
        return damageValue > 4 ? "game.neutral.hurt.fall.big" : "game.neutral.hurt.fall.small";
1178
    }
1179
1180
    /**
1181
     * Setups the entity to do the hurt animation. Only used by packets in multiplayer.
1182
     */
1183
    public void performHurtAnimation()
1184
    {
1185
        this.hurtTime = this.maxHurtTime = 10;
1186
        this.attackedAtYaw = 0.0F;
1187
    }
1188
1189
    /**
1190
     * Returns the current armor value as determined by a call to InventoryPlayer.getTotalArmorValue
1191
     */
1192
    public int getTotalArmorValue()
1193
    {
1194
        int i = 0;
1195
1196
        for (ItemStack itemstack : this.getInventory())
1197
        {
1198
            if (itemstack != null && itemstack.getItem() instanceof ItemArmor)
1199
            {
1200
                int j = ((ItemArmor)itemstack.getItem()).damageReduceAmount;
1201
                i += j;
1202
            }
1203
        }
1204
1205
        return i;
1206
    }
1207
1208
    protected void damageArmor(float p_70675_1_)
1209
    {
1210
    }
1211
1212
    /**
1213
     * Reduces damage, depending on armor
1214
     */
1215
    protected float applyArmorCalculations(DamageSource source, float damage)
1216
    {
1217
        if (!source.isUnblockable())
1218
        {
1219
            int i = 25 - this.getTotalArmorValue();
1220
            float f = damage * (float)i;
1221
            this.damageArmor(damage);
1222
            damage = f / 25.0F;
1223
        }
1224
1225
        return damage;
1226
    }
1227
1228
    /**
1229
     * Reduces damage, depending on potions
1230
     */
1231
    protected float applyPotionDamageCalculations(DamageSource source, float damage)
1232
    {
1233
        if (source.isDamageAbsolute())
1234
        {
1235
            return damage;
1236
        }
1237
        else
1238
        {
1239
            if (this.isPotionActive(Potion.resistance) && source != DamageSource.outOfWorld)
1240
            {
1241
                int i = (this.getActivePotionEffect(Potion.resistance).getAmplifier() + 1) * 5;
1242
                int j = 25 - i;
1243
                float f = damage * (float)j;
1244
                damage = f / 25.0F;
1245
            }
1246
1247
            if (damage <= 0.0F)
1248
            {
1249
                return 0.0F;
1250
            }
1251
            else
1252
            {
1253
                int k = EnchantmentHelper.getEnchantmentModifierDamage(this.getInventory(), source);
1254
1255
                if (k > 20)
1256
                {
1257
                    k = 20;
1258
                }
1259
1260
                if (k > 0 && k <= 20)
1261
                {
1262
                    int l = 25 - k;
1263
                    float f1 = damage * (float)l;
1264
                    damage = f1 / 25.0F;
1265
                }
1266
1267
                return damage;
1268
            }
1269
        }
1270
    }
1271
1272
    /**
1273
     * Deals damage to the entity. If its a EntityPlayer then will take damage from the armor first and then health
1274
     * second with the reduced value. Args: damageAmount
1275
     */
1276
    protected void damageEntity(DamageSource damageSrc, float damageAmount)
1277
    {
1278
        if (!this.isEntityInvulnerable(damageSrc))
1279
        {
1280
            damageAmount = this.applyArmorCalculations(damageSrc, damageAmount);
1281
            damageAmount = this.applyPotionDamageCalculations(damageSrc, damageAmount);
1282
            float f = damageAmount;
1283
            damageAmount = Math.max(damageAmount - this.getAbsorptionAmount(), 0.0F);
1284
            this.setAbsorptionAmount(this.getAbsorptionAmount() - (f - damageAmount));
1285
1286
            if (damageAmount != 0.0F)
1287
            {
1288
                float f1 = this.getHealth();
1289
                this.setHealth(f1 - damageAmount);
1290
                this.getCombatTracker().trackDamage(damageSrc, f1, damageAmount);
1291
                this.setAbsorptionAmount(this.getAbsorptionAmount() - damageAmount);
1292
            }
1293
        }
1294
    }
1295
1296
    /**
1297
     * 1.8.9
1298
     */
1299
    public CombatTracker getCombatTracker()
1300
    {
1301
        return this._combatTracker;
1302
    }
1303
1304
    public EntityLivingBase getAttackingEntity()
1305
    {
1306
        return (EntityLivingBase)(this._combatTracker.func_94550_c() != null ? this._combatTracker.func_94550_c() : (this.attackingPlayer != null ? this.attackingPlayer : (this.entityLivingToAttack != null ? this.entityLivingToAttack : null)));
1307
    }
1308
1309
    public final float getMaxHealth()
1310
    {
1311
        return (float)this.getEntityAttribute(SharedMonsterAttributes.maxHealth).getAttributeValue();
1312
    }
1313
1314
    /**
1315
     * counts the amount of arrows stuck in the entity. getting hit by arrows increases this, used in rendering
1316
     */
1317
    public final int getArrowCountInEntity()
1318
    {
1319
        return this.dataWatcher.getWatchableObjectByte(9);
1320
    }
1321
1322
    /**
1323
     * sets the amount of arrows stuck in the entity. used for rendering those
1324
     */
1325
    public final void setArrowCountInEntity(int count)
1326
    {
1327
        this.dataWatcher.updateObject(9, Byte.valueOf((byte)count));
1328
    }
1329
1330
    /**
1331
     * Returns an integer indicating the end point of the swing animation, used by {@link #swingProgress} to provide a
1332
     * progress indicator. Takes dig speed enchantments into account.
1333
     */
1334
    private int getArmSwingAnimationEnd()
1335
    {
1336
        return this.isPotionActive(Potion.digSpeed) ? 6 - (1 + this.getActivePotionEffect(Potion.digSpeed).getAmplifier()) * 1 : (this.isPotionActive(Potion.digSlowdown) ? 6 + (1 + this.getActivePotionEffect(Potion.digSlowdown).getAmplifier()) * 2 : 6);
1337
    }
1338
1339
    /**
1340
     * Swings the item the player is holding.
1341
     */
1342
    public void swingItem()
1343
    {
1344
        if (!this.isSwingInProgress || this.swingProgressInt >= this.getArmSwingAnimationEnd() / 2 || this.swingProgressInt < 0)
1345
        {
1346
            this.swingProgressInt = -1;
1347
            this.isSwingInProgress = true;
1348
1349
            if (this.worldObj instanceof WorldServer)
1350
            {
1351
                ((WorldServer)this.worldObj).getEntityTracker().sendToAllTrackingEntity(this, new S0BPacketAnimation(this, 0));
1352
            }
1353
        }
1354
    }
1355
1356
    public void handleStatusUpdate(byte id)
1357
    {
1358
        if (id == 2)
1359
        {
1360
            this.limbSwingAmount = 1.5F;
1361
            this.hurtResistantTime = this.maxHurtResistantTime;
1362
            this.hurtTime = this.maxHurtTime = 10;
1363
            this.attackedAtYaw = 0.0F;
1364
            String s = this.getHurtSound();
1365
1366
            if (s != null)
1367
            {
1368
                this.playSound(this.getHurtSound(), this.getSoundVolume(), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
1369
            }
1370
1371
            this.attackEntityFrom(DamageSource.generic, 0.0F);
1372
        }
1373
        else if (id == 3)
1374
        {
1375
            String s1 = this.getDeathSound();
1376
1377
            if (s1 != null)
1378
            {
1379
                this.playSound(this.getDeathSound(), this.getSoundVolume(), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
1380
            }
1381
1382
            this.setHealth(0.0F);
1383
            this.onDeath(DamageSource.generic);
1384
        }
1385
        else
1386
        {
1387
            super.handleStatusUpdate(id);
1388
        }
1389
    }
1390
1391
    /**
1392
     * sets the dead flag. Used when you fall off the bottom of the world.
1393
     */
1394
    protected void kill()
1395
    {
1396
        this.attackEntityFrom(DamageSource.outOfWorld, 4.0F);
1397
    }
1398
1399
    /**
1400
     * Updates the arm swing progress counters and animation progress
1401
     */
1402
    protected void updateArmSwingProgress()
1403
    {
1404
        int i = this.getArmSwingAnimationEnd();
1405
1406
        if (this.isSwingInProgress)
1407
        {
1408
            ++this.swingProgressInt;
1409
1410
            if (this.swingProgressInt >= i)
1411
            {
1412
                this.swingProgressInt = 0;
1413
                this.isSwingInProgress = false;
1414
            }
1415
        }
1416
        else
1417
        {
1418
            this.swingProgressInt = 0;
1419
        }
1420
1421
        this.swingProgress = (float)this.swingProgressInt / (float)i;
1422
    }
1423
1424
    public IAttributeInstance getEntityAttribute(IAttribute attribute)
1425
    {
1426
        return this.getAttributeMap().getAttributeInstance(attribute);
1427
    }
1428
1429
    public BaseAttributeMap getAttributeMap()
1430
    {
1431
        if (this.attributeMap == null)
1432
        {
1433
            this.attributeMap = new ServersideAttributeMap();
1434
        }
1435
1436
        return this.attributeMap;
1437
    }
1438
1439
    /**
1440
     * Get this Entity's EnumCreatureAttribute
1441
     */
1442
    public EnumCreatureAttribute getCreatureAttribute()
1443
    {
1444
        return EnumCreatureAttribute.UNDEFINED;
1445
    }
1446
1447
    /**
1448
     * Returns the item that this EntityLiving is holding, if any.
1449
     */
1450
    public abstract ItemStack getHeldItem();
1451
1452
    /**
1453
     * 0: Tool in Hand; 1-4: Armor
1454
     */
1455
    public abstract ItemStack getEquipmentInSlot(int slotIn);
1456
1457
    public abstract ItemStack getCurrentArmor(int slotIn);
1458
1459
    /**
1460
     * Sets the held item, or an armor slot. Slot 0 is held item. Slot 1-4 is armor. Params: Item, slot
1461
     */
1462
    public abstract void setCurrentItemOrArmor(int slotIn, ItemStack stack);
1463
1464
    /**
1465
     * Set sprinting switch for Entity.
1466
     */
1467
    public void setSprinting(boolean sprinting)
1468
    {
1469
        super.setSprinting(sprinting);
1470
        IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
1471
1472
        if (iattributeinstance.getModifier(sprintingSpeedBoostModifierUUID) != null)
1473
        {
1474
            iattributeinstance.removeModifier(sprintingSpeedBoostModifier);
1475
        }
1476
1477
        if (sprinting)
1478
        {
1479
            iattributeinstance.applyModifier(sprintingSpeedBoostModifier);
1480
        }
1481
    }
1482
1483
    /**
1484
     * returns the inventory of this entity (only used in EntityPlayerMP it seems)
1485
     */
1486
    public abstract ItemStack[] getInventory();
1487
1488
    /**
1489
     * Returns the volume for the sounds this mob makes.
1490
     */
1491
    protected float getSoundVolume()
1492
    {
1493
        return 1.0F;
1494
    }
1495
1496
    /**
1497
     * Gets the pitch of living sounds in living entities.
1498
     */
1499
    protected float getSoundPitch()
1500
    {
1501
        return this.isChild() ? (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.5F : (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F;
1502
    }
1503
1504
    /**
1505
     * Dead and sleeping entities cannot move
1506
     */
1507
    protected boolean isMovementBlocked()
1508
    {
1509
        return this.getHealth() <= 0.0F;
1510
    }
1511
1512
    /**
1513
     * Moves the entity to a position out of the way of its mount.
1514
     */
1515
    public void dismountEntity(Entity entityIn)
1516
    {
1517
        double d0 = entityIn.posX;
1518
        double d1 = entityIn.getEntityBoundingBox().minY + (double)entityIn.height;
1519
        double d2 = entityIn.posZ;
1520
        int i = 1;
1521
1522
        for (int j = -i; j <= i; ++j)
1523
        {
1524
            for (int k = -i; k < i; ++k)
1525
            {
1526
                if (j != 0 || k != 0)
1527
                {
1528
                    int l = (int)(this.posX + (double)j);
1529
                    int i1 = (int)(this.posZ + (double)k);
1530
                    AxisAlignedBB axisalignedbb = this.getEntityBoundingBox().offset((double)j, 1.0D, (double)k);
1531
1532
                    if (this.worldObj.getCollisionBoxes(axisalignedbb).isEmpty())
1533
                    {
1534
                        if (World.doesBlockHaveSolidTopSurface(this.worldObj, new BlockPos(l, (int)this.posY, i1)))
1535
                        {
1536
                            this.setPositionAndUpdate(this.posX + (double)j, this.posY + 1.0D, this.posZ + (double)k);
1537
                            return;
1538
                        }
1539
1540
                        if (World.doesBlockHaveSolidTopSurface(this.worldObj, new BlockPos(l, (int)this.posY - 1, i1)) || this.worldObj.getBlockState(new BlockPos(l, (int)this.posY - 1, i1)).getBlock().getMaterial() == Material.water)
1541
                        {
1542
                            d0 = this.posX + (double)j;
1543
                            d1 = this.posY + 1.0D;
1544
                            d2 = this.posZ + (double)k;
1545
                        }
1546
                    }
1547
                }
1548
            }
1549
        }
1550
1551
        this.setPositionAndUpdate(d0, d1, d2);
1552
    }
1553
1554
    public boolean getAlwaysRenderNameTagForRender()
1555
    {
1556
        return false;
1557
    }
1558
1559
    protected float getJumpUpwardsMotion()
1560
    {
1561
        return 0.42F;
1562
    }
1563
1564
    /**
1565
     * Causes this entity to do an upwards motion (jumping).
1566
     */
1567
    protected void jump()
1568
    {
1569
        this.motionY = (double)this.getJumpUpwardsMotion();
1570
1571
        if (this.isPotionActive(Potion.jump))
1572
        {
1573
            this.motionY += (double)((float)(this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
1574
        }
1575
1576
        if (this.isSprinting())
1577
        {
1578
            float f = this.rotationYaw * 0.017453292F;
1579
            this.motionX -= (double)(MathHelper.sin(f) * 0.2F);
1580
            this.motionZ += (double)(MathHelper.cos(f) * 0.2F);
1581
        }
1582
1583
        this.isAirBorne = true;
1584
    }
1585
1586
    /**
1587
     * main AI tick function, replaces updateEntityActionState
1588
     */
1589
    protected void updateAITick()
1590
    {
1591
        this.motionY += 0.03999999910593033D;
1592
    }
1593
1594
    protected void handleJumpLava()
1595
    {
1596
        this.motionY += 0.03999999910593033D;
1597
    }
1598
1599
    /**
1600
     * Moves the entity based on the specified heading.  Args: strafe, forward
1601
     */
1602
    public void moveEntityWithHeading(float strafe, float forward)
1603
    {
1604
        if (this.isServerWorld())
1605
        {
1606
            if (!this.isInWater() || this instanceof EntityPlayer && ((EntityPlayer)this).capabilities.isFlying)
1607
            {
1608
                if (!this.isInLava() || this instanceof EntityPlayer && ((EntityPlayer)this).capabilities.isFlying)
1609
                {
1610
                    float f4 = 0.91F;
1611
1612
                    if (this.onGround)
1613
                    {
1614
                        f4 = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.getEntityBoundingBox().minY) - 1, MathHelper.floor_double(this.posZ))).getBlock().slipperiness * 0.91F;
1615
                    }
1616
1617
                    float f = 0.16277136F / (f4 * f4 * f4);
1618
                    float f5;
1619
1620
                    if (this.onGround)
1621
                    {
1622
                        f5 = this.getAIMoveSpeed() * f;
1623
                    }
1624
                    else
1625
                    {
1626
                        f5 = this.jumpMovementFactor;
1627
                    }
1628
1629
                    this.moveFlying(strafe, forward, f5);
1630
                    f4 = 0.91F;
1631
1632
                    if (this.onGround)
1633
                    {
1634
                        f4 = this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.getEntityBoundingBox().minY) - 1, MathHelper.floor_double(this.posZ))).getBlock().slipperiness * 0.91F;
1635
                    }
1636
1637
                    if (this.isOnLadder())
1638
                    {
1639
                        float f6 = 0.15F;
1640
                        this.motionX = MathHelper.clamp_double(this.motionX, (double)(-f6), (double)f6);
1641
                        this.motionZ = MathHelper.clamp_double(this.motionZ, (double)(-f6), (double)f6);
1642
                        this.fallDistance = 0.0F;
1643
1644
                        if (this.motionY < -0.15D)
1645
                        {
1646
                            this.motionY = -0.15D;
1647
                        }
1648
1649
                        boolean flag = this.isSneaking() && this instanceof EntityPlayer;
1650
1651
                        if (flag && this.motionY < 0.0D)
1652
                        {
1653
                            this.motionY = 0.0D;
1654
                        }
1655
                    }
1656
1657
                    this.moveEntity(this.motionX, this.motionY, this.motionZ);
1658
1659
                    if (this.isCollidedHorizontally && this.isOnLadder())
1660
                    {
1661
                        this.motionY = 0.2D;
1662
                    }
1663
1664
                    if (this.worldObj.isRemote && (!this.worldObj.isBlockLoaded(new BlockPos((int)this.posX, 0, (int)this.posZ)) || !this.worldObj.getChunkFromBlockCoords(new BlockPos((int)this.posX, 0, (int)this.posZ)).isLoaded()))
1665
                    {
1666
                        if (this.posY > 0.0D)
1667
                        {
1668
                            this.motionY = -0.1D;
1669
                        }
1670
                        else
1671
                        {
1672
                            this.motionY = 0.0D;
1673
                        }
1674
                    }
1675
                    else
1676
                    {
1677
                        this.motionY -= 0.08D;
1678
                    }
1679
1680
                    this.motionY *= 0.9800000190734863D;
1681
                    this.motionX *= (double)f4;
1682
                    this.motionZ *= (double)f4;
1683
                }
1684
                else
1685
                {
1686
                    double d1 = this.posY;
1687
                    this.moveFlying(strafe, forward, 0.02F);
1688
                    this.moveEntity(this.motionX, this.motionY, this.motionZ);
1689
                    this.motionX *= 0.5D;
1690
                    this.motionY *= 0.5D;
1691
                    this.motionZ *= 0.5D;
1692
                    this.motionY -= 0.02D;
1693
1694
                    if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6000000238418579D - this.posY + d1, this.motionZ))
1695
                    {
1696
                        this.motionY = 0.30000001192092896D;
1697
                    }
1698
                }
1699
            }
1700
            else
1701
            {
1702
                double d0 = this.posY;
1703
                float f1 = 0.8F;
1704
                float f2 = 0.02F;
1705
                float f3 = (float)EnchantmentHelper.getDepthStriderModifier(this);
1706
1707
                if (f3 > 3.0F)
1708
                {
1709
                    f3 = 3.0F;
1710
                }
1711
1712
                if (!this.onGround)
1713
                {
1714
                    f3 *= 0.5F;
1715
                }
1716
1717
                if (f3 > 0.0F)
1718
                {
1719
                    f1 += (0.54600006F - f1) * f3 / 3.0F;
1720
                    f2 += (this.getAIMoveSpeed() * 1.0F - f2) * f3 / 3.0F;
1721
                }
1722
1723
                this.moveFlying(strafe, forward, f2);
1724
                this.moveEntity(this.motionX, this.motionY, this.motionZ);
1725
                this.motionX *= (double)f1;
1726
                this.motionY *= 0.800000011920929D;
1727
                this.motionZ *= (double)f1;
1728
                this.motionY -= 0.02D;
1729
1730
                if (this.isCollidedHorizontally && this.isOffsetPositionInLiquid(this.motionX, this.motionY + 0.6000000238418579D - this.posY + d0, this.motionZ))
1731
                {
1732
                    this.motionY = 0.30000001192092896D;
1733
                }
1734
            }
1735
        }
1736
1737
        this.prevLimbSwingAmount = this.limbSwingAmount;
1738
        double d2 = this.posX - this.prevPosX;
1739
        double d3 = this.posZ - this.prevPosZ;
1740
        float f7 = MathHelper.sqrt_double(d2 * d2 + d3 * d3) * 4.0F;
1741
1742
        if (f7 > 1.0F)
1743
        {
1744
            f7 = 1.0F;
1745
        }
1746
1747
        this.limbSwingAmount += (f7 - this.limbSwingAmount) * 0.4F;
1748
        this.limbSwing += this.limbSwingAmount;
1749
    }
1750
1751
    /**
1752
     * the movespeed used for the new AI system
1753
     */
1754
    public float getAIMoveSpeed()
1755
    {
1756
        return this.landMovementFactor;
1757
    }
1758
1759
    /**
1760
     * set the movespeed used for the new AI system
1761
     */
1762
    public void setAIMoveSpeed(float speedIn)
1763
    {
1764
        this.landMovementFactor = speedIn;
1765
    }
1766
1767
    public boolean attackEntityAsMob(Entity entityIn)
1768
    {
1769
        this.setLastAttacker(entityIn);
1770
        return false;
1771
    }
1772
1773
    /**
1774
     * Returns whether player is sleeping or not
1775
     */
1776
    public boolean isPlayerSleeping()
1777
    {
1778
        return false;
1779
    }
1780
1781
    /**
1782
     * Called to update the entity's position/logic.
1783
     */
1784
    public void onUpdate()
1785
    {
1786
        super.onUpdate();
1787
1788
        if (!this.worldObj.isRemote)
1789
        {
1790
            int i = this.getArrowCountInEntity();
1791
1792
            if (i > 0)
1793
            {
1794
                if (this.arrowHitTimer <= 0)
1795
                {
1796
                    this.arrowHitTimer = 20 * (30 - i);
1797
                }
1798
1799
                --this.arrowHitTimer;
1800
1801
                if (this.arrowHitTimer <= 0)
1802
                {
1803
                    this.setArrowCountInEntity(i - 1);
1804
                }
1805
            }
1806
1807
            for (int j = 0; j < 5; ++j)
1808
            {
1809
                ItemStack itemstack = this.previousEquipment[j];
1810
                ItemStack itemstack1 = this.getEquipmentInSlot(j);
1811
1812
                if (!ItemStack.areItemStacksEqual(itemstack1, itemstack))
1813
                {
1814
                    ((WorldServer)this.worldObj).getEntityTracker().sendToAllTrackingEntity(this, new S04PacketEntityEquipment(this.getEntityId(), j, itemstack1));
1815
1816
                    if (itemstack != null)
1817
                    {
1818
                        this.attributeMap.removeAttributeModifiers(itemstack.getAttributeModifiers());
1819
                    }
1820
1821
                    if (itemstack1 != null)
1822
                    {
1823
                        this.attributeMap.applyAttributeModifiers(itemstack1.getAttributeModifiers());
1824
                    }
1825
1826
                    this.previousEquipment[j] = itemstack1 == null ? null : itemstack1.copy();
1827
                }
1828
            }
1829
1830
            if (this.ticksExisted % 20 == 0)
1831
            {
1832
                this.getCombatTracker().reset();
1833
            }
1834
        }
1835
1836
        this.onLivingUpdate();
1837
        double d0 = this.posX - this.prevPosX;
1838
        double d1 = this.posZ - this.prevPosZ;
1839
        float f = (float)(d0 * d0 + d1 * d1);
1840
        float f1 = this.renderYawOffset;
1841
        float f2 = 0.0F;
1842
        this.prevOnGroundSpeedFactor = this.onGroundSpeedFactor;
1843
        float f3 = 0.0F;
1844
1845
        if (f > 0.0025000002F)
1846
        {
1847
            f3 = 1.0F;
1848
            f2 = (float)Math.sqrt((double)f) * 3.0F;
1849
            f1 = (float)MathHelper.atan2(d1, d0) * 180.0F / (float)Math.PI - 90.0F;
1850
        }
1851
1852
        if (this.swingProgress > 0.0F)
1853
        {
1854
            f1 = this.rotationYaw;
1855
        }
1856
1857
        if (!this.onGround)
1858
        {
1859
            f3 = 0.0F;
1860
        }
1861
1862
        this.onGroundSpeedFactor += (f3 - this.onGroundSpeedFactor) * 0.3F;
1863
        this.worldObj.theProfiler.startSection("headTurn");
1864
        f2 = this.updateDistance(f1, f2);
1865
        this.worldObj.theProfiler.endSection();
1866
        this.worldObj.theProfiler.startSection("rangeChecks");
1867
1868
        while (this.rotationYaw - this.prevRotationYaw < -180.0F)
1869
        {
1870
            this.prevRotationYaw -= 360.0F;
1871
        }
1872
1873
        while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
1874
        {
1875
            this.prevRotationYaw += 360.0F;
1876
        }
1877
1878
        while (this.renderYawOffset - this.prevRenderYawOffset < -180.0F)
1879
        {
1880
            this.prevRenderYawOffset -= 360.0F;
1881
        }
1882
1883
        while (this.renderYawOffset - this.prevRenderYawOffset >= 180.0F)
1884
        {
1885
            this.prevRenderYawOffset += 360.0F;
1886
        }
1887
1888
        while (this.rotationPitch - this.prevRotationPitch < -180.0F)
1889
        {
1890
            this.prevRotationPitch -= 360.0F;
1891
        }
1892
1893
        while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
1894
        {
1895
            this.prevRotationPitch += 360.0F;
1896
        }
1897
1898
        while (this.rotationYawHead - this.prevRotationYawHead < -180.0F)
1899
        {
1900
            this.prevRotationYawHead -= 360.0F;
1901
        }
1902
1903
        while (this.rotationYawHead - this.prevRotationYawHead >= 180.0F)
1904
        {
1905
            this.prevRotationYawHead += 360.0F;
1906
        }
1907
1908
        this.worldObj.theProfiler.endSection();
1909
        this.movedDistance += f2;
1910
    }
1911
1912
    protected float updateDistance(float p_110146_1_, float p_110146_2_)
1913
    {
1914
        float f = MathHelper.wrapAngleTo180_float(p_110146_1_ - this.renderYawOffset);
1915
        this.renderYawOffset += f * 0.3F;
1916
        float f1 = MathHelper.wrapAngleTo180_float(this.rotationYaw - this.renderYawOffset);
1917
        boolean flag = f1 < -90.0F || f1 >= 90.0F;
1918
1919
        if (f1 < -75.0F)
1920
        {
1921
            f1 = -75.0F;
1922
        }
1923
1924
        if (f1 >= 75.0F)
1925
        {
1926
            f1 = 75.0F;
1927
        }
1928
1929
        this.renderYawOffset = this.rotationYaw - f1;
1930
1931
        if (f1 * f1 > 2500.0F)
1932
        {
1933
            this.renderYawOffset += f1 * 0.2F;
1934
        }
1935
1936
        if (flag)
1937
        {
1938
            p_110146_2_ *= -1.0F;
1939
        }
1940
1941
        return p_110146_2_;
1942
    }
1943
1944
    /**
1945
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
1946
     * use this to react to sunlight and start to burn.
1947
     */
1948
    public void onLivingUpdate()
1949
    {
1950
        if (this.jumpTicks > 0)
1951
        {
1952
            --this.jumpTicks;
1953
        }
1954
1955
        if (this.newPosRotationIncrements > 0)
1956
        {
1957
            double d0 = this.posX + (this.newPosX - this.posX) / (double)this.newPosRotationIncrements;
1958
            double d1 = this.posY + (this.newPosY - this.posY) / (double)this.newPosRotationIncrements;
1959
            double d2 = this.posZ + (this.newPosZ - this.posZ) / (double)this.newPosRotationIncrements;
1960
            double d3 = MathHelper.wrapAngleTo180_double(this.newRotationYaw - (double)this.rotationYaw);
1961
            this.rotationYaw = (float)((double)this.rotationYaw + d3 / (double)this.newPosRotationIncrements);
1962
            this.rotationPitch = (float)((double)this.rotationPitch + (this.newRotationPitch - (double)this.rotationPitch) / (double)this.newPosRotationIncrements);
1963
            --this.newPosRotationIncrements;
1964
            this.setPosition(d0, d1, d2);
1965
            this.setRotation(this.rotationYaw, this.rotationPitch);
1966
        }
1967
        else if (!this.isServerWorld())
1968
        {
1969
            this.motionX *= 0.98D;
1970
            this.motionY *= 0.98D;
1971
            this.motionZ *= 0.98D;
1972
        }
1973
1974
        if (Math.abs(this.motionX) < 0.005D)
1975
        {
1976
            this.motionX = 0.0D;
1977
        }
1978
1979
        if (Math.abs(this.motionY) < 0.005D)
1980
        {
1981
            this.motionY = 0.0D;
1982
        }
1983
1984
        if (Math.abs(this.motionZ) < 0.005D)
1985
        {
1986
            this.motionZ = 0.0D;
1987
        }
1988
1989
        this.worldObj.theProfiler.startSection("ai");
1990
1991
        if (this.isMovementBlocked())
1992
        {
1993
            this.isJumping = false;
1994
            this.moveStrafing = 0.0F;
1995
            this.moveForward = 0.0F;
1996
            this.randomYawVelocity = 0.0F;
1997
        }
1998
        else if (this.isServerWorld())
1999
        {
2000
            this.worldObj.theProfiler.startSection("newAi");
2001
            this.updateEntityActionState();
2002
            this.worldObj.theProfiler.endSection();
2003
        }
2004
2005
        this.worldObj.theProfiler.endSection();
2006
        this.worldObj.theProfiler.startSection("jump");
2007
2008
        if (this.isJumping)
2009
        {
2010
            if (this.isInWater())
2011
            {
2012
                this.updateAITick();
2013
            }
2014
            else if (this.isInLava())
2015
            {
2016
                this.handleJumpLava();
2017
            }
2018
            else if (this.onGround && this.jumpTicks == 0)
2019
            {
2020
                this.jump();
2021
                this.jumpTicks = 10;
2022
            }
2023
        }
2024
        else
2025
        {
2026
            this.jumpTicks = 0;
2027
        }
2028
2029
        this.worldObj.theProfiler.endSection();
2030
        this.worldObj.theProfiler.startSection("travel");
2031
        this.moveStrafing *= 0.98F;
2032
        this.moveForward *= 0.98F;
2033
        this.randomYawVelocity *= 0.9F;
2034
        this.moveEntityWithHeading(this.moveStrafing, this.moveForward);
2035
        this.worldObj.theProfiler.endSection();
2036
        this.worldObj.theProfiler.startSection("push");
2037
2038
        if (!this.worldObj.isRemote)
2039
        {
2040
            this.collideWithNearbyEntities();
2041
        }
2042
2043
        this.worldObj.theProfiler.endSection();
2044
    }
2045
2046
    protected void updateEntityActionState()
2047
    {
2048
    }
2049
2050
    protected void collideWithNearbyEntities()
2051
    {
2052
        List<Entity> list = this.worldObj.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().expand(0.20000000298023224D, 0.0D, 0.20000000298023224D), Predicates.<Entity> and (EntitySelectors.NOT_SPECTATING, new Predicate<Entity>()
2053
        {
2054
            public boolean apply(Entity p_apply_1_)
2055
            {
2056
                return p_apply_1_.canBePushed();
2057
            }
2058
        }));
2059
2060
        if (!list.isEmpty())
2061
        {
2062
            for (int i = 0; i < list.size(); ++i)
2063
            {
2064
                Entity entity = (Entity)list.get(i);
2065
                this.collideWithEntity(entity);
2066
            }
2067
        }
2068
    }
2069
2070
    protected void collideWithEntity(Entity entityIn)
2071
    {
2072
        entityIn.applyEntityCollision(this);
2073
    }
2074
2075
    /**
2076
     * Called when a player mounts an entity. e.g. mounts a pig, mounts a boat.
2077
     */
2078
    public void mountEntity(Entity entityIn)
2079
    {
2080
        if (this.ridingEntity != null && entityIn == null)
2081
        {
2082
            if (!this.worldObj.isRemote)
2083
            {
2084
                this.dismountEntity(this.ridingEntity);
2085
            }
2086
2087
            if (this.ridingEntity != null)
2088
            {
2089
                this.ridingEntity.riddenByEntity = null;
2090
            }
2091
2092
            this.ridingEntity = null;
2093
        }
2094
        else
2095
        {
2096
            super.mountEntity(entityIn);
2097
        }
2098
    }
2099
2100
    /**
2101
     * Handles updating while being ridden by an entity
2102
     */
2103
    public void updateRidden()
2104
    {
2105
        super.updateRidden();
2106
        this.prevOnGroundSpeedFactor = this.onGroundSpeedFactor;
2107
        this.onGroundSpeedFactor = 0.0F;
2108
        this.fallDistance = 0.0F;
2109
    }
2110
2111
    public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean p_180426_10_)
2112
    {
2113
        this.newPosX = x;
2114
        this.newPosY = y;
2115
        this.newPosZ = z;
2116
        this.newRotationYaw = (double)yaw;
2117
        this.newRotationPitch = (double)pitch;
2118
        this.newPosRotationIncrements = posRotationIncrements;
2119
    }
2120
2121
    public void setJumping(boolean jumping)
2122
    {
2123
        this.isJumping = jumping;
2124
    }
2125
2126
    /**
2127
     * Called whenever an item is picked up from walking over it. Args: pickedUpEntity, stackSize
2128
     */
2129
    public void onItemPickup(Entity p_71001_1_, int p_71001_2_)
2130
    {
2131
        if (!p_71001_1_.isDead && !this.worldObj.isRemote)
2132
        {
2133
            EntityTracker entitytracker = ((WorldServer)this.worldObj).getEntityTracker();
2134
2135
            if (p_71001_1_ instanceof EntityItem)
2136
            {
2137
                entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
2138
            }
2139
2140
            if (p_71001_1_ instanceof EntityArrow)
2141
            {
2142
                entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
2143
            }
2144
2145
            if (p_71001_1_ instanceof EntityXPOrb)
2146
            {
2147
                entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
2148
            }
2149
        }
2150
    }
2151
2152
    /**
2153
     * returns true if the entity provided in the argument can be seen. (Raytrace)
2154
     */
2155
    public boolean canEntityBeSeen(Entity entityIn)
2156
    {
2157
        return this.worldObj.rayTraceBlocks(new Vec3(this.posX, this.posY + (double)this.getEyeHeight(), this.posZ), new Vec3(entityIn.posX, entityIn.posY + (double)entityIn.getEyeHeight(), entityIn.posZ)) == null;
2158
    }
2159
2160
    /**
2161
     * returns a (normalized) vector of where this entity is looking
2162
     */
2163
    public Vec3 getLookVec()
2164
    {
2165
        return this.getLook(1.0F);
2166
    }
2167
2168
    /**
2169
     * interpolated look vector
2170
     */
2171
    public Vec3 getLook(float partialTicks)
2172
    {
2173
        if (partialTicks == 1.0F)
2174
        {
2175
            return this.getVectorForRotation(this.rotationPitch, this.rotationYawHead);
2176
        }
2177
        else
2178
        {
2179
            float f = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * partialTicks;
2180
            float f1 = this.prevRotationYawHead + (this.rotationYawHead - this.prevRotationYawHead) * partialTicks;
2181
            return this.getVectorForRotation(f, f1);
2182
        }
2183
    }
2184
2185
    /**
2186
     * Returns where in the swing animation the living entity is (from 0 to 1).  Args: partialTickTime
2187
     */
2188
    public float getSwingProgress(float partialTickTime)
2189
    {
2190
        float f = this.swingProgress - this.prevSwingProgress;
2191
2192
        if (f < 0.0F)
2193
        {
2194
            ++f;
2195
        }
2196
2197
        return this.prevSwingProgress + f * partialTickTime;
2198
    }
2199
2200
    /**
2201
     * Returns whether the entity is in a server world
2202
     */
2203
    public boolean isServerWorld()
2204
    {
2205
        return !this.worldObj.isRemote;
2206
    }
2207
2208
    /**
2209
     * Returns true if other Entities should be prevented from moving through this Entity.
2210
     */
2211
    public boolean canBeCollidedWith()
2212
    {
2213
        return !this.isDead;
2214
    }
2215
2216
    /**
2217
     * Returns true if this entity should push and be pushed by other entities when colliding.
2218
     */
2219
    public boolean canBePushed()
2220
    {
2221
        return !this.isDead;
2222
    }
2223
2224
    /**
2225
     * Sets that this entity has been attacked.
2226
     */
2227
    protected void setBeenAttacked()
2228
    {
2229
        this.velocityChanged = this.rand.nextDouble() >= this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).getAttributeValue();
2230
    }
2231
2232
    public float getRotationYawHead()
2233
    {
2234
        return this.rotationYawHead;
2235
    }
2236
2237
    /**
2238
     * Sets the head's yaw rotation of the entity.
2239
     */
2240
    public void setRotationYawHead(float rotation)
2241
    {
2242
        this.rotationYawHead = rotation;
2243
    }
2244
2245
    /**
2246
     * Set the render yaw offset
2247
     *  
2248
     * @param offset The render yaw offset
2249
     */
2250
    public void setRenderYawOffset(float offset)
2251
    {
2252
        this.renderYawOffset = offset;
2253
    }
2254
2255
    public float getAbsorptionAmount()
2256
    {
2257
        return this.absorptionAmount;
2258
    }
2259
2260
    public void setAbsorptionAmount(float amount)
2261
    {
2262
        if (amount < 0.0F)
2263
        {
2264
            amount = 0.0F;
2265
        }
2266
2267
        this.absorptionAmount = amount;
2268
    }
2269
2270
    public Team getTeam()
2271
    {
2272
        return this.worldObj.getScoreboard().getPlayersTeam(this.getUniqueID().toString());
2273
    }
2274
2275
    public boolean isOnSameTeam(EntityLivingBase otherEntity)
2276
    {
2277
        return this.isOnTeam(otherEntity.getTeam());
2278
    }
2279
2280
    /**
2281
     * Returns true if the entity is on a specific team.
2282
     */
2283
    public boolean isOnTeam(Team teamIn)
2284
    {
2285
        return this.getTeam() != null ? this.getTeam().isSameTeam(teamIn) : false;
2286
    }
2287
2288
    /**
2289
     * Sends an ENTER_COMBAT packet to the client
2290
     */
2291
    public void sendEnterCombat()
2292
    {
2293
    }
2294
2295
    /**
2296
     * Sends an END_COMBAT packet to the client
2297
     */
2298
    public void sendEndCombat()
2299
    {
2300
    }
2301
2302
    protected void markPotionsDirty()
2303
    {
2304
        this.potionsNeedUpdate = true;
2305
    }
2306
}

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