EntityPlayerSP

Client player entity: emits C03 movement, C0A swings, C0B actions and C0C input every tick from onUpdateWalkingPlayer.

net/minecraft/client/entity/EntityPlayerSP.java

Updated 2026-09-12

Deep Analysis

Client-side local player (extends AbstractClientPlayer). Predicts movement, health, input each tick. Tick flow: onUpdate (riding vs walk) -> onUpdateWalkingPlayer + onLivingUpdate (sprint, fly, portal). Bridges Minecraft, MovementInput and NetHandlerPlayClient sendQueue for all C packets.

Key Methods in Depth (9)

onUpdate

Per-tick client update; delegates to walk or riding branch.

onUpdate runs every client tick for the local player and first gates on worldObj.isBlockLoaded at BlockPos(posX, 0, posZ) so no packets are sent from unloaded areas. It calls super.onUpdate first to run entity physics, collision, and position integration before any networking decision. If isRiding is true it takes the vehicle branch and does not call onUpdateWalkingPlayer at all. In the riding branch it queues a C03 C05PacketPlayerLook with current rotationYaw, rotationPitch and onGround every tick because the server drives vehicle position. It also queues a C0CPacketInput with moveStrafing, moveForward, movementInput.jump and movementInput.sneak so the server can steer the ridden horse, boat, pig or minecart. If not riding it delegates to onUpdateWalkingPlayer which owns the on-foot C03 family and C0B throttling. This split prevents double-sending position while riding and explains why ground-spoof and blink cheats hook the on-foot path. The receiver NetHandlerPlayServer validates look and input and applies them to the riding entity rather than the player.

    public void onUpdate()
    {
        if (this.worldObj.isBlockLoaded(new BlockPos(this.posX, 0.0D, this.posZ)))
        {
            super.onUpdate();

            if (this.isRiding())
            {
                this.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(this.rotationYaw, this.rotationPitch, this.onGround));
                this.sendQueue.addToSendQueue(new C0CPacketInput(this.moveStrafing, this.moveForward, this.movementInput.jump, this.movementInput.sneak));
            }
            else
            {
                this.onUpdateWalkingPlayer();
            }
        }
    }

The isBlockLoaded guard stops updates when the player column is unloaded, preventing desync packets from void or unloaded chunks. super.onUpdate runs shared EntityLivingBase physics before networking so sent values reflect the new tick. The isRiding branch constructs C05PacketPlayerLook from live yaw, pitch and onGround, telling the server where the rider looks while the vehicle moves. The next line constructs C0CPacketInput from strafe, forward, jump and sneak, which is the only channel for steering ridden entities. The else calls onUpdateWalkingPlayer for the on-foot C03 and C0B logic, so suppressing either queue call creates a blink-like stall that the server later corrects.

onUpdateWalkingPlayer

Sends sprint/sneak deltas and throttled position/look updates.

onUpdateWalkingPlayer compares live isSprinting against cached serverSprintState and live isSneaking against serverSneakState, sending C0BPacketEntityAction START or STOP only on a flip to save bandwidth. It then gates all position traffic on isCurrentViewEntity so only the camera entity transmits, ignoring other render-view switches. It computes d0, d1 from posX and boundingBox.minY minus lastReported, d2 from posZ, and d3, d4 from yaw and pitch deltas. It sets flag2 when squared positional delta exceeds 9.0E-4D or positionUpdateTicks reaches 20, forcing a keep-alive at least once per second. It sets flag3 when yaw or pitch changed at all, then picks C06 pos-look when both moved, C04 position when only moved, C05 look when only rotated, else bare C03 onGround keep-alive. When ridingEntity is non-null it sends a special C06 with motionX, -999.0D Y and motionZ as a stall marker and forces flag2 false. Finally it increments positionUpdateTicks, and on flag2 or flag3 copies current pos and angles into lastReported fields and zeroes the tick counter, which is the state blink freezes.

        if (this.isCurrentViewEntity())
        {
            double d0 = this.posX - this.lastReportedPosX;
            double d1 = this.getEntityBoundingBox().minY - this.lastReportedPosY;
            double d2 = this.posZ - this.lastReportedPosZ;
            double d3 = (double)(this.rotationYaw - this.lastReportedYaw);
            double d4 = (double)(this.rotationPitch - this.lastReportedPitch);
            boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
            boolean flag3 = d3 != 0.0D || d4 != 0.0D;

            if (this.ridingEntity == null)
            {
                if (flag2 && flag3)
                {
                    this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.rotationYaw, this.rotationPitch, this.onGround));
                }
                else if (flag2)
                {
                    this.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround));
                }
                else if (flag3)
                {
                    this.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(this.rotationYaw, this.rotationPitch, this.onGround));
                }
                else
                {
                    this.sendQueue.addToSendQueue(new C03PacketPlayer(this.onGround));
                }
            }
            else
            {
                this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.motionX, -999.0D, this.motionZ, this.rotationYaw, this.rotationPitch, this.onGround));

The d0 through d4 lines snapshot how far position and look drifted since the last transmitted report, using boundingBox.minY for the feet Y the server validates. flag2 applies the 9.0E-4D squared-distance threshold plus the 20-tick forced update, which is why standing still still sends a bare C03 once per second. flag3 fires on any yaw or pitch delta, separating look-only C05 traffic from movement. The four-way if chain maps the two booleans to C06, C04, C05 or base C03, each carrying the onGround boolean the server uses for fall damage, so spoofing that bit is ground-spoof. The riding branch with -999.0D Y signals the server not to apply on-foot movement, and freezing these queues while continuing to render locally is exactly a blink exploit.

onLivingUpdate

Handles sprint timers, fly toggle, horse jump, portal, push-out.

