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