001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import net.minecraft.client.Minecraft;
006    
007    @SideOnly(Side.CLIENT)
008    public class EntityClientPlayerMP extends EntityPlayerSP
009    {
010        public NetClientHandler sendQueue;
011        private double oldPosX;
012    
013        /** Old Minimum Y of the bounding box */
014        private double oldMinY;
015        private double oldPosY;
016        private double oldPosZ;
017        private float oldRotationYaw;
018        private float oldRotationPitch;
019    
020        /** Check if was on ground last update */
021        private boolean wasOnGround = false;
022    
023        /** should the player stop sneaking? */
024        private boolean shouldStopSneaking = false;
025        private boolean wasSneaking = false;
026        private int field_71168_co = 0;
027    
028        /** has the client player's health been set? */
029        private boolean hasSetHealth = false;
030    
031        public EntityClientPlayerMP(Minecraft par1Minecraft, World par2World, Session par3Session, NetClientHandler par4NetClientHandler)
032        {
033            super(par1Minecraft, par2World, par3Session, 0);
034            this.sendQueue = par4NetClientHandler;
035        }
036    
037        /**
038         * Called when the entity is attacked.
039         */
040        public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
041        {
042            return false;
043        }
044    
045        /**
046         * Heal living entity (param: amount of half-hearts)
047         */
048        public void heal(int par1) {}
049    
050        /**
051         * Called to update the entity's position/logic.
052         */
053        public void onUpdate()
054        {
055            if (this.worldObj.blockExists(MathHelper.floor_double(this.posX), 0, MathHelper.floor_double(this.posZ)))
056            {
057                super.onUpdate();
058                this.sendMotionUpdates();
059            }
060        }
061    
062        /**
063         * Send updated motion and position information to the server
064         */
065        public void sendMotionUpdates()
066        {
067            boolean var1 = this.isSprinting();
068    
069            if (var1 != this.wasSneaking)
070            {
071                if (var1)
072                {
073                    this.sendQueue.addToSendQueue(new Packet19EntityAction(this, 4));
074                }
075                else
076                {
077                    this.sendQueue.addToSendQueue(new Packet19EntityAction(this, 5));
078                }
079    
080                this.wasSneaking = var1;
081            }
082    
083            boolean var2 = this.isSneaking();
084    
085            if (var2 != this.shouldStopSneaking)
086            {
087                if (var2)
088                {
089                    this.sendQueue.addToSendQueue(new Packet19EntityAction(this, 1));
090                }
091                else
092                {
093                    this.sendQueue.addToSendQueue(new Packet19EntityAction(this, 2));
094                }
095    
096                this.shouldStopSneaking = var2;
097            }
098    
099            double var3 = this.posX - this.oldPosX;
100            double var5 = this.boundingBox.minY - this.oldMinY;
101            double var7 = this.posZ - this.oldPosZ;
102            double var9 = (double)(this.rotationYaw - this.oldRotationYaw);
103            double var11 = (double)(this.rotationPitch - this.oldRotationPitch);
104            boolean var13 = var3 * var3 + var5 * var5 + var7 * var7 > 9.0E-4D || this.field_71168_co >= 20;
105            boolean var14 = var9 != 0.0D || var11 != 0.0D;
106    
107            if (this.ridingEntity != null)
108            {
109                this.sendQueue.addToSendQueue(new Packet13PlayerLookMove(this.motionX, -999.0D, -999.0D, this.motionZ, this.rotationYaw, this.rotationPitch, this.onGround));
110                var13 = false;
111            }
112            else if (var13 && var14)
113            {
114                this.sendQueue.addToSendQueue(new Packet13PlayerLookMove(this.posX, this.boundingBox.minY, this.posY, this.posZ, this.rotationYaw, this.rotationPitch, this.onGround));
115            }
116            else if (var13)
117            {
118                this.sendQueue.addToSendQueue(new Packet11PlayerPosition(this.posX, this.boundingBox.minY, this.posY, this.posZ, this.onGround));
119            }
120            else if (var14)
121            {
122                this.sendQueue.addToSendQueue(new Packet12PlayerLook(this.rotationYaw, this.rotationPitch, this.onGround));
123            }
124            else
125            {
126                this.sendQueue.addToSendQueue(new Packet10Flying(this.onGround));
127            }
128    
129            ++this.field_71168_co;
130            this.wasOnGround = this.onGround;
131    
132            if (var13)
133            {
134                this.oldPosX = this.posX;
135                this.oldMinY = this.boundingBox.minY;
136                this.oldPosY = this.posY;
137                this.oldPosZ = this.posZ;
138                this.field_71168_co = 0;
139            }
140    
141            if (var14)
142            {
143                this.oldRotationYaw = this.rotationYaw;
144                this.oldRotationPitch = this.rotationPitch;
145            }
146        }
147    
148        /**
149         * Called when player presses the drop item key
150         */
151        public EntityItem dropOneItem()
152        {
153            this.sendQueue.addToSendQueue(new Packet14BlockDig(4, 0, 0, 0, 0));
154            return null;
155        }
156    
157        /**
158         * Joins the passed in entity item with the world. Args: entityItem
159         */
160        public void joinEntityItemWithWorld(EntityItem par1EntityItem) {}
161    
162        /**
163         * Sends a chat message from the player. Args: chatMessage
164         */
165        public void sendChatMessage(String par1Str)
166        {
167            this.sendQueue.addToSendQueue(new Packet3Chat(par1Str));
168        }
169    
170        /**
171         * Swings the item the player is holding.
172         */
173        public void swingItem()
174        {
175            super.swingItem();
176            this.sendQueue.addToSendQueue(new Packet18Animation(this, 1));
177        }
178    
179        public void respawnPlayer()
180        {
181            this.sendQueue.addToSendQueue(new Packet205ClientCommand(1));
182        }
183    
184        /**
185         * Deals damage to the entity. If its a EntityPlayer then will take damage from the armor first and then health
186         * second with the reduced value. Args: damageAmount
187         */
188        protected void damageEntity(DamageSource par1DamageSource, int par2)
189        {
190            if (!this.func_85032_ar())
191            {
192                this.setEntityHealth(this.getHealth() - par2);
193            }
194        }
195    
196        /**
197         * sets current screen to null (used on escape buttons of GUIs)
198         */
199        public void closeScreen()
200        {
201            this.sendQueue.addToSendQueue(new Packet101CloseWindow(this.craftingInventory.windowId));
202            this.inventory.setItemStack((ItemStack)null);
203            super.closeScreen();
204        }
205    
206        /**
207         * Updates health locally.
208         */
209        public void setHealth(int par1)
210        {
211            if (this.hasSetHealth)
212            {
213                super.setHealth(par1);
214            }
215            else
216            {
217                this.setEntityHealth(par1);
218                this.hasSetHealth = true;
219            }
220        }
221    
222        /**
223         * Adds a value to a statistic field.
224         */
225        public void addStat(StatBase par1StatBase, int par2)
226        {
227            if (par1StatBase != null)
228            {
229                if (par1StatBase.isIndependent)
230                {
231                    super.addStat(par1StatBase, par2);
232                }
233            }
234        }
235    
236        /**
237         * Used by NetClientHandler.handleStatistic
238         */
239        public void incrementStat(StatBase par1StatBase, int par2)
240        {
241            if (par1StatBase != null)
242            {
243                if (!par1StatBase.isIndependent)
244                {
245                    super.addStat(par1StatBase, par2);
246                }
247            }
248        }
249    
250        /**
251         * Sends the player's abilities to the server (if there is one).
252         */
253        public void sendPlayerAbilities()
254        {
255            this.sendQueue.addToSendQueue(new Packet202PlayerAbilities(this.capabilities));
256        }
257    
258        public boolean func_71066_bF()
259        {
260            return true;
261        }
262    }