onLivingUpdate runs before physics each tick and first decrements sprintingTicksLeft, sprintToggleTimer and timeUntilPortal so sprint expiry, double-tap windows and portal cooldowns age correctly. It handles double-tap-W sprint by setting sprintToggleTimer to 7 on first tap and calling setSprinting true on second tap within the window, gated on food above 6, allowFlying, onGround and not using an item or blinded. It handles the sprint key, sprint cancel on slowdown or collision, and slows movementInput by 0.2 while using an item. For flight it forces isFlying true in spectator mode with a C13 send, and detects double-space via flyToggleTimer 7 to toggle capabilities.isFlying and call sendPlayerAbilities which emits C13PacketPlayerAbilities. It manages horse jump charging with horseJumpPowerCounter from -10 through 10, sending C0B RIDING_JUMP on release and computing power up to 0.8 plus curve, plus horse inventory via C0B OPEN_INVENTORY. On landing while flying in non-spectator it clears isFlying and re-sends C13, and it accumulates timeInPortal toward 1.0 for dimension travel. The server NetHandlerPlayServer re-validates abilities and jump power, so forged C13 or C0B values are the classic fly and horse-jump cheat vectors.

        if (this.capabilities.allowFlying)
        {
            if (this.mc.playerController.isSpectatorMode())
            {
                if (!this.capabilities.isFlying)
                {
                    this.capabilities.isFlying = true;
                    this.sendPlayerAbilities();
                }
            }
            else if (!flag && this.movementInput.jump)
            {
                if (this.flyToggleTimer == 0)
                {
                    this.flyToggleTimer = 7;
                }
                else
                {
                    this.capabilities.isFlying = !this.capabilities.isFlying;
                    this.sendPlayerAbilities();
                    this.flyToggleTimer = 0;
                }
            }
        }

        if (this.capabilities.isFlying && this.isCurrentViewEntity())
        {
            if (this.movementInput.sneak)
            {
                this.motionY -= (double)(this.capabilities.getFlySpeed() * 3.0F);
            }

The allowFlying outer gate ensures only creative or spectator clients can enter the toggle logic, otherwise no C13 is produced here. The spectator inner branch forces isFlying true and calls sendPlayerAbilities, which queues C13 with the full capabilities object for server approval. The double-space detector uses flyToggleTimer 7 ticks to distinguish a tap from a hold, flipping isFlying and re-sending C13 on the second press. The isFlying plus isCurrentViewEntity block then applies flySpeed vertical motion locally, so a forged C13 that enables flying without permission lets the client move vertically until the server corrects it.

sendChatMessage

Forwards user chat to server.

sendChatMessage takes the raw string from the chat GUI or command line with no client-side filtering, length splitting or command parsing. It wraps the string verbatim in a new C01PacketChatMessage and adds it to sendQueue via addToSendQueue for TCP flush. It does not distinguish slash commands from public chat, leaving that decision to NetHandlerPlayServer on the receiving side. The server then routes slash-prefixed text to the command dispatcher and other text to broadcast with spam and visibility checks. Because the client sends the full string, server plugins see the exact typed content including formatting codes. Dropping or mutating this packet silences the player, while flooding it is chat spam. No other packet is emitted here, so chat has no movement or inventory side effects.

    public void sendChatMessage(String message)
    {
        this.sendQueue.addToSendQueue(new C01PacketChatMessage(message));
    }

    /**
     * Swings the item the player is holding.
     */
    public void swingItem()
    {
        super.swingItem();
        this.sendQueue.addToSendQueue(new C0APacketAnimation());
    }

    public void respawnPlayer()
    {
        this.sendQueue.addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.PERFORM_RESPAWN));
    }

The single addToSendQueue line shows the entire method body, constructing C01PacketChatMessage directly from the message argument with no rewrite. sendQueue is the NetHandlerPlayClient channel to the server, so the text leaves the client in one TCP packet. The neighboring swingItem and respawnPlayer snippets show the same one-line queue pattern for C0A and C16, confirming this class delegates all authority to the server. If this C01 is blocked the server never sees chat, and if forged at high rate the server throttle or kick applies.

swingItem

Local arm swing plus server animation notify.

swingItem first calls super.swingItem to run the client-side arm swing timer and render animation immediately without waiting for the server. It then constructs an empty C0APacketAnimation with no entity ID or hand argument, because 1.8.9 has a single swing type inferred from the sender. It queues that packet on sendQueue so the server and then other clients via S0B animation can mirror the motion. It is called for attacks, block hits and item use visuals, decoupling visual feedback from damage outcome. The server uses the C0A arrival time as a heuristic alongside C02 attack and C07 dig packets for anti-cheat timing. Suppressing C0A while still attacking creates silent swings that look like no-animation kill-aura. The receiver NetHandlerPlayServer broadcasts the swing to trackers without changing inventory or health.

    public void swingItem()
    {
        super.swingItem();
        this.sendQueue.addToSendQueue(new C0APacketAnimation());
    }

    public void respawnPlayer()
    {
        this.sendQueue.addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.PERFORM_RESPAWN));
    }

    /**
     * Deals damage to the entity. If its a EntityPlayer then will take damage from the armor first and then health
     * second with the reduced value. Args: damageAmount
     */

super.swingItem starts the local swingTimer and arm render so the player sees instant feedback before any round trip. The new C0APacketAnimation line carries no fields, the server attributes it to the sending NetHandlerPlayServer connection. addToSendQueue flushes it to the server where it fans out as S0B animation to nearby trackers. Deleting this line keeps local visuals but hides swings from others, a common silent-aim artifact, while spamming it has no damage effect without a paired C02.

dropOneItem

Requests server item drop; no client spawn.

dropOneItem maps the boolean dropAll from the Q key handler to a C07PacketPlayerDigging Action enum, choosing DROP_ALL_ITEMS when true and DROP_ITEM for a single item. It constructs the packet with BlockPos.ORIGIN and EnumFacing.DOWN as dummy position and facing values because drops carry no block target. It queues the packet on sendQueue and returns null without spawning any EntityItem client-side, keeping inventory authoritative. The server NetHandlerPlayServer interprets the action, splits or clears the held stack, and spawns the EntityItem itself with pickup delay. Holding Ctrl-Q drives the dropAll path to empty the stack, while tapping Q drops one. Forging this C07 with modified actions is how drop-spam or inventory-desync exploits attempt to duplicate items, but the server re-validates the held stack. No S packet is produced locally here.

    /**
     * Called when player presses the drop item key
     */
    public EntityItem dropOneItem(boolean dropAll)
    {
        C07PacketPlayerDigging.Action c07packetplayerdigging$action = dropAll ? C07PacketPlayerDigging.Action.DROP_ALL_ITEMS : C07PacketPlayerDigging.Action.DROP_ITEM;
        this.sendQueue.addToSendQueue(new C07PacketPlayerDigging(c07packetplayerdigging$action, BlockPos.ORIGIN, EnumFacing.DOWN));
        return null;
    }

    /**
     * Joins the passed in entity item with the world. Args: entityItem
     */
    protected void joinEntityItemWithWorld(EntityItem itemIn)
    {
    }

