    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import org.lwjgl.opengl.GL11;
    006    import static net.minecraftforge.client.IItemRenderer.ItemRenderType.EQUIPPED;
    007    import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.BLOCK_3D;
    008    import net.minecraftforge.client.ForgeHooksClient;
    009    import net.minecraftforge.client.IItemRenderer;
    010    import net.minecraftforge.client.MinecraftForgeClient;
    011
    012    @SideOnly(Side.CLIENT)
    013    public class RenderBiped extends RenderLiving
    014    {
    015        protected ModelBiped modelBipedMain;
    016        protected float field_77070_b;
    017        protected ModelBiped field_82423_g;
    018        protected ModelBiped field_82425_h;
    019        public static String[] field_82424_k = new String[] {"cloth", "chain", "iron", "diamond", "gold"};
    020
    021        public RenderBiped(ModelBiped par1ModelBiped, float par2)
    022        {
    023            this(par1ModelBiped, par2, 1.0F);
    024        }
    025
    026        public RenderBiped(ModelBiped par1ModelBiped, float par2, float par3)
    027        {
    028            super(par1ModelBiped, par2);
    029            this.modelBipedMain = par1ModelBiped;
    030            this.field_77070_b = par3;
    031            this.func_82421_b();
    032        }
    033
    034        protected void func_82421_b()
    035        {
    036            this.field_82423_g = new ModelBiped(1.0F);
    037            this.field_82425_h = new ModelBiped(0.5F);
    038        }
    039
    040        /**
    041         * Queries whether should render the specified pass or not.
    042         */
    043        protected int shouldRenderPass(EntityLiving par1EntityLiving, int par2, float par3)
    044        {
    045            ItemStack var4 = par1EntityLiving.func_82169_q(3 - par2);
    046
    047            if (var4 != null)
    048            {
    049                Item var5 = var4.getItem();
    050
    051                if (var5 instanceof ItemArmor)
    052                {
    053                    ItemArmor var6 = (ItemArmor)var5;
    054                    this.loadTexture(ForgeHooksClient.getArmorTexture(var4, "/armor/" + field_82424_k[var6.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + ".png"));
    055                    ModelBiped var7 = par2 == 2 ? this.field_82425_h : this.field_82423_g;
    056                    var7.bipedHead.showModel = par2 == 0;
    057                    var7.bipedHeadwear.showModel = par2 == 0;
    058                    var7.bipedBody.showModel = par2 == 1 || par2 == 2;
    059                    var7.bipedRightArm.showModel = par2 == 1;
    060                    var7.bipedLeftArm.showModel = par2 == 1;
    061                    var7.bipedRightLeg.showModel = par2 == 2 || par2 == 3;
    062                    var7.bipedLeftLeg.showModel = par2 == 2 || par2 == 3;
    063                    this.setRenderPassModel(var7);
    064
    065                    if (var7 != null)
    066                    {
    067                        var7.onGround = this.mainModel.onGround;
    068                    }
    069
    070                    if (var7 != null)
    071                    {
    072                        var7.isRiding = this.mainModel.isRiding;
    073                    }
    074
    075                    if (var7 != null)
    076                    {
    077                        var7.isChild = this.mainModel.isChild;
    078                    }
    079
    080                    float var8 = 1.0F;
    081
    082                    if (var6.func_82812_d() == EnumArmorMaterial.CLOTH)
    083                    {
    084                        int var9 = var6.func_82814_b(var4);
    085                        float var10 = (float)(var9 >> 16 & 255) / 255.0F;
    086                        float var11 = (float)(var9 >> 8 & 255) / 255.0F;
    087                        float var12 = (float)(var9 & 255) / 255.0F;
    088                        GL11.glColor3f(var8 * var10, var8 * var11, var8 * var12);
    089
    090                        if (var4.isItemEnchanted())
    091                        {
    092                            return 31;
    093                        }
    094
    095                        return 16;
    096                    }
    097
    098                    GL11.glColor3f(var8, var8, var8);
    099
    100                    if (var4.isItemEnchanted())
    101                    {
    102                        return 15;
    103                    }
    104
    105                    return 1;
    106                }
    107            }
    108
    109            return -1;
    110        }
    111
    112        protected void func_82408_c(EntityLiving par1EntityLiving, int par2, float par3)
    113        {
    114            ItemStack var4 = par1EntityLiving.func_82169_q(3 - par2);
    115
    116            if (var4 != null)
    117            {
    118                Item var5 = var4.getItem();
    119
    120                if (var5 instanceof ItemArmor)
    121                {
    122                    ItemArmor var6 = (ItemArmor)var5;
    123                    this.loadTexture("/armor/" + field_82424_k[var6.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + "_b.png");
    124                    float var7 = 1.0F;
    125                    GL11.glColor3f(var7, var7, var7);
    126                }
    127            }
    128        }
    129
    130        public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)
    131        {
    132            float var10 = 1.0F;
    133            GL11.glColor3f(var10, var10, var10);
    134            ItemStack var11 = par1EntityLiving.getHeldItem();
    135            this.func_82420_a(par1EntityLiving, var11);
    136            double var12 = par4 - (double)par1EntityLiving.yOffset;
    137
    138            if (par1EntityLiving.isSneaking() && !(par1EntityLiving instanceof EntityPlayerSP))
    139            {
    140                var12 -= 0.125D;
    141            }
    142
    143            super.doRenderLiving(par1EntityLiving, par2, var12, par6, par8, par9);
    144            this.field_82423_g.aimedBow = this.field_82425_h.aimedBow = this.modelBipedMain.aimedBow = false;
    145            this.field_82423_g.isSneak = this.field_82425_h.isSneak = this.modelBipedMain.isSneak = false;
    146            this.field_82423_g.heldItemRight = this.field_82425_h.heldItemRight = this.modelBipedMain.heldItemRight = 0;
    147        }
    148
    149        protected void func_82420_a(EntityLiving par1EntityLiving, ItemStack par2ItemStack)
    150        {
    151            this.field_82423_g.heldItemRight = this.field_82425_h.heldItemRight = this.modelBipedMain.heldItemRight = par2ItemStack != null ? 1 : 0;
    152            this.field_82423_g.isSneak = this.field_82425_h.isSneak = this.modelBipedMain.isSneak = par1EntityLiving.isSneaking();
    153        }
    154
    155        protected void renderEquippedItems(EntityLiving par1EntityLiving, float par2)
    156        {
    157            float var3 = 1.0F;
    158            GL11.glColor3f(var3, var3, var3);
    159            super.renderEquippedItems(par1EntityLiving, par2);
    160            ItemStack var4 = par1EntityLiving.getHeldItem();
    161            ItemStack var5 = par1EntityLiving.func_82169_q(3);
    162            float var6;
    163
    164            if (var5 != null)
    165            {
    166                GL11.glPushMatrix();
    167                this.modelBipedMain.bipedHead.postRender(0.0625F);
    168
    169                IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(var5, EQUIPPED);
    170                boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(EQUIPPED, var5, BLOCK_3D));
    171
    172                if (var5.getItem() instanceof ItemBlock)
    173                {
    174                    if (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[var5.itemID].getRenderType()))
    175                    {
    176                        var6 = 0.625F;
    177                        GL11.glTranslatef(0.0F, -0.25F, 0.0F);
    178                        GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
    179                        GL11.glScalef(var6, -var6, -var6);
    180                    }
    181
    182                    this.renderManager.itemRenderer.renderItem(par1EntityLiving, var5, 0);
    183                }
    184                else if (var5.getItem().shiftedIndex == Item.field_82799_bQ.shiftedIndex)
    185                {
    186                    var6 = 1.0625F;
    187                    GL11.glScalef(var6, -var6, -var6);
    188                    String var7 = "";
    189
    190                    if (var5.hasTagCompound() && var5.getTagCompound().hasKey("SkullOwner"))
    191                    {
    192                        var7 = var5.getTagCompound().getString("SkullOwner");
    193                    }
    194
    195                    TileEntitySkullRenderer.field_82397_a.func_82393_a(-0.5F, 0.0F, -0.5F, 1, 180.0F, var5.getItemDamage(), var7);
    196                }
    197
    198                GL11.glPopMatrix();
    199            }
    200
    201            if (var4 != null)
    202            {
    203                GL11.glPushMatrix();
    204
    205                if (this.mainModel.isChild)
    206                {
    207                    var6 = 0.5F;
    208                    GL11.glTranslatef(0.0F, 0.625F, 0.0F);
    209                    GL11.glRotatef(-20.0F, -1.0F, 0.0F, 0.0F);
    210                    GL11.glScalef(var6, var6, var6);
    211                }
    212
    213                this.modelBipedMain.bipedRightArm.postRender(0.0625F);
    214                GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F);
    215
    216                IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(var4, EQUIPPED);
    217                boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(EQUIPPED, var4, BLOCK_3D));
    218
    219                if (var4.getItem() instanceof ItemBlock && (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[var4.itemID].getRenderType())))
    220                {
    221                    var6 = 0.5F;
    222                    GL11.glTranslatef(0.0F, 0.1875F, -0.3125F);
    223                    var6 *= 0.75F;
    224                    GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
    225                    GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
    226                    GL11.glScalef(var6, -var6, var6);
    227                }
    228                else if (var4.itemID == Item.bow.shiftedIndex)
    229                {
    230                    var6 = 0.625F;
    231                    GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
    232                    GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
    233                    GL11.glScalef(var6, -var6, var6);
    234                    GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
    235                    GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
    236                }
    237                else if (Item.itemsList[var4.itemID].isFull3D())
    238                {
    239                    var6 = 0.625F;
    240
    241                    if (Item.itemsList[var4.itemID].shouldRotateAroundWhenRendering())
    242                    {
    243                        GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
    244                        GL11.glTranslatef(0.0F, -0.125F, 0.0F);
    245                    }
    246
    247                    this.func_82422_c();
    248                    GL11.glScalef(var6, -var6, var6);
    249                    GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
    250                    GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
    251                }
    252                else
    253                {
    254                    var6 = 0.375F;
    255                    GL11.glTranslatef(0.25F, 0.1875F, -0.1875F);
    256                    GL11.glScalef(var6, var6, var6);
    257                    GL11.glRotatef(60.0F, 0.0F, 0.0F, 1.0F);
    258                    GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F);
    259                    GL11.glRotatef(20.0F, 0.0F, 0.0F, 1.0F);
    260                }
    261
    262                this.renderManager.itemRenderer.renderItem(par1EntityLiving, var4, 0);
    263
    264                if (var4.getItem().requiresMultipleRenderPasses())
    265                {
    266                    for (int x = 1; x < var4.getItem().getRenderPasses(var4.getItemDamage()); x++)
    267                    {
    268                        this.renderManager.itemRenderer.renderItem(par1EntityLiving, var4, x);
    269                    }
    270                }
    271
    272                GL11.glPopMatrix();
    273            }
    274        }
    275
    276        protected void func_82422_c()
    277        {
    278            GL11.glTranslatef(0.0F, 0.1875F, 0.0F);
    279        }
    280
    281        /**
    282         * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
    283         * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
    284         * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
    285         * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
    286         */
    287        public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    288        {
    289            this.doRenderLiving((EntityLiving)par1Entity, par2, par4, par6, par8, par9);
    290        }
    291    }