    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.playerCloakUrl = "http://skins.minecraft.net/MinecraftCloaks/" + StringUtils.stripControlCodes(this.username) + ".png";
    076        this.cloakUrl = this.playerCloakUrl;
    077    }
    078
    079    /**
    080     * Called to update the entity's position/logic.
    081     */
    082    public void onUpdate()
    083    {
    084        this.field_71082_cx = 0.0F;
    085        super.onUpdate();
    086        this.prevLegYaw = this.legYaw;
    087        double var1 = this.posX - this.prevPosX;
    088        double var3 = this.posZ - this.prevPosZ;
    089        float var5 = MathHelper.sqrt_double(var1 * var1 + var3 * var3) * 4.0F;
    090
    091        if (var5 > 1.0F)
    092        {
    093            var5 = 1.0F;
    094        }
    095
    096        this.legYaw += (var5 - this.legYaw) * 0.4F;
    097        this.legSwing += this.legYaw;
    098
    099        if (!this.isItemInUse && this.isEating() && this.inventory.mainInventory[this.inventory.currentItem] != null)
    100        {
    101            ItemStack var6 = this.inventory.mainInventory[this.inventory.currentItem];
    102            this.setItemInUse(this.inventory.mainInventory[this.inventory.currentItem], Item.itemsList[var6.itemID].getMaxItemUseDuration(var6));
    103            this.isItemInUse = true;
    104        }
    105        else if (this.isItemInUse && !this.isEating())
    106        {
    107            this.clearItemInUse();
    108            this.isItemInUse = false;
    109        }
    110    }
    111
    112    public float getShadowSize()
    113    {
    114        return 0.0F;
    115    }
    116
    117    /**
    118     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
    119     * use this to react to sunlight and start to burn.
    120     */
    121    public void onLivingUpdate()
    122    {
    123        super.updateEntityActionState();
    124
    125        if (this.otherPlayerMPPosRotationIncrements > 0)
    126        {
    127            double var1 = this.posX + (this.otherPlayerMPX - this.posX) / (double)this.otherPlayerMPPosRotationIncrements;
    128            double var3 = this.posY + (this.otherPlayerMPY - this.posY) / (double)this.otherPlayerMPPosRotationIncrements;
    129            double var5 = this.posZ + (this.otherPlayerMPZ - this.posZ) / (double)this.otherPlayerMPPosRotationIncrements;
    130            double var7;
    131
    132            for (var7 = this.otherPlayerMPYaw - (double)this.rotationYaw; var7 < -180.0D; var7 += 360.0D)
    133            {
    134                ;
    135            }
    136
    137            while (var7 >= 180.0D)
    138            {
    139                var7 -= 360.0D;
    140            }
    141
    142            this.rotationYaw = (float)((double)this.rotationYaw + var7 / (double)this.otherPlayerMPPosRotationIncrements);
    143            this.rotationPitch = (float)((double)this.rotationPitch + (this.otherPlayerMPPitch - (double)this.rotationPitch) / (double)this.otherPlayerMPPosRotationIncrements);
    144            --this.otherPlayerMPPosRotationIncrements;
    145            this.setPosition(var1, var3, var5);
    146            this.setRotation(this.rotationYaw, this.rotationPitch);
    147        }
    148
    149        this.prevCameraYaw = this.cameraYaw;
    150        float var9 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
    151        float var2 = (float)Math.atan(-this.motionY * 0.20000000298023224D) * 15.0F;
    152
    153        if (var9 > 0.1F)
    154        {
    155            var9 = 0.1F;
    156        }
    157
    158        if (!this.onGround || this.getHealth() <= 0)
    159        {
    160            var9 = 0.0F;
    161        }
    162
    163        if (this.onGround || this.getHealth() <= 0)
    164        {
    165            var2 = 0.0F;
    166        }
    167
    168        this.cameraYaw += (var9 - this.cameraYaw) * 0.4F;
    169        this.cameraPitch += (var2 - this.cameraPitch) * 0.8F;
    170    }
    171
    172    /**
    173     * Sets the held item, or an armor slot. Slot 0 is held item. Slot 1-4 is armor. Params: Item, slot
    174     */
    175    public void setCurrentItemOrArmor(int par1, ItemStack par2ItemStack)
    176    {
    177        if (par1 == 0)
    178        {
    179            this.inventory.mainInventory[this.inventory.currentItem] = par2ItemStack;
    180        }
    181        else
    182        {
    183            this.inventory.armorInventory[par1 - 1] = par2ItemStack;
    184        }
    185    }
    186
    187    public float getEyeHeight()
    188    {
    189        return 1.82F;
    190    }
    191
    192    public void sendChatToPlayer(String par1Str)
    193    {
    194        Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(par1Str);
    195    }
    196
    197    /**
    198     * Returns true if the command sender is allowed to use the given command.
    199     */
    200    public boolean canCommandSenderUseCommand(int par1, String par2Str)
    201    {
    202        return false;
    203    }
    204
    205    /**
    206     * Return the position for this command sender.
    207     */
    208    public ChunkCoordinates getPlayerCoordinates()
    209    {
    210        return new ChunkCoordinates(MathHelper.floor_double(this.posX + 0.5D), MathHelper.floor_double(this.posY + 0.5D), MathHelper.floor_double(this.posZ + 0.5D));
    211    }
    212}