The ternary line translates the dropAll boolean into the exact C07 Action enum the server switches on, so the packet meaning hinges on that one enum value. The constructor uses BlockPos.ORIGIN and EnumFacing.DOWN as placeholders because the server ignores position for drop actions, unlike dig actions that need a real block. addToSendQueue sends the request without creating an EntityItem, proving drops are server-authoritative. Returning null signals no local entity to the caller, so blocking the packet means nothing drops and replaying it duplicates drop attempts the server must deduplicate.

closeScreen

Notifies server container close.

closeScreen reads openContainer.windowId as the server-assigned container ID so the close refers to the exact chest, furnace or custom GUI. It constructs C0DPacketCloseWindow with that ID and queues it on sendQueue to tell the server the client dismissed the screen. It then calls closeScreenAndDropStack which clears the cursor ItemStack via inventory.setItemStack null, calls super.closeScreen and calls mc.displayGuiScreen null to remove the GUI. The server NetHandlerPlayServer closes its Container on C0D, cancels pending slot transactions and may drop or retain the cursor stack. Sending a wrong windowId desyncs containers and can leave ghost items until the next S2E or S30 resync. This is a pure teardown with no item movement packet, so dupes that race C0E clicks against C0D rely on server ordering here.

    public void closeScreen()
    {
        this.sendQueue.addToSendQueue(new C0DPacketCloseWindow(this.openContainer.windowId));
        this.closeScreenAndDropStack();
    }

    public void closeScreenAndDropStack()
    {
        this.inventory.setItemStack((ItemStack)null);
        super.closeScreen();
        this.mc.displayGuiScreen((GuiScreen)null);
    }

    /**
     * Updates health locally.
     */

The C0DPacketCloseWindow constructor captures openContainer.windowId at call time, binding the close to the currently open container instance. addToSendQueue delivers that ID to the server where NetHandlerPlayServer matches it against its own openContainer. closeScreenAndDropStack then nulls the dragged cursor stack and clears the GuiScreen locally, so visuals close even if the packet is delayed. If the C0D is dropped the server keeps the container open and later forces S2E close, which is why inventory-desync fixes always resync windowId.

sendPlayerAbilities

Syncs capabilities (fly, creative) to server.

sendPlayerAbilities wraps the live this.capabilities object, including isFlying, allowFlying, isCreativeMode, flySpeed and walkSpeed, into a new C13PacketPlayerAbilities. It queues that snapshot on sendQueue with no extra validation, trusting the caller in onLivingUpdate to have flipped the flags correctly for spectator, double-space or landing. It is called when spectator forces flight on, when double-space toggles flight, and when landing clears flight in non-spectator. The server compares the received flags against the authoritative GameType and op state, ignoring or kicking on illegal fly enable. Because the whole capabilities struct is sent, stale walkSpeed or flySpeed values can also leak to the server if mods mutate them. The receiver applies allowed changes and echoes the authoritative state back via S39, so a forged C13 only persists until the next S39 correction.

    /**
     * Sends the player's abilities to the server (if there is one).
     */
    public void sendPlayerAbilities()
    {
        this.sendQueue.addToSendQueue(new C13PacketPlayerAbilities(this.capabilities));
    }

    /**
     * returns true if this is an EntityPlayerSP, or the logged in player.
     */
    public boolean isUser()
    {
        return true;
    }

    protected void sendHorseJump()
    {
        this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.RIDING_JUMP, (int)(this.getHorseJumpPower() * 100.0F)));
    }

    public void sendHorseInventory()
    {
        this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.OPEN_INVENTORY));
    }

The one-line body constructs C13PacketPlayerAbilities from this.capabilities by reference copy, so every flag and speed at call time goes on the wire. addToSendQueue pushes it through NetHandlerPlayClient to NetHandlerPlayServer, which re-checks allowFlying against gamemode. The adjacent sendHorseJump and sendHorseInventory lines show the C0B RIDING_JUMP with power times 100 and OPEN_INVENTORY pattern, distinguishing ability sync from action packets. Tampering with capabilities before this call is the client fly-speed hack, corrected when the server replies with S39.

respawnPlayer

Requests respawn after death screen.

respawnPlayer is bound to the death-screen respawn button and takes no position or health arguments because the server owns the spawn point. It constructs C16PacketClientStatus with EnumState.PERFORM_RESPAWN, the dedicated respawn enum distinct from OPEN_INVENTORY statistics states. It queues that packet on sendQueue so NetHandlerPlayServer can trigger ServerConfigurationManager respawn, clearing death, resetting health and food, and teleporting to spawn or bed. The client does not move itself or heal locally here, waiting for S07 respawn, S06 health and S21 chunk packets to rebuild state. Pressing the button twice queues duplicate C16s that the server idempotently ignores if already alive. Blocking this packet leaves the player on the death screen indefinitely, while forging it while alive is ignored by the server state check.

    public void respawnPlayer()
    {
        this.sendQueue.addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.PERFORM_RESPAWN));
    }

    /**
     * Deals damage to the entity. If its a EntityPlayer then will take damage from the armor first and then health
     * second with the reduced value. Args: damageAmount
     */
    protected void damageEntity(DamageSource damageSrc, float damageAmount)
    {
        if (!this.isEntityInvulnerable(damageSrc))
        {
            this.setHealth(this.getHealth() - damageAmount);
        }
    }

    /**
     * set current crafting inventory back to the 2x2 square
     */

The constructor argument PERFORM_RESPAWN selects the respawn branch in NetHandlerPlayServer handleClientStatus, not a generic status update. addToSendQueue sends it over the established play channel, so it only works while connected to a server after death. The following damageEntity snippet shows local health subtraction is separate and not invoked here, proving respawn does not heal client-side. The server responds with position, health and inventory resyncs, so dropping C16 strands the client on the death GUI.

Packet Usage

