    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    import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*;
    007    import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*;
    008    import net.minecraftforge.client.IItemRenderer;
    009    import net.minecraftforge.client.MinecraftForgeClient;
    010    import net.minecraftforge.client.ForgeHooksClient;
    011
    012    import org.lwjgl.opengl.GL11;
    013
    014    @SideOnly(Side.CLIENT)
    015    public class RenderPlayer extends RenderLiving
    016    {
    017        private ModelBiped modelBipedMain;
    018        private ModelBiped modelArmorChestplate;
    019        private ModelBiped modelArmor;
    020        public static String[] armorFilenamePrefix = new String[] {"cloth", "chain", "iron", "diamond", "gold"};
    021
    022        public RenderPlayer()
    023        {
    024            super(new ModelBiped(0.0F), 0.5F);
    025            this.modelBipedMain = (ModelBiped)this.mainModel;
    026            this.modelArmorChestplate = new ModelBiped(1.0F);
    027            this.modelArmor = new ModelBiped(0.5F);
    028        }
    029
    030        /**
    031         * Set the specified armor model as the player model. Args: player, armorSlot, partialTick
    032         */
    033        protected int setArmorModel(EntityPlayer par1EntityPlayer, int par2, float par3)
    034        {
    035            ItemStack var4 = par1EntityPlayer.inventory.armorItemInSlot(3 - par2);
    036
    037            if (var4 != null)
    038            {
    039                Item var5 = var4.getItem();
    040
    041                if (var5 instanceof ItemArmor)
    042                {
    043                    ItemArmor var6 = (ItemArmor)var5;
    044                    this.loadTexture(ForgeHooksClient.getArmorTexture(var4, "/armor/" + armorFilenamePrefix[var6.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + ".png"));
    045                    ModelBiped var7 = par2 == 2 ? this.modelArmor : this.modelArmorChestplate;
    046                    var7.bipedHead.showModel = par2 == 0;
    047                    var7.bipedHeadwear.showModel = par2 == 0;
    048                    var7.bipedBody.showModel = par2 == 1 || par2 == 2;
    049                    var7.bipedRightArm.showModel = par2 == 1;
    050                    var7.bipedLeftArm.showModel = par2 == 1;
    051                    var7.bipedRightLeg.showModel = par2 == 2 || par2 == 3;
    052                    var7.bipedLeftLeg.showModel = par2 == 2 || par2 == 3;
    053                    this.setRenderPassModel(var7);
    054
    055                    if (var4.isItemEnchanted())
    056                    {
    057                        return 15;
    058                    }
    059
    060                    return 1;
    061                }
    062            }
    063
    064            return -1;
    065        }
    066
    067        public void renderPlayer(EntityPlayer par1EntityPlayer, double par2, double par4, double par6, float par8, float par9)
    068        {
    069            ItemStack var10 = par1EntityPlayer.inventory.getCurrentItem();
    070            this.modelArmorChestplate.heldItemRight = this.modelArmor.heldItemRight = this.modelBipedMain.heldItemRight = var10 != null ? 1 : 0;
    071
    072            if (var10 != null && par1EntityPlayer.getItemInUseCount() > 0)
    073            {
    074                EnumAction var11 = var10.getItemUseAction();
    075
    076                if (var11 == EnumAction.block)
    077                {
    078                    this.modelArmorChestplate.heldItemRight = this.modelArmor.heldItemRight = this.modelBipedMain.heldItemRight = 3;
    079                }
    080                else if (var11 == EnumAction.bow)
    081                {
    082                    this.modelArmorChestplate.aimedBow = this.modelArmor.aimedBow = this.modelBipedMain.aimedBow = true;
    083                }
    084            }
    085
    086            this.modelArmorChestplate.isSneak = this.modelArmor.isSneak = this.modelBipedMain.isSneak = par1EntityPlayer.isSneaking();
    087            double var13 = par4 - (double)par1EntityPlayer.yOffset;
    088
    089            if (par1EntityPlayer.isSneaking() && !(par1EntityPlayer instanceof EntityPlayerSP))
    090            {
    091                var13 -= 0.125D;
    092            }
    093
    094            super.doRenderLiving(par1EntityPlayer, par2, var13, par6, par8, par9);
    095            this.modelArmorChestplate.aimedBow = this.modelArmor.aimedBow = this.modelBipedMain.aimedBow = false;
    096            this.modelArmorChestplate.isSneak = this.modelArmor.isSneak = this.modelBipedMain.isSneak = false;
    097            this.modelArmorChestplate.heldItemRight = this.modelArmor.heldItemRight = this.modelBipedMain.heldItemRight = 0;
    098        }
    099
    100        /**
    101         * Used to render a player's name above their head
    102         */
    103        protected void renderName(EntityPlayer par1EntityPlayer, double par2, double par4, double par6)
    104        {
    105            if (Minecraft.isGuiEnabled() && par1EntityPlayer != this.renderManager.livingPlayer)
    106            {
    107                float var8 = 1.6F;
    108                float var9 = 0.016666668F * var8;
    109                double var10 = par1EntityPlayer.getDistanceSqToEntity(this.renderManager.livingPlayer);
    110                float var12 = par1EntityPlayer.isSneaking() ? 32.0F : 64.0F;
    111
    112                if (var10 < (double)(var12 * var12))
    113                {
    114                    String var13 = par1EntityPlayer.username;
    115
    116                    if (par1EntityPlayer.isSneaking())
    117                    {
    118                        FontRenderer var14 = this.getFontRendererFromRenderManager();
    119                        GL11.glPushMatrix();
    120                        GL11.glTranslatef((float)par2 + 0.0F, (float)par4 + 2.3F, (float)par6);
    121                        GL11.glNormal3f(0.0F, 1.0F, 0.0F);
    122                        GL11.glRotatef(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
    123                        GL11.glRotatef(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
    124                        GL11.glScalef(-var9, -var9, var9);
    125                        GL11.glDisable(GL11.GL_LIGHTING);
    126                        GL11.glTranslatef(0.0F, 0.25F / var9, 0.0F);
    127                        GL11.glDepthMask(false);
    128                        GL11.glEnable(GL11.GL_BLEND);
    129                        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    130                        Tessellator var15 = Tessellator.instance;
    131                        GL11.glDisable(GL11.GL_TEXTURE_2D);
    132                        var15.startDrawingQuads();
    133                        int var16 = var14.getStringWidth(var13) / 2;
    134                        var15.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.25F);
    135                        var15.addVertex((double)(-var16 - 1), -1.0D, 0.0D);
    136                        var15.addVertex((double)(-var16 - 1), 8.0D, 0.0D);
    137                        var15.addVertex((double)(var16 + 1), 8.0D, 0.0D);
    138                        var15.addVertex((double)(var16 + 1), -1.0D, 0.0D);
    139                        var15.draw();
    140                        GL11.glEnable(GL11.GL_TEXTURE_2D);
    141                        GL11.glDepthMask(true);
    142                        var14.drawString(var13, -var14.getStringWidth(var13) / 2, 0, 553648127);
    143                        GL11.glEnable(GL11.GL_LIGHTING);
    144                        GL11.glDisable(GL11.GL_BLEND);
    145                        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    146                        GL11.glPopMatrix();
    147                    }
    148                    else if (par1EntityPlayer.isPlayerSleeping())
    149                    {
    150                        this.renderLivingLabel(par1EntityPlayer, var13, par2, par4 - 1.5D, par6, 64);
    151                    }
    152                    else
    153                    {
    154                        this.renderLivingLabel(par1EntityPlayer, var13, par2, par4, par6, 64);
    155                    }
    156                }
    157            }
    158        }
    159
    160        /**
    161         * Method for adding special render rules
    162         */
    163        protected void renderSpecials(EntityPlayer par1EntityPlayer, float par2)
    164        {
    165            super.renderEquippedItems(par1EntityPlayer, par2);
    166            ItemStack var3 = par1EntityPlayer.inventory.armorItemInSlot(3);
    167
    168            if (var3 != null && var3.getItem() instanceof ItemBlock)
    169            {
    170                GL11.glPushMatrix();
    171                this.modelBipedMain.bipedHead.postRender(0.0625F);
    172                IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(var3, EQUIPPED);
    173                boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(EQUIPPED, var3, BLOCK_3D));
    174
    175                if (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[var3.itemID].getRenderType()))
    176                {
    177                    float var4 = 0.625F;
    178                    GL11.glTranslatef(0.0F, -0.25F, 0.0F);
    179                    GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
    180                    GL11.glScalef(var4, -var4, var4);
    181                }
    182
    183                this.renderManager.itemRenderer.renderItem(par1EntityPlayer, var3, 0);
    184                GL11.glPopMatrix();
    185            }
    186
    187            float var6;
    188
    189            if (par1EntityPlayer.username.equals("deadmau5") && this.loadDownloadableImageTexture(par1EntityPlayer.skinUrl, (String)null))
    190            {
    191                for (int var19 = 0; var19 < 2; ++var19)
    192                {
    193                    float var5 = par1EntityPlayer.prevRotationYaw + (par1EntityPlayer.rotationYaw - par1EntityPlayer.prevRotationYaw) * par2 - (par1EntityPlayer.prevRenderYawOffset + (par1EntityPlayer.renderYawOffset - par1EntityPlayer.prevRenderYawOffset) * par2);
    194                    var6 = par1EntityPlayer.prevRotationPitch + (par1EntityPlayer.rotationPitch - par1EntityPlayer.prevRotationPitch) * par2;
    195                    GL11.glPushMatrix();
    196                    GL11.glRotatef(var5, 0.0F, 1.0F, 0.0F);
    197                    GL11.glRotatef(var6, 1.0F, 0.0F, 0.0F);
    198                    GL11.glTranslatef(0.375F * (float)(var19 * 2 - 1), 0.0F, 0.0F);
    199                    GL11.glTranslatef(0.0F, -0.375F, 0.0F);
    200                    GL11.glRotatef(-var6, 1.0F, 0.0F, 0.0F);
    201                    GL11.glRotatef(-var5, 0.0F, 1.0F, 0.0F);
    202                    float var7 = 1.3333334F;
    203                    GL11.glScalef(var7, var7, var7);
    204                    this.modelBipedMain.renderEars(0.0625F);
    205                    GL11.glPopMatrix();
    206                }
    207            }
    208
    209            float var10;
    210
    211            if (this.loadDownloadableImageTexture(par1EntityPlayer.playerCloakUrl, (String)null))
    212            {
    213                GL11.glPushMatrix();
    214                GL11.glTranslatef(0.0F, 0.0F, 0.125F);
    215                double var22 = par1EntityPlayer.field_71091_bM + (par1EntityPlayer.field_71094_bP - par1EntityPlayer.field_71091_bM) * (double)par2 - (par1EntityPlayer.prevPosX + (par1EntityPlayer.posX - par1EntityPlayer.prevPosX) * (double)par2);
    216                double var23 = par1EntityPlayer.field_71096_bN + (par1EntityPlayer.field_71095_bQ - par1EntityPlayer.field_71096_bN) * (double)par2 - (par1EntityPlayer.prevPosY + (par1EntityPlayer.posY - par1EntityPlayer.prevPosY) * (double)par2);
    217                double var8 = par1EntityPlayer.field_71097_bO + (par1EntityPlayer.field_71085_bR - par1EntityPlayer.field_71097_bO) * (double)par2 - (par1EntityPlayer.prevPosZ + (par1EntityPlayer.posZ - par1EntityPlayer.prevPosZ) * (double)par2);
    218                var10 = par1EntityPlayer.prevRenderYawOffset + (par1EntityPlayer.renderYawOffset - par1EntityPlayer.prevRenderYawOffset) * par2;
    219                double var11 = (double)MathHelper.sin(var10 * (float)Math.PI / 180.0F);
    220                double var13 = (double)(-MathHelper.cos(var10 * (float)Math.PI / 180.0F));
    221                float var15 = (float)var23 * 10.0F;
    222
    223                if (var15 < -6.0F)
    224                {
    225                    var15 = -6.0F;
    226                }
    227
    228                if (var15 > 32.0F)
    229                {
    230                    var15 = 32.0F;
    231                }
    232
    233                float var16 = (float)(var22 * var11 + var8 * var13) * 100.0F;
    234                float var17 = (float)(var22 * var13 - var8 * var11) * 100.0F;
    235
    236                if (var16 < 0.0F)
    237                {
    238                    var16 = 0.0F;
    239                }
    240
    241                float var18 = par1EntityPlayer.prevCameraYaw + (par1EntityPlayer.cameraYaw - par1EntityPlayer.prevCameraYaw) * par2;
    242                var15 += MathHelper.sin((par1EntityPlayer.prevDistanceWalkedModified + (par1EntityPlayer.distanceWalkedModified - par1EntityPlayer.prevDistanceWalkedModified) * par2) * 6.0F) * 32.0F * var18;
    243
    244                if (par1EntityPlayer.isSneaking())
    245                {
    246                    var15 += 25.0F;
    247                }
    248
    249                GL11.glRotatef(6.0F + var16 / 2.0F + var15, 1.0F, 0.0F, 0.0F);
    250                GL11.glRotatef(var17 / 2.0F, 0.0F, 0.0F, 1.0F);
    251                GL11.glRotatef(-var17 / 2.0F, 0.0F, 1.0F, 0.0F);
    252                GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
    253                this.modelBipedMain.renderCloak(0.0625F);
    254                GL11.glPopMatrix();
    255            }
    256
    257            ItemStack var21 = par1EntityPlayer.inventory.getCurrentItem();
    258
    259            if (var21 != null)
    260            {
    261                GL11.glPushMatrix();
    262                this.modelBipedMain.bipedRightArm.postRender(0.0625F);
    263                GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F);
    264
    265                if (par1EntityPlayer.fishEntity != null)
    266                {
    267                    var21 = new ItemStack(Item.stick);
    268                }
    269
    270                EnumAction var20 = null;
    271
    272                if (par1EntityPlayer.getItemInUseCount() > 0)
    273                {
    274                    var20 = var21.getItemUseAction();
    275                }
    276
    277                IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(var21, EQUIPPED);
    278                boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(EQUIPPED, var21, BLOCK_3D));
    279
    280                if (var21.getItem() instanceof ItemBlock && (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[var21.itemID].getRenderType())))
    281                {
    282                    var6 = 0.5F;
    283                    GL11.glTranslatef(0.0F, 0.1875F, -0.3125F);
    284                    var6 *= 0.75F;
    285                    GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
    286                    GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
    287                    GL11.glScalef(var6, -var6, var6);
    288                }
    289                else if (var21.itemID == Item.bow.shiftedIndex)
    290                {
    291                    var6 = 0.625F;
    292                    GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
    293                    GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
    294                    GL11.glScalef(var6, -var6, var6);
    295                    GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
    296                    GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
    297                }
    298                else if (Item.itemsList[var21.itemID].isFull3D())
    299                {
    300                    var6 = 0.625F;
    301
    302                    if (Item.itemsList[var21.itemID].shouldRotateAroundWhenRendering())
    303                    {
    304                        GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
    305                        GL11.glTranslatef(0.0F, -0.125F, 0.0F);
    306                    }
    307
    308                    if (par1EntityPlayer.getItemInUseCount() > 0 && var20 == EnumAction.block)
    309                    {
    310                        GL11.glTranslatef(0.05F, 0.0F, -0.1F);
    311                        GL11.glRotatef(-50.0F, 0.0F, 1.0F, 0.0F);
    312                        GL11.glRotatef(-10.0F, 1.0F, 0.0F, 0.0F);
    313                        GL11.glRotatef(-60.0F, 0.0F, 0.0F, 1.0F);
    314                    }
    315
    316                    GL11.glTranslatef(0.0F, 0.1875F, 0.0F);
    317                    GL11.glScalef(var6, -var6, var6);
    318                    GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
    319                    GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
    320                }
    321                else
    322                {
    323                    var6 = 0.375F;
    324                    GL11.glTranslatef(0.25F, 0.1875F, -0.1875F);
    325                    GL11.glScalef(var6, var6, var6);
    326                    GL11.glRotatef(60.0F, 0.0F, 0.0F, 1.0F);
    327                    GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F);
    328                    GL11.glRotatef(20.0F, 0.0F, 0.0F, 1.0F);
    329                }
    330
    331                if (var21.getItem().requiresMultipleRenderPasses())
    332                {
    333                    for (int var25 = 0; var25 < var21.getItem().getRenderPasses(var21.getItemDamage()); ++var25)
    334                    {
    335                        int var24 = var21.getItem().getColorFromDamage(var21.getItemDamage(), var25);
    336                        float var26 = (float)(var24 >> 16 & 255) / 255.0F;
    337                        float var9 = (float)(var24 >> 8 & 255) / 255.0F;
    338                        var10 = (float)(var24 & 255) / 255.0F;
    339                        GL11.glColor4f(var26, var9, var10, 1.0F);
    340                        this.renderManager.itemRenderer.renderItem(par1EntityPlayer, var21, var25);
    341                    }
    342                }
    343                else
    344                {
    345                    this.renderManager.itemRenderer.renderItem(par1EntityPlayer, var21, 0);
    346                }
    347
    348                GL11.glPopMatrix();
    349            }
    350        }
    351
    352        protected void renderPlayerScale(EntityPlayer par1EntityPlayer, float par2)
    353        {
    354            float var3 = 0.9375F;
    355            GL11.glScalef(var3, var3, var3);
    356        }
    357
    358        public void drawFirstPersonHand()
    359        {
    360            this.modelBipedMain.onGround = 0.0F;
    361            this.modelBipedMain.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
    362            this.modelBipedMain.bipedRightArm.render(0.0625F);
    363        }
    364
    365        /**
    366         * Renders player with sleeping offset if sleeping
    367         */
    368        protected void renderPlayerSleep(EntityPlayer par1EntityPlayer, double par2, double par4, double par6)
    369        {
    370            if (par1EntityPlayer.isEntityAlive() && par1EntityPlayer.isPlayerSleeping())
    371            {
    372                super.renderLivingAt(par1EntityPlayer, par2 + (double)par1EntityPlayer.field_71079_bU, par4 + (double)par1EntityPlayer.field_71082_cx, par6 + (double)par1EntityPlayer.field_71089_bV);
    373            }
    374            else
    375            {
    376                super.renderLivingAt(par1EntityPlayer, par2, par4, par6);
    377            }
    378        }
    379
    380        /**
    381         * Rotates the player if the player is sleeping. This method is called in rotateCorpse.
    382         */
    383        protected void rotatePlayer(EntityPlayer par1EntityPlayer, float par2, float par3, float par4)
    384        {
    385            if (par1EntityPlayer.isEntityAlive() && par1EntityPlayer.isPlayerSleeping())
    386            {
    387                GL11.glRotatef(par1EntityPlayer.getBedOrientationInDegrees(), 0.0F, 1.0F, 0.0F);
    388                GL11.glRotatef(this.getDeathMaxRotation(par1EntityPlayer), 0.0F, 0.0F, 1.0F);
    389                GL11.glRotatef(270.0F, 0.0F, 1.0F, 0.0F);
    390            }
    391            else
    392            {
    393                super.rotateCorpse(par1EntityPlayer, par2, par3, par4);
    394            }
    395        }
    396
    397        /**
    398         * Passes the specialRender and renders it
    399         */
    400        protected void passSpecialRender(EntityLiving par1EntityLiving, double par2, double par4, double par6)
    401        {
    402            this.renderName((EntityPlayer)par1EntityLiving, par2, par4, par6);
    403        }
    404
    405        /**
    406         * Allows the render to do any OpenGL state modifications necessary before the model is rendered. Args:
    407         * entityLiving, partialTickTime
    408         */
    409        protected void preRenderCallback(EntityLiving par1EntityLiving, float par2)
    410        {
    411            this.renderPlayerScale((EntityPlayer)par1EntityLiving, par2);
    412        }
    413
    414        /**
    415         * Queries whether should render the specified pass or not.
    416         */
    417        protected int shouldRenderPass(EntityLiving par1EntityLiving, int par2, float par3)
    418        {
    419            return this.setArmorModel((EntityPlayer)par1EntityLiving, par2, par3);
    420        }
    421
    422        protected void renderEquippedItems(EntityLiving par1EntityLiving, float par2)
    423        {
    424            this.renderSpecials((EntityPlayer)par1EntityLiving, par2);
    425        }
    426
    427        protected void rotateCorpse(EntityLiving par1EntityLiving, float par2, float par3, float par4)
    428        {
    429            this.rotatePlayer((EntityPlayer)par1EntityLiving, par2, par3, par4);
    430        }
    431
    432        /**
    433         * Sets a simple glTranslate on a LivingEntity.
    434         */
    435        protected void renderLivingAt(EntityLiving par1EntityLiving, double par2, double par4, double par6)
    436        {
    437            this.renderPlayerSleep((EntityPlayer)par1EntityLiving, par2, par4, par6);
    438        }
    439
    440        public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)
    441        {
    442            this.renderPlayer((EntityPlayer)par1EntityLiving, par2, par4, par6, par8, par9);
    443        }
    444
    445        /**
    446         * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
    447         * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
    448         * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
    449         * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
    450         */
    451        public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    452        {
    453            this.renderPlayer((EntityPlayer)par1Entity, par2, par4, par6, par8, par9);
    454        }
    455    }