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