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