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