PacketDirTrigger
C01sentUser sends chat via sendChatMessage.
C03sentForced keep-alive every tick when pos/look unchanged; also riding look.
C07sentQ drop key via dropOneItem.
C0AsentArm swing via swingItem.
C0BsentSprint/sneak toggle, horse jump/inventory.
C0CsentRiding input each tick in onUpdate.
C0DsentClosing container screen.
C13sentFly state change in onLivingUpdate.
C16sentRespawn button via respawnPlayer.

Internal State

sendQueueNetHandlerPlayClient used for all addToSendQueue C packets
lastReportedPosX/Y/Z + Yaw/PitchLast sent transform; delta vs 9.0E-4 threshold picks packet type
positionUpdateTicksForces C03 at least every 20 ticks when idle
serverSprintState/serverSneakStateCaches last C0B state to send only on change
movementInputKeyboard input driving moveStrafe/Forward/jump/sneak
sprintToggleTimer/sprintingTicksLeftDouble-tap sprint window and sprint expiry timer

Related Vanilla Internals

Full Source

EntityPlayerSP.java910 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.entity;
2
3
import net.minecraft.client.Minecraft;
4
import net.minecraft.client.audio.MovingSoundMinecartRiding;
5
import net.minecraft.client.audio.PositionedSoundRecord;
6
import net.minecraft.client.gui.GuiCommandBlock;
7
import net.minecraft.client.gui.GuiEnchantment;
8
import net.minecraft.client.gui.GuiHopper;
9
import net.minecraft.client.gui.GuiMerchant;
10
import net.minecraft.client.gui.GuiRepair;
11
import net.minecraft.client.gui.GuiScreen;
12
import net.minecraft.client.gui.GuiScreenBook;
13
import net.minecraft.client.gui.inventory.GuiBeacon;
14
import net.minecraft.client.gui.inventory.GuiBrewingStand;
15
import net.minecraft.client.gui.inventory.GuiChest;
16
import net.minecraft.client.gui.inventory.GuiCrafting;
17
import net.minecraft.client.gui.inventory.GuiDispenser;
18
import net.minecraft.client.gui.inventory.GuiEditSign;
19
import net.minecraft.client.gui.inventory.GuiFurnace;
20
import net.minecraft.client.gui.inventory.GuiScreenHorseInventory;
21
import net.minecraft.client.network.NetHandlerPlayClient;
22
import net.minecraft.command.server.CommandBlockLogic;
23
import net.minecraft.entity.Entity;
24
import net.minecraft.entity.IMerchant;
25
import net.minecraft.entity.item.EntityItem;
26
import net.minecraft.entity.item.EntityMinecart;
27
import net.minecraft.entity.passive.EntityHorse;
28
import net.minecraft.init.Items;
29
import net.minecraft.inventory.IInventory;
30
import net.minecraft.item.Item;
31
import net.minecraft.item.ItemStack;
32
import net.minecraft.network.play.client.C01PacketChatMessage;
33
import net.minecraft.network.play.client.C03PacketPlayer;
34
import net.minecraft.network.play.client.C07PacketPlayerDigging;
35
import net.minecraft.network.play.client.C0APacketAnimation;
36
import net.minecraft.network.play.client.C0BPacketEntityAction;
37
import net.minecraft.network.play.client.C0CPacketInput;
38
import net.minecraft.network.play.client.C0DPacketCloseWindow;
39
import net.minecraft.network.play.client.C13PacketPlayerAbilities;
40
import net.minecraft.network.play.client.C16PacketClientStatus;
41
import net.minecraft.potion.Potion;
42
import net.minecraft.stats.StatBase;
43
import net.minecraft.stats.StatFileWriter;
44
import net.minecraft.tileentity.TileEntitySign;
45
import net.minecraft.util.BlockPos;
46
import net.minecraft.util.DamageSource;
47
import net.minecraft.util.EnumFacing;
48
import net.minecraft.util.EnumParticleTypes;
49
import net.minecraft.util.IChatComponent;
50
import net.minecraft.util.MovementInput;
51
import net.minecraft.util.ResourceLocation;
52
import net.minecraft.world.IInteractionObject;
53
import net.minecraft.world.World;
54
55
public class EntityPlayerSP extends AbstractClientPlayer
56
{
57
    public final NetHandlerPlayClient sendQueue;
58
    private final StatFileWriter statWriter;
59
60
    /**
61
     * The last X position which was transmitted to the server, used to determine when the X position changes and needs
62
     * to be re-trasmitted
63
     */
64
    private double lastReportedPosX;
65
66
    /**
67
     * The last Y position which was transmitted to the server, used to determine when the Y position changes and needs
68
     * to be re-transmitted
69
     */
70
    private double lastReportedPosY;
71
72
    /**
73
     * The last Z position which was transmitted to the server, used to determine when the Z position changes and needs
74
     * to be re-transmitted
75
     */
76
    private double lastReportedPosZ;
77
78
    /**
79
     * The last yaw value which was transmitted to the server, used to determine when the yaw changes and needs to be
80
     * re-transmitted
81
     */
82
    private float lastReportedYaw;
83
84
    /**
85
     * The last pitch value which was transmitted to the server, used to determine when the pitch changes and needs to
86
     * be re-transmitted
87
     */
88
    private float lastReportedPitch;
89
90
    /** the last sneaking state sent to the server */
91
    private boolean serverSneakState;
92
93
    /** the last sprinting state sent to the server */
94
    private boolean serverSprintState;
95
96
    /**
97
     * Reset to 0 every time position is sent to the server, used to send periodic updates every 20 ticks even when the
98
     * player is not moving.
99
     */
100
    private int positionUpdateTicks;
101
    private boolean hasValidHealth;
102
    private String clientBrand;
103
    public MovementInput movementInput;
104
    protected Minecraft mc;
105
106
    /**
107
     * Used to tell if the player pressed forward twice. If this is at 0 and it's pressed (And they are allowed to
108
     * sprint, aka enough food on the ground etc) it sets this to 7. If it's pressed and it's greater than 0 enable
109
     * sprinting.
110
     */
111
    protected int sprintToggleTimer;
112
113
    /** Ticks left before sprinting is disabled. */
114
    public int sprintingTicksLeft;
115
    public float renderArmYaw;
116
    public float renderArmPitch;
117
    public float prevRenderArmYaw;
118
    public float prevRenderArmPitch;
119
    private int horseJumpPowerCounter;
120
    private float horseJumpPower;
121
122
    /** The amount of time an entity has been in a Portal */
123
    public float timeInPortal;
124
125
    /** The amount of time an entity has been in a Portal the previous tick */
126
    public float prevTimeInPortal;
127
128
    public EntityPlayerSP(Minecraft mcIn, World worldIn, NetHandlerPlayClient netHandler, StatFileWriter statFile)
129
    {
130
        super(worldIn, netHandler.getGameProfile());
131
        this.sendQueue = netHandler;
132
        this.statWriter = statFile;
133
        this.mc = mcIn;
134
        this.dimension = 0;
135
    }
136
137
    /**
138
     * Called when the entity is attacked.
139
     */
140
    public boolean attackEntityFrom(DamageSource source, float amount)
141
    {
142
        return false;
143
    }
144
145
    /**
146
     * Heal living entity (param: amount of half-hearts)
147
     */
148
    public void heal(float healAmount)
149
    {
150
    }
151
152
    /**
153
     * Called when a player mounts an entity. e.g. mounts a pig, mounts a boat.
154
     */
155
    public void mountEntity(Entity entityIn)
156
    {
157
        super.mountEntity(entityIn);
158
159
        if (entityIn instanceof EntityMinecart)
160
        {
161
            this.mc.getSoundHandler().playSound(new MovingSoundMinecartRiding(this, (EntityMinecart)entityIn));
162
        }
163
    }
164
165
    /**
166
     * Called to update the entity's position/logic.
167
     */
168
    public void onUpdate()
169
    {
170
        if (this.worldObj.isBlockLoaded(new BlockPos(this.posX, 0.0D, this.posZ)))
171
        {
172
            super.onUpdate();
173
174
            if (this.isRiding())
175
            {
176
                this.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(this.rotationYaw, this.rotationPitch, this.onGround));
177
                this.sendQueue.addToSendQueue(new C0CPacketInput(this.moveStrafing, this.moveForward, this.movementInput.jump, this.movementInput.sneak));
178
            }
179
            else
180
            {
181
                this.onUpdateWalkingPlayer();
182
            }
183
        }
184
    }
