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(itemstack, "/armor/" + bipedArmorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + ".png"));
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                if (itemarmor.getArmorMaterial() == EnumArmorMaterial.CLOTH)
097                {
098                    int j = itemarmor.getColor(itemstack);
099                    float f2 = (float)(j >> 16 & 255) / 255.0F;
100                    float f3 = (float)(j >> 8 & 255) / 255.0F;
101                    float f4 = (float)(j & 255) / 255.0F;
102                    GL11.glColor3f(f1 * f2, f1 * f3, f1 * f4);
103
104                    if (itemstack.isItemEnchanted())
105                    {
106                        return 31;
107                    }
108
109                    return 16;
110                }
111
112                GL11.glColor3f(f1, f1, f1);
113
114                if (itemstack.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 itemstack = par1EntityLiving.getCurrentArmor(3 - par2);
129
130        if (itemstack != null)
131        {
132            Item item = itemstack.getItem();
133
134            if (item instanceof ItemArmor)
135            {
136                ItemArmor itemarmor = (ItemArmor)item;
137                this.loadTexture("/armor/" + bipedArmorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + "_b.png");
138                float f1 = 1.0F;
139                GL11.glColor3f(f1, f1, f1);
140            }
141        }
142    }
143
144    public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)
145    {
146        float f2 = 1.0F;
147        GL11.glColor3f(f2, f2, f2);
148        ItemStack itemstack = par1EntityLiving.getHeldItem();
149        this.func_82420_a(par1EntityLiving, itemstack);
150        double d3 = par4 - (double)par1EntityLiving.yOffset;
151
152        if (par1EntityLiving.isSneaking() && !(par1EntityLiving instanceof EntityPlayerSP))
153        {
154            d3 -= 0.125D;
155        }
156
157        super.doRenderLiving(par1EntityLiving, par2, d3, 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 f1 = 1.0F;
172        GL11.glColor3f(f1, f1, f1);
173        super.renderEquippedItems(par1EntityLiving, par2);
174        ItemStack itemstack = par1EntityLiving.getHeldItem();
175        ItemStack itemstack1 = par1EntityLiving.getCurrentArmor(3);
176        float f2;
177
178        if (itemstack1 != null)
179        {
180            GL11.glPushMatrix();
181            this.modelBipedMain.bipedHead.postRender(0.0625F);
182
183            IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemstack1, EQUIPPED);
184            boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(EQUIPPED, itemstack1, BLOCK_3D));
185
186            if (itemstack1.getItem() instanceof ItemBlock)
187            {
188                if (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[itemstack1.itemID].getRenderType()))
189                {
190                    f2 = 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(f2, -f2, -f2);
194                }
195
196                this.renderManager.itemRenderer.renderItem(par1EntityLiving, itemstack1, 0);
197            }
198            else if (itemstack1.getItem().itemID == Item.skull.itemID)
199            {
200                f2 = 1.0625F;
201                GL11.glScalef(f2, -f2, -f2);
202                String s = "";
203
204                if (itemstack1.hasTagCompound() && itemstack1.getTagCompound().hasKey("SkullOwner"))
205                {
206                    s = itemstack1.getTagCompound().getString("SkullOwner");
207                }
208
209                TileEntitySkullRenderer.skullRenderer.func_82393_a(-0.5F, 0.0F, -0.5F, 1, 180.0F, itemstack1.getItemDamage(), s);
210            }
211
212            GL11.glPopMatrix();
213        }
214
215        if (itemstack != null)
216        {
217            GL11.glPushMatrix();
218
219            if (this.mainModel.isChild)
220            {
221                f2 = 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(f2, f2, f2);
225            }
226
227            this.modelBipedMain.bipedRightArm.postRender(0.0625F);
228            GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F);
229
230            IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemstack, EQUIPPED);
231            boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(EQUIPPED, itemstack, BLOCK_3D));
232
233            if (itemstack.getItem() instanceof ItemBlock && (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[itemstack.itemID].getRenderType())))
234            {
235                f2 = 0.5F;
236                GL11.glTranslatef(0.0F, 0.1875F, -0.3125F);
237                f2 *= 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(-f2, -f2, f2);
241            }
242            else if (itemstack.itemID == Item.bow.itemID)
243            {
244                f2 = 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(f2, -f2, f2);
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[itemstack.itemID].isFull3D())
252            {
253                f2 = 0.625F;
254
255                if (Item.itemsList[itemstack.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(f2, -f2, f2);
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                f2 = 0.375F;
269                GL11.glTranslatef(0.25F, 0.1875F, -0.1875F);
270                GL11.glScalef(f2, f2, f2);
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, itemstack, 0);
277
278            if (itemstack.getItem().requiresMultipleRenderPasses())
279            {
280                for (int x = 1; x < itemstack.getItem().getRenderPasses(itemstack.getItemDamage()); x++)
281                {
282                    this.renderManager.itemRenderer.renderItem(par1EntityLiving, itemstack, 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}