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                if (var14)
110                {
111                    this.sendQueue.addToSendQueue(new Packet11PlayerPosition(this.motionX, -999.0D, -999.0D, this.motionZ, this.onGround));
112                }
113                else
114                {
115                    this.sendQueue.addToSendQueue(new Packet13PlayerLookMove(this.motionX, -999.0D, -999.0D, this.motionZ, this.rotationYaw, this.rotationPitch, this.onGround));
116                }
117    
118                var13 = false;
119            }
120            else if (var13 && var14)
121            {
122                this.sendQueue.addToSendQueue(new Packet13PlayerLookMove(this.posX, this.boundingBox.minY, this.posY, this.posZ, this.rotationYaw, this.rotationPitch, this.onGround));
123            }
124            else if (var13)
125            {
126                this.sendQueue.addToSendQueue(new Packet11PlayerPosition(this.posX, this.boundingBox.minY, this.posY, this.posZ, this.onGround));
127            }
128            else if (var14)
129            {
130                this.sendQueue.addToSendQueue(new Packet12PlayerLook(this.rotationYaw, this.rotationPitch, this.onGround));
131            }
132            else if (this.wasOnGround != this.onGround)
133            {
134                this.sendQueue.addToSendQueue(new Packet10Flying(this.onGround));
135            }
136    
137            ++this.field_71168_co;
138            this.wasOnGround = this.onGround;
139    
140            if (var13)
141            {
142                this.oldPosX = this.posX;
143                this.oldMinY = this.boundingBox.minY;
144                this.oldPosY = this.posY;
145                this.oldPosZ = this.posZ;
146                this.field_71168_co = 0;
147            }
148    
149            if (var14)
150            {
151                this.oldRotationYaw = this.rotationYaw;
152                this.oldRotationPitch = this.rotationPitch;
153            }
154        }
155    
156        /**
157         * Called when player presses the drop item key
158         */
159        public EntityItem dropOneItem()
160        {
161            this.sendQueue.addToSendQueue(new Packet14BlockDig(4, 0, 0, 0, 0));
162            return null;
163        }
164    
165        /**
166         * Joins the passed in entity item with the world. Args: entityItem
167         */
168        protected void joinEntityItemWithWorld(EntityItem par1EntityItem) {}
169    
170        /**
171         * Sends a chat message from the player. Args: chatMessage
172         */
173        public void sendChatMessage(String par1Str)
174        {
175            this.sendQueue.addToSendQueue(new Packet3Chat(par1Str));
176        }
177    
178        /**
179         * Swings the item the player is holding.
180         */
181        public void swingItem()
182        {
183            super.swingItem();
184            this.sendQueue.addToSendQueue(new Packet18Animation(this, 1));
185        }
186    
187        public void respawnPlayer()
188        {
189            this.sendQueue.addToSendQueue(new Packet205ClientCommand(1));
190        }
191    
192        /**
193         * Deals damage to the entity. If its a EntityPlayer then will take damage from the armor first and then health
194         * second with the reduced value. Args: damageAmount
195         */
196        protected void damageEntity(DamageSource par1DamageSource, int par2)
197        {
198            this.setEntityHealth(this.getHealth() - par2);
199        }
200    
201        /**
202         * sets current screen to null (used on escape buttons of GUIs)
203         */
204        public void closeScreen()
205        {
206            this.sendQueue.addToSendQueue(new Packet101CloseWindow(this.craftingInventory.windowId));
207            this.inventory.setItemStack((ItemStack)null);
208            super.closeScreen();
209        }
210    
211        /**
212         * Updates health locally.
213         */
214        public void setHealth(int par1)
215        {
216            if (this.hasSetHealth)
217            {
218                super.setHealth(par1);
219            }
220            else
221            {
222                this.setEntityHealth(par1);
223                this.hasSetHealth = true;
224            }
225        }
226    
227        /**
228         * Adds a value to a statistic field.
229         */
230        public void addStat(StatBase par1StatBase, int par2)
231        {
232            if (par1StatBase != null)
233            {
234                if (par1StatBase.isIndependent)
235                {
236                    super.addStat(par1StatBase, par2);
237                }
238            }
239        }
240    
241        /**
242         * Used by NetClientHandler.handleStatistic
243         */
244        public void incrementStat(StatBase par1StatBase, int par2)
245        {
246            if (par1StatBase != null)
247            {
248                if (!par1StatBase.isIndependent)
249                {
250                    super.addStat(par1StatBase, par2);
251                }
252            }
253        }
254    
255        /**
256         * Sends the player's abilities to the server (if there is one).
257         */
258        public void sendPlayerAbilities()
259        {
260            this.sendQueue.addToSendQueue(new Packet202PlayerAbilities(this.capabilities));
261        }
262    
263        public boolean func_71066_bF()
264        {
265            return true;
266        }
267    }