185
186
    /**
187
     * called every tick when the player is on foot. Performs all the things that normally happen during movement.
188
     */
189
    public void onUpdateWalkingPlayer()
190
    {
191
        boolean flag = this.isSprinting();
192
193
        if (flag != this.serverSprintState)
194
        {
195
            if (flag)
196
            {
197
                this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.START_SPRINTING));
198
            }
199
            else
200
            {
201
                this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.STOP_SPRINTING));
202
            }
203
204
            this.serverSprintState = flag;
205
        }
206
207
        boolean flag1 = this.isSneaking();
208
209
        if (flag1 != this.serverSneakState)
210
        {
211
            if (flag1)
212
            {
213
                this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.START_SNEAKING));
214
            }
215
            else
216
            {
217
                this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.STOP_SNEAKING));
218
            }
219
220
            this.serverSneakState = flag1;
221
        }
222
223
        if (this.isCurrentViewEntity())
224
        {
225
            double d0 = this.posX - this.lastReportedPosX;
226
            double d1 = this.getEntityBoundingBox().minY - this.lastReportedPosY;
227
            double d2 = this.posZ - this.lastReportedPosZ;
228
            double d3 = (double)(this.rotationYaw - this.lastReportedYaw);
229
            double d4 = (double)(this.rotationPitch - this.lastReportedPitch);
230
            boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
231
            boolean flag3 = d3 != 0.0D || d4 != 0.0D;
232
233
            if (this.ridingEntity == null)
234
            {
235
                if (flag2 && flag3)
236
                {
237
                    this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.rotationYaw, this.rotationPitch, this.onGround));
238
                }
239
                else if (flag2)
240
                {
241
                    this.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround));
242
                }
243
                else if (flag3)
244
                {
245
                    this.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(this.rotationYaw, this.rotationPitch, this.onGround));
246
                }
247
                else
248
                {
249
                    this.sendQueue.addToSendQueue(new C03PacketPlayer(this.onGround));
250
                }
251
            }
252
            else
253
            {
254
                this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.motionX, -999.0D, this.motionZ, this.rotationYaw, this.rotationPitch, this.onGround));
255
                flag2 = false;
256
            }
257
258
            ++this.positionUpdateTicks;
259
260
            if (flag2)
261
            {
262
                this.lastReportedPosX = this.posX;
263
                this.lastReportedPosY = this.getEntityBoundingBox().minY;
264
                this.lastReportedPosZ = this.posZ;
265
                this.positionUpdateTicks = 0;
266
            }
267
268
            if (flag3)
269
            {
270
                this.lastReportedYaw = this.rotationYaw;
271
                this.lastReportedPitch = this.rotationPitch;
272
            }
273
        }
274
    }
275
276
    /**
277
     * Called when player presses the drop item key
278
     */
279
    public EntityItem dropOneItem(boolean dropAll)
280
    {
281
        C07PacketPlayerDigging.Action c07packetplayerdigging$action = dropAll ? C07PacketPlayerDigging.Action.DROP_ALL_ITEMS : C07PacketPlayerDigging.Action.DROP_ITEM;
282
        this.sendQueue.addToSendQueue(new C07PacketPlayerDigging(c07packetplayerdigging$action, BlockPos.ORIGIN, EnumFacing.DOWN));
283
        return null;
284
    }
285
286
    /**
287
     * Joins the passed in entity item with the world. Args: entityItem
288
     */
289
    protected void joinEntityItemWithWorld(EntityItem itemIn)
290
    {
291
    }
292
293
    /**
294
     * Sends a chat message from the player. Args: chatMessage
295
     */
296
    public void sendChatMessage(String message)
297
    {
298
        this.sendQueue.addToSendQueue(new C01PacketChatMessage(message));
299
    }
300
301
    /**
302
     * Swings the item the player is holding.
303
     */
304
    public void swingItem()
305
    {
306
        super.swingItem();
307
        this.sendQueue.addToSendQueue(new C0APacketAnimation());
308
    }
309
310
    public void respawnPlayer()
311
    {
312
        this.sendQueue.addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.PERFORM_RESPAWN));
313
    }
314
315
    /**
316
     * Deals damage to the entity. If its a EntityPlayer then will take damage from the armor first and then health
317
     * second with the reduced value. Args: damageAmount
318
     */
319
    protected void damageEntity(DamageSource damageSrc, float damageAmount)
320
    {
321
        if (!this.isEntityInvulnerable(damageSrc))
322
        {
323
            this.setHealth(this.getHealth() - damageAmount);
324
        }
325
    }
326
327
    /**
328
     * set current crafting inventory back to the 2x2 square
329
     */
330
    public void closeScreen()
331
    {
332
        this.sendQueue.addToSendQueue(new C0DPacketCloseWindow(this.openContainer.windowId));
333
        this.closeScreenAndDropStack();
334
    }
335
336
    public void closeScreenAndDropStack()
337
    {
338
        this.inventory.setItemStack((ItemStack)null);
339
        super.closeScreen();
340
        this.mc.displayGuiScreen((GuiScreen)null);
341
    }
342
343
    /**
344
     * Updates health locally.
345
     */
346
    public void setPlayerSPHealth(float health)
347
    {
348
        if (this.hasValidHealth)
349
        {
350
            float f = this.getHealth() - health;
351
352
            if (f <= 0.0F)
353
            {
354
                this.setHealth(health);
355
356
                if (f < 0.0F)
357
                {
358
                    this.hurtResistantTime = this.maxHurtResistantTime / 2;
359
                }
360
            }
361
            else
362
            {
363
                this.lastDamage = f;
364
                this.setHealth(this.getHealth());
365
                this.hurtResistantTime = this.maxHurtResistantTime;
366
                this.damageEntity(DamageSource.generic, f);
367
                this.hurtTime = this.maxHurtTime = 10;
368
            }
369
        }
370
        else
371
        {
372
            this.setHealth(health);
373
            this.hasValidHealth = true;
374
        }
375
    }
376
377
    /**
378
     * Adds a value to a statistic field.
379
     */
380
    public void addStat(StatBase stat, int amount)
381
    {
382
        if (stat != null)
383
        {
384
            if (stat.isIndependent)
385
            {
386
                super.addStat(stat, amount);
387
            }
388
        }
389
    }
390
391
    /**
392
     * Sends the player's abilities to the server (if there is one).
393
     */
394
    public void sendPlayerAbilities()
395
    {
396
        this.sendQueue.addToSendQueue(new C13PacketPlayerAbilities(this.capabilities));
397
    }
398
399
    /**
400
     * returns true if this is an EntityPlayerSP, or the logged in player.
401
     */
402
    public boolean isUser()
403
    {
404
        return true;
405
    }
406
407
    protected void sendHorseJump()
408
    {
409
        this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.RIDING_JUMP, (int)(this.getHorseJumpPower() * 100.0F)));
410
    }
411
412
    public void sendHorseInventory()
413
    {
414
        this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.OPEN_INVENTORY));
415
    }
416
417
    public void setClientBrand(String brand)
418
    {
419
        this.clientBrand = brand;
420
    }
421
422
    public String getClientBrand()
423
    {
424
        return this.clientBrand;
425
    }
426
427
    public StatFileWriter getStatFileWriter()
428
    {
429
        return this.statWriter;
430
    }
431
432
    public void addChatComponentMessage(IChatComponent chatComponent)
433
    {
434
        this.mc.ingameGUI.getChatGUI().printChatMessage(chatComponent);
435
    }
436
437
    protected boolean pushOutOfBlocks(double x, double y, double z)
438
    {
439
        if (this.noClip)
440
        {
441
            return false;
442
        }
443
        else
444
        {
445
            BlockPos blockpos = new BlockPos(x, y, z);
446
            double d0 = x - (double)blockpos.getX();
447
            double d1 = z - (double)blockpos.getZ();
448
449
            if (!this.isOpenBlockSpace(blockpos))
450
            {
451
                int i = -1;
452
                double d2 = 9999.0D;
453
454
                if (this.isOpenBlockSpace(blockpos.west()) && d0 < d2)
455
                {
456
                    d2 = d0;
457
                    i = 0;
458
                }
459
460
                if (this.isOpenBlockSpace(blockpos.east()) && 1.0D - d0 < d2)
461
                {
462
                    d2 = 1.0D - d0;
463
                    i = 1;
464
                }
465
466
                if (this.isOpenBlockSpace(blockpos.north()) && d1 < d2)
467
                {
468
                    d2 = d1;
469
                    i = 4;
470
                }
471
472
                if (this.isOpenBlockSpace(blockpos.south()) && 1.0D - d1 < d2)
473
                {
474
                    d2 = 1.0D - d1;
475
                    i = 5;
476
                }
477
478
                float f = 0.1F;
479
480
                if (i == 0)
481
                {
482
                    this.motionX = (double)(-f);
483
                }
484
485
                if (i == 1)
486
                {
487
                    this.motionX = (double)f;
488
                }
489
490
                if (i == 4)
491
                {
492
                    this.motionZ = (double)(-f);
493
                }
494
495
                if (i == 5)
496
                {
497
                    this.motionZ = (double)f;
498
                }
499
            }
500
501
            return false;
502
        }
503
    }
504
505
    /**
506
     * Returns true if the block at the given BlockPos and the block above it are NOT full cubes.
507
     */
508
    private boolean isOpenBlockSpace(BlockPos pos)
509
    {
510
        return !this.worldObj.getBlockState(pos).getBlock().isNormalCube() && !this.worldObj.getBlockState(pos.up()).getBlock().isNormalCube();
511
    }
512
513
    /**
514
     * Set sprinting switch for Entity.
515
     */
516
    public void setSprinting(boolean sprinting)
517
    {
518
        super.setSprinting(sprinting);
519
        this.sprintingTicksLeft = sprinting ? 600 : 0;
520
    }
521
522
    /**
523
     * Sets the current XP, total XP, and level number.
524
     */
525
    public void setXPStats(float currentXP, int maxXP, int level)
526
    {
527
        this.experience = currentXP;
528
        this.experienceTotal = maxXP;
529
        this.experienceLevel = level;
530
    }
531
532
    /**
533
     * Send a chat message to the CommandSender
534
     */
535
    public void addChatMessage(IChatComponent component)
536
    {
537
        this.mc.ingameGUI.getChatGUI().printChatMessage(component);
538
    }
539
540
    /**
541
     * Returns {@code true} if the CommandSender is allowed to execute the command, {@code false} if not
542
     */
543
    public boolean canCommandSenderUseCommand(int permLevel, String commandName)
544
    {
545
        return permLevel <= 0;
546
    }
547
548
    /**
549
     * Get the position in the world. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return
550
     * the coordinates 0, 0, 0
551
     */
552
    public BlockPos getPosition()
553
    {
554
        return new BlockPos(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D);
555
    }
556
557
    public void playSound(String name, float volume, float pitch)
558
    {
559
        this.worldObj.playSound(this.posX, this.posY, this.posZ, name, volume, pitch, false);
560
    }
561
562
    /**
563
     * Returns whether the entity is in a server world
564
     */
565
    public boolean isServerWorld()
566
    {
567
        return true;
568
    }
569
570
    public boolean isRidingHorse()
571
    {
572
        return this.ridingEntity != null && this.ridingEntity instanceof EntityHorse && ((EntityHorse)this.ridingEntity).isHorseSaddled();
573
    }
574
575
    public float getHorseJumpPower()
576
    {
577
        return this.horseJumpPower;
578
    }
579
580
    public void openEditSign(TileEntitySign signTile)
581
    {
582
        this.mc.displayGuiScreen(new GuiEditSign(signTile));
583
    }
584
585
    public void openEditCommandBlock(CommandBlockLogic cmdBlockLogic)
586
    {
587
        this.mc.displayGuiScreen(new GuiCommandBlock(cmdBlockLogic));
588
    }
589
590
    /**
591
     * Displays the GUI for interacting with a book.
592
     */
593
    public void displayGUIBook(ItemStack bookStack)
594
    {
595
        Item item = bookStack.getItem();
596
597
        if (item == Items.writable_book)
598
        {
599
            this.mc.displayGuiScreen(new GuiScreenBook(this, bookStack, true));
600
        }
601
    }
602
603
    /**
604
     * Displays the GUI for interacting with a chest inventory. Args: chestInventory
605
     */
606
    public void displayGUIChest(IInventory chestInventory)
607
    {
608
        String s = chestInventory instanceof IInteractionObject ? ((IInteractionObject)chestInventory).getGuiID() : "minecraft:container";
609
610
        if ("minecraft:chest".equals(s))
611
        {
612
            this.mc.displayGuiScreen(new GuiChest(this.inventory, chestInventory));
613
        }
614
        else if ("minecraft:hopper".equals(s))
615
        {
616
            this.mc.displayGuiScreen(new GuiHopper(this.inventory, chestInventory));
617
        }
618
        else if ("minecraft:furnace".equals(s))
619
        {
620
            this.mc.displayGuiScreen(new GuiFurnace(this.inventory, chestInventory));
621
        }
622
        else if ("minecraft:brewing_stand".equals(s))
623
        {
624
            this.mc.displayGuiScreen(new GuiBrewingStand(this.inventory, chestInventory));
625
        }
626
        else if ("minecraft:beacon".equals(s))
627
        {
628
            this.mc.displayGuiScreen(new GuiBeacon(this.inventory, chestInventory));
629
        }
630
        else if (!"minecraft:dispenser".equals(s) && !"minecraft:dropper".equals(s))
631
        {
632
            this.mc.displayGuiScreen(new GuiChest(this.inventory, chestInventory));
633
        }
634
        else
635
        {
636
            this.mc.displayGuiScreen(new GuiDispenser(this.inventory, chestInventory));
637
        }
638
    }
639
640
    public void displayGUIHorse(EntityHorse horse, IInventory horseInventory)
641
    {
642
        this.mc.displayGuiScreen(new GuiScreenHorseInventory(this.inventory, horseInventory, horse));
643
    }
644
645
    public void displayGui(IInteractionObject guiOwner)
646
    {
647
        String s = guiOwner.getGuiID();
648
649
        if ("minecraft:crafting_table".equals(s))
650
        {
651
            this.mc.displayGuiScreen(new GuiCrafting(this.inventory, this.worldObj));
652
        }
653
        else if ("minecraft:enchanting_table".equals(s))
654
        {
655
            this.mc.displayGuiScreen(new GuiEnchantment(this.inventory, this.worldObj, guiOwner));
656
        }
657
        else if ("minecraft:anvil".equals(s))
658
        {
659
            this.mc.displayGuiScreen(new GuiRepair(this.inventory, this.worldObj));
660
        }
661
    }
662
663
    public void displayVillagerTradeGui(IMerchant villager)
664
    {
665
        this.mc.displayGuiScreen(new GuiMerchant(this.inventory, villager, this.worldObj));
666
    }
667
668
    /**
669
     * Called when the player performs a critical hit on the Entity. Args: entity that was hit critically
670
     */
671
    public void onCriticalHit(Entity entityHit)
672
    {
673
        this.mc.effectRenderer.emitParticleAtEntity(entityHit, EnumParticleTypes.CRIT);
674
    }
675
676
    public void onEnchantmentCritical(Entity entityHit)
677
    {
678
        this.mc.effectRenderer.emitParticleAtEntity(entityHit, EnumParticleTypes.CRIT_MAGIC);
679
    }
680
681
    /**
682
     * Returns if this entity is sneaking.
683
     */
684
    public boolean isSneaking()
685
    {
686
        boolean flag = this.movementInput != null ? this.movementInput.sneak : false;
687
        return flag && !this.sleeping;
688
    }
689
690
    public void updateEntityActionState()
691
    {
692
        super.updateEntityActionState();
693
694
        if (this.isCurrentViewEntity())
695
        {
696
            this.moveStrafing = this.movementInput.moveStrafe;
697
            this.moveForward = this.movementInput.moveForward;
698
            this.isJumping = this.movementInput.jump;
699
            this.prevRenderArmYaw = this.renderArmYaw;
700
            this.prevRenderArmPitch = this.renderArmPitch;
701
            this.renderArmPitch = (float)((double)this.renderArmPitch + (double)(this.rotationPitch - this.renderArmPitch) * 0.5D);
702
            this.renderArmYaw = (float)((double)this.renderArmYaw + (double)(this.rotationYaw - this.renderArmYaw) * 0.5D);
703
        }
704
    }
705
706
    protected boolean isCurrentViewEntity()
707
    {
708
        return this.mc.getRenderViewEntity() == this;
709
    }
710
711
    /**
712
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
713
     * use this to react to sunlight and start to burn.
714
     */
715
    public void onLivingUpdate()
716
    {
717
        if (this.sprintingTicksLeft > 0)
718
        {
719
            --this.sprintingTicksLeft;
720
721
            if (this.sprintingTicksLeft == 0)
722
            {
723
                this.setSprinting(false);
724
            }
725
        }
726
727
        if (this.sprintToggleTimer > 0)
728
        {
729
            --this.sprintToggleTimer;
730
        }
731
732
        this.prevTimeInPortal = this.timeInPortal;
733
734
        if (this.inPortal)
735
        {
736
            if (this.mc.currentScreen != null && !this.mc.currentScreen.doesGuiPauseGame())
737
            {
738
                this.mc.displayGuiScreen((GuiScreen)null);
739
            }
740
741
            if (this.timeInPortal == 0.0F)
742
            {
743
                this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("portal.trigger"), this.rand.nextFloat() * 0.4F + 0.8F));
744
            }
745
746
            this.timeInPortal += 0.0125F;
747
748
            if (this.timeInPortal >= 1.0F)
749
            {
750
                this.timeInPortal = 1.0F;
751
            }
752
753
            this.inPortal = false;
754
        }
755
        else if (this.isPotionActive(Potion.confusion) && this.getActivePotionEffect(Potion.confusion).getDuration() > 60)
756
        {
757
            this.timeInPortal += 0.006666667F;
758
759
            if (this.timeInPortal > 1.0F)
760
            {
761
                this.timeInPortal = 1.0F;
762
            }
763
        }
764
        else
765
        {
766
            if (this.timeInPortal > 0.0F)
767
            {
768
                this.timeInPortal -= 0.05F;
769
            }
770
771
            if (this.timeInPortal < 0.0F)
772
            {
773
                this.timeInPortal = 0.0F;
774
            }
775
        }
776
777
        if (this.timeUntilPortal > 0)
778
        {
779
            --this.timeUntilPortal;
780
        }
781
782
        boolean flag = this.movementInput.jump;
783
        boolean flag1 = this.movementInput.sneak;
784
        float f = 0.8F;
785
        boolean flag2 = this.movementInput.moveForward >= f;
786
        this.movementInput.updatePlayerMoveState();
787
788
        if (this.isUsingItem() && !this.isRiding())
789
        {
790
            this.movementInput.moveStrafe *= 0.2F;
791
            this.movementInput.moveForward *= 0.2F;
792
            this.sprintToggleTimer = 0;
793
        }
794
795
        this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D);
796
        this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double)this.width * 0.35D);
797
        this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double)this.width * 0.35D);
798
        this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D);
799
        boolean flag3 = (float)this.getFoodStats().getFoodLevel() > 6.0F || this.capabilities.allowFlying;
800
801
        if (this.onGround && !flag1 && !flag2 && this.movementInput.moveForward >= f && !this.isSprinting() && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness))
802
        {
803
            if (this.sprintToggleTimer <= 0 && !this.mc.gameSettings.keyBindSprint.isKeyDown())
804
            {
805
                this.sprintToggleTimer = 7;
806
            }
807
            else
808
            {
809
                this.setSprinting(true);
810
            }
811
        }
812
813
        if (!this.isSprinting() && this.movementInput.moveForward >= f && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness) && this.mc.gameSettings.keyBindSprint.isKeyDown())
814
        {
815
            this.setSprinting(true);
816
        }
817
818
        if (this.isSprinting() && (this.movementInput.moveForward < f || this.isCollidedHorizontally || !flag3))
819
        {
820
            this.setSprinting(false);
821
        }
822
823
        if (this.capabilities.allowFlying)
824
        {
825
            if (this.mc.playerController.isSpectatorMode())
826
            {
827
                if (!this.capabilities.isFlying)
828
                {
829
                    this.capabilities.isFlying = true;
830
                    this.sendPlayerAbilities();
831
                }
832
            }
833
            else if (!flag && this.movementInput.jump)
834
            {
835
                if (this.flyToggleTimer == 0)
836
                {
837
                    this.flyToggleTimer = 7;
838
                }
839
                else
840
                {
841
                    this.capabilities.isFlying = !this.capabilities.isFlying;
842
                    this.sendPlayerAbilities();
843
                    this.flyToggleTimer = 0;
844
                }
845
            }
846
        }
847
848
        if (this.capabilities.isFlying && this.isCurrentViewEntity())
849
        {
850
            if (this.movementInput.sneak)
851
            {
852
                this.motionY -= (double)(this.capabilities.getFlySpeed() * 3.0F);
853
            }
854
855
            if (this.movementInput.jump)
856
            {
857
                this.motionY += (double)(this.capabilities.getFlySpeed() * 3.0F);
858
            }
859
        }
860
861
        if (this.isRidingHorse())
862
        {
863
            if (this.horseJumpPowerCounter < 0)
864
            {
865
                ++this.horseJumpPowerCounter;
866
867
                if (this.horseJumpPowerCounter == 0)
868
                {
869
                    this.horseJumpPower = 0.0F;
870
                }
871
            }
872
873
            if (flag && !this.movementInput.jump)
874
            {
875
                this.horseJumpPowerCounter = -10;
876
                this.sendHorseJump();
877
            }
878
            else if (!flag && this.movementInput.jump)
879
            {
880
                this.horseJumpPowerCounter = 0;
881
                this.horseJumpPower = 0.0F;
882
            }
883
            else if (flag)
884
            {
885
                ++this.horseJumpPowerCounter;
886
887
                if (this.horseJumpPowerCounter < 10)
888
                {
889
                    this.horseJumpPower = (float)this.horseJumpPowerCounter * 0.1F;
890
                }
891
                else
892
                {
893
                    this.horseJumpPower = 0.8F + 2.0F / (float)(this.horseJumpPowerCounter - 9) * 0.1F;
894
                }
895
            }
896
        }
897
        else
898
        {
899
            this.horseJumpPower = 0.0F;
900
        }
901
902
        super.onLivingUpdate();
903
904
        if (this.onGround && this.capabilities.isFlying && !this.mc.playerController.isSpectatorMode())
905
        {
906
            this.capabilities.isFlying = false;
907
            this.sendPlayerAbilities();
908
        }
909
    }
910
}

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