001package net.minecraft.client.entity;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.client.Minecraft;
006import net.minecraft.entity.player.EntityPlayer;
007import net.minecraft.item.Item;
008import net.minecraft.item.ItemStack;
009import net.minecraft.util.ChunkCoordinates;
010import net.minecraft.util.DamageSource;
011import net.minecraft.util.MathHelper;
012import net.minecraft.util.StringUtils;
013import net.minecraft.world.World;
014
015@SideOnly(Side.CLIENT)
016public class EntityOtherPlayerMP extends EntityPlayer
017{
018    private boolean isItemInUse = false;
019    private int otherPlayerMPPosRotationIncrements;
020    private double otherPlayerMPX;
021    private double otherPlayerMPY;
022    private double otherPlayerMPZ;
023    private double otherPlayerMPYaw;
024    private double otherPlayerMPPitch;
025
026    public EntityOtherPlayerMP(World par1World, String par2Str)
027    {
028        super(par1World);
029        this.username = par2Str;
030        this.yOffset = 0.0F;
031        this.stepHeight = 0.0F;
032
033        if (par2Str != null && par2Str.length() > 0)
034        {
035            this.skinUrl = "http://skins.minecraft.net/MinecraftSkins/" + StringUtils.stripControlCodes(par2Str) + ".png";
036        }
037
038        this.noClip = true;
039        this.field_71082_cx = 0.25F;
040        this.renderDistanceWeight = 10.0D;
041    }
042
043    /**
044     * sets the players height back to normal after doing things like sleeping and dieing
045     */
046    protected void resetHeight()
047    {
048        this.yOffset = 0.0F;
049    }
050
051    /**
052     * Called when the entity is attacked.
053     */
054    public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
055    {
056        return true;
057    }
058
059    /**
060     * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,
061     * posY, posZ, yaw, pitch
062     */
063    public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9)
064    {
065        this.otherPlayerMPX = par1;
066        this.otherPlayerMPY = par3;
067        this.otherPlayerMPZ = par5;
068        this.otherPlayerMPYaw = (double)par7;
069        this.otherPlayerMPPitch = (double)par8;
070        this.otherPlayerMPPosRotationIncrements = par9;
071    }
072
073    public void updateCloak()
074    {
075        this.cloakUrl = "http://skins.minecraft.net/MinecraftCloaks/" + StringUtils.stripControlCodes(this.username) + ".png";
076    }
077
078    /**
079     * Called to update the entity's position/logic.
080     */
081    public void onUpdate()
082    {
083        this.field_71082_cx = 0.0F;
084        super.onUpdate();
085        this.prevLimbYaw = this.limbYaw;
086        double d0 = this.posX - this.prevPosX;
087        double d1 = this.posZ - this.prevPosZ;
088        float f = MathHelper.sqrt_double(d0 * d0 + d1 * d1) * 4.0F;
089
090        if (f > 1.0F)
091        {
092            f = 1.0F;
093        }
094
095        this.limbYaw += (f - this.limbYaw) * 0.4F;
096        this.limbSwing += this.limbYaw;
097
098        if (!this.isItemInUse && this.isEating() && this.inventory.mainInventory[this.inventory.currentItem] != null)
099        {
100            ItemStack itemstack = this.inventory.mainInventory[this.inventory.currentItem];
101            this.setItemInUse(this.inventory.mainInventory[this.inventory.currentItem], Item.itemsList[itemstack.itemID].getMaxItemUseDuration(itemstack));
102            this.isItemInUse = true;
103        }
104        else if (this.isItemInUse && !this.isEating())
105        {
106            this.clearItemInUse();
107            this.isItemInUse = false;
108        }
109    }
110
111    public float getShadowSize()
112    {
113        return 0.0F;
114    }
115
116    /**
117     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
118     * use this to react to sunlight and start to burn.
119     */
120    public void onLivingUpdate()
121    {
122        super.updateEntityActionState();
123
124        if (this.otherPlayerMPPosRotationIncrements > 0)
125        {
126            double d0 = this.posX + (this.otherPlayerMPX - this.posX) / (double)this.otherPlayerMPPosRotationIncrements;
127            double d1 = this.posY + (this.otherPlayerMPY - this.posY) / (double)this.otherPlayerMPPosRotationIncrements;
128            double d2 = this.posZ + (this.otherPlayerMPZ - this.posZ) / (double)this.otherPlayerMPPosRotationIncrements;
129            double d3;
130
131            for (d3 = this.otherPlayerMPYaw - (double)this.rotationYaw; d3 < -180.0D; d3 += 360.0D)
132            {
133                ;
134            }
135
136            while (d3 >= 180.0D)
137            {
138                d3 -= 360.0D;
139            }
140
141            this.rotationYaw = (float)((double)this.rotationYaw + d3 / (double)this.otherPlayerMPPosRotationIncrements);
142            this.rotationPitch = (float)((double)this.rotationPitch + (this.otherPlayerMPPitch - (double)this.rotationPitch) / (double)this.otherPlayerMPPosRotationIncrements);
143            --this.otherPlayerMPPosRotationIncrements;
144            this.setPosition(d0, d1, d2);
145            this.setRotation(this.rotationYaw, this.rotationPitch);
146        }
147
148        this.prevCameraYaw = this.cameraYaw;
149        float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
150        float f1 = (float)Math.atan(-this.motionY * 0.20000000298023224D) * 15.0F;
151
152        if (f > 0.1F)
153        {
154            f = 0.1F;
155        }
156
157        if (!this.onGround || this.getHealth() <= 0)
158        {
159            f = 0.0F;
160        }
161
162        if (this.onGround || this.getHealth() <= 0)
163        {
164            f1 = 0.0F;
165        }
166
167        this.cameraYaw += (f - this.cameraYaw) * 0.4F;
168        this.cameraPitch += (f1 - this.cameraPitch) * 0.8F;
169    }
170
171    /**
172     * Sets the held item, or an armor slot. Slot 0 is held item. Slot 1-4 is armor. Params: Item, slot
173     */
174    public void setCurrentItemOrArmor(int par1, ItemStack par2ItemStack)
175    {
176        if (par1 == 0)
177        {
178            this.inventory.mainInventory[this.inventory.currentItem] = par2ItemStack;
179        }
180        else
181        {
182            this.inventory.armorInventory[par1 - 1] = par2ItemStack;
183        }
184    }
185
186    public float getEyeHeight()
187    {
188        return 1.82F;
189    }
190
191    public void sendChatToPlayer(String par1Str)
192    {
193        Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(par1Str);
194    }
195
196    /**
197     * Returns true if the command sender is allowed to use the given command.
198     */
199    public boolean canCommandSenderUseCommand(int par1, String par2Str)
200    {
201        return false;
202    }
203
204    /**
205     * Return the position for this command sender.
206     */
207    public ChunkCoordinates getPlayerCoordinates()
208    {
209        return new ChunkCoordinates(MathHelper.floor_double(this.posX + 0.5D), MathHelper.floor_double(this.posY + 0.5D), MathHelper.floor_double(this.posZ + 0.5D));
210    }
211}