001    package net.minecraft.client.model;
002    
003    import cpw.mods.fml.relauncher.Side;
004    import cpw.mods.fml.relauncher.SideOnly;
005    import net.minecraft.entity.Entity;
006    import net.minecraft.util.MathHelper;
007    import org.lwjgl.opengl.GL11;
008    
009    @SideOnly(Side.CLIENT)
010    public class ModelBiped extends ModelBase
011    {
012        public ModelRenderer bipedHead;
013        public ModelRenderer bipedHeadwear;
014        public ModelRenderer bipedBody;
015        public ModelRenderer bipedRightArm;
016        public ModelRenderer bipedLeftArm;
017        public ModelRenderer bipedRightLeg;
018        public ModelRenderer bipedLeftLeg;
019        public ModelRenderer bipedEars;
020        public ModelRenderer bipedCloak;
021    
022        /**
023         * Records whether the model should be rendered holding an item in the left hand, and if that item is a block.
024         */
025        public int heldItemLeft;
026    
027        /**
028         * Records whether the model should be rendered holding an item in the right hand, and if that item is a block.
029         */
030        public int heldItemRight;
031        public boolean isSneak;
032    
033        /** Records whether the model should be rendered aiming a bow. */
034        public boolean aimedBow;
035    
036        public ModelBiped()
037        {
038            this(0.0F);
039        }
040    
041        public ModelBiped(float par1)
042        {
043            this(par1, 0.0F, 64, 32);
044        }
045    
046        public ModelBiped(float par1, float par2, int par3, int par4)
047        {
048            this.heldItemLeft = 0;
049            this.heldItemRight = 0;
050            this.isSneak = false;
051            this.aimedBow = false;
052            this.textureWidth = par3;
053            this.textureHeight = par4;
054            this.bipedCloak = new ModelRenderer(this, 0, 0);
055            this.bipedCloak.addBox(-5.0F, 0.0F, -1.0F, 10, 16, 1, par1);
056            this.bipedEars = new ModelRenderer(this, 24, 0);
057            this.bipedEars.addBox(-3.0F, -6.0F, -1.0F, 6, 6, 1, par1);
058            this.bipedHead = new ModelRenderer(this, 0, 0);
059            this.bipedHead.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, par1);
060            this.bipedHead.setRotationPoint(0.0F, 0.0F + par2, 0.0F);
061            this.bipedHeadwear = new ModelRenderer(this, 32, 0);
062            this.bipedHeadwear.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, par1 + 0.5F);
063            this.bipedHeadwear.setRotationPoint(0.0F, 0.0F + par2, 0.0F);
064            this.bipedBody = new ModelRenderer(this, 16, 16);
065            this.bipedBody.addBox(-4.0F, 0.0F, -2.0F, 8, 12, 4, par1);
066            this.bipedBody.setRotationPoint(0.0F, 0.0F + par2, 0.0F);
067            this.bipedRightArm = new ModelRenderer(this, 40, 16);
068            this.bipedRightArm.addBox(-3.0F, -2.0F, -2.0F, 4, 12, 4, par1);
069            this.bipedRightArm.setRotationPoint(-5.0F, 2.0F + par2, 0.0F);
070            this.bipedLeftArm = new ModelRenderer(this, 40, 16);
071            this.bipedLeftArm.mirror = true;
072            this.bipedLeftArm.addBox(-1.0F, -2.0F, -2.0F, 4, 12, 4, par1);
073            this.bipedLeftArm.setRotationPoint(5.0F, 2.0F + par2, 0.0F);
074            this.bipedRightLeg = new ModelRenderer(this, 0, 16);
075            this.bipedRightLeg.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, par1);
076            this.bipedRightLeg.setRotationPoint(-1.9F, 12.0F + par2, 0.0F);
077            this.bipedLeftLeg = new ModelRenderer(this, 0, 16);
078            this.bipedLeftLeg.mirror = true;
079            this.bipedLeftLeg.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, par1);
080            this.bipedLeftLeg.setRotationPoint(1.9F, 12.0F + par2, 0.0F);
081        }
082    
083        /**
084         * Sets the models various rotation angles then renders the model.
085         */
086        public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7)
087        {
088            this.setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity);
089    
090            if (this.isChild)
091            {
092                float var8 = 2.0F;
093                GL11.glPushMatrix();
094                GL11.glScalef(1.5F / var8, 1.5F / var8, 1.5F / var8);
095                GL11.glTranslatef(0.0F, 16.0F * par7, 0.0F);
096                this.bipedHead.render(par7);
097                GL11.glPopMatrix();
098                GL11.glPushMatrix();
099                GL11.glScalef(1.0F / var8, 1.0F / var8, 1.0F / var8);
100                GL11.glTranslatef(0.0F, 24.0F * par7, 0.0F);
101                this.bipedBody.render(par7);
102                this.bipedRightArm.render(par7);
103                this.bipedLeftArm.render(par7);
104                this.bipedRightLeg.render(par7);
105                this.bipedLeftLeg.render(par7);
106                this.bipedHeadwear.render(par7);
107                GL11.glPopMatrix();
108            }
109            else
110            {
111                this.bipedHead.render(par7);
112                this.bipedBody.render(par7);
113                this.bipedRightArm.render(par7);
114                this.bipedLeftArm.render(par7);
115                this.bipedRightLeg.render(par7);
116                this.bipedLeftLeg.render(par7);
117                this.bipedHeadwear.render(par7);
118            }
119        }
120    
121        /**
122         * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms
123         * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how
124         * "far" arms and legs can swing at most.
125         */
126        public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity)
127        {
128            this.bipedHead.rotateAngleY = par4 / (180F / (float)Math.PI);
129            this.bipedHead.rotateAngleX = par5 / (180F / (float)Math.PI);
130            this.bipedHeadwear.rotateAngleY = this.bipedHead.rotateAngleY;
131            this.bipedHeadwear.rotateAngleX = this.bipedHead.rotateAngleX;
132            this.bipedRightArm.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float)Math.PI) * 2.0F * par2 * 0.5F;
133            this.bipedLeftArm.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 2.0F * par2 * 0.5F;
134            this.bipedRightArm.rotateAngleZ = 0.0F;
135            this.bipedLeftArm.rotateAngleZ = 0.0F;
136            this.bipedRightLeg.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 1.4F * par2;
137            this.bipedLeftLeg.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float)Math.PI) * 1.4F * par2;
138            this.bipedRightLeg.rotateAngleY = 0.0F;
139            this.bipedLeftLeg.rotateAngleY = 0.0F;
140    
141            if (this.isRiding)
142            {
143                this.bipedRightArm.rotateAngleX += -((float)Math.PI / 5F);
144                this.bipedLeftArm.rotateAngleX += -((float)Math.PI / 5F);
145                this.bipedRightLeg.rotateAngleX = -((float)Math.PI * 2F / 5F);
146                this.bipedLeftLeg.rotateAngleX = -((float)Math.PI * 2F / 5F);
147                this.bipedRightLeg.rotateAngleY = ((float)Math.PI / 10F);
148                this.bipedLeftLeg.rotateAngleY = -((float)Math.PI / 10F);
149            }
150    
151            if (this.heldItemLeft != 0)
152            {
153                this.bipedLeftArm.rotateAngleX = this.bipedLeftArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F) * (float)this.heldItemLeft;
154            }
155    
156            if (this.heldItemRight != 0)
157            {
158                this.bipedRightArm.rotateAngleX = this.bipedRightArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F) * (float)this.heldItemRight;
159            }
160    
161            this.bipedRightArm.rotateAngleY = 0.0F;
162            this.bipedLeftArm.rotateAngleY = 0.0F;
163            float var8;
164            float var9;
165    
166            if (this.onGround > -9990.0F)
167            {
168                var8 = this.onGround;
169                this.bipedBody.rotateAngleY = MathHelper.sin(MathHelper.sqrt_float(var8) * (float)Math.PI * 2.0F) * 0.2F;
170                this.bipedRightArm.rotationPointZ = MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F;
171                this.bipedRightArm.rotationPointX = -MathHelper.cos(this.bipedBody.rotateAngleY) * 5.0F;
172                this.bipedLeftArm.rotationPointZ = -MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F;
173                this.bipedLeftArm.rotationPointX = MathHelper.cos(this.bipedBody.rotateAngleY) * 5.0F;
174                this.bipedRightArm.rotateAngleY += this.bipedBody.rotateAngleY;
175                this.bipedLeftArm.rotateAngleY += this.bipedBody.rotateAngleY;
176                this.bipedLeftArm.rotateAngleX += this.bipedBody.rotateAngleY;
177                var8 = 1.0F - this.onGround;
178                var8 *= var8;
179                var8 *= var8;
180                var8 = 1.0F - var8;
181                var9 = MathHelper.sin(var8 * (float)Math.PI);
182                float var10 = MathHelper.sin(this.onGround * (float)Math.PI) * -(this.bipedHead.rotateAngleX - 0.7F) * 0.75F;
183                this.bipedRightArm.rotateAngleX = (float)((double)this.bipedRightArm.rotateAngleX - ((double)var9 * 1.2D + (double)var10));
184                this.bipedRightArm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F;
185                this.bipedRightArm.rotateAngleZ = MathHelper.sin(this.onGround * (float)Math.PI) * -0.4F;
186            }
187    
188            if (this.isSneak)
189            {
190                this.bipedBody.rotateAngleX = 0.5F;
191                this.bipedRightArm.rotateAngleX += 0.4F;
192                this.bipedLeftArm.rotateAngleX += 0.4F;
193                this.bipedRightLeg.rotationPointZ = 4.0F;
194                this.bipedLeftLeg.rotationPointZ = 4.0F;
195                this.bipedRightLeg.rotationPointY = 9.0F;
196                this.bipedLeftLeg.rotationPointY = 9.0F;
197                this.bipedHead.rotationPointY = 1.0F;
198                this.bipedHeadwear.rotationPointY = 1.0F;
199            }
200            else
201            {
202                this.bipedBody.rotateAngleX = 0.0F;
203                this.bipedRightLeg.rotationPointZ = 0.1F;
204                this.bipedLeftLeg.rotationPointZ = 0.1F;
205                this.bipedRightLeg.rotationPointY = 12.0F;
206                this.bipedLeftLeg.rotationPointY = 12.0F;
207                this.bipedHead.rotationPointY = 0.0F;
208                this.bipedHeadwear.rotationPointY = 0.0F;
209            }
210    
211            this.bipedRightArm.rotateAngleZ += MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F;
212            this.bipedLeftArm.rotateAngleZ -= MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F;
213            this.bipedRightArm.rotateAngleX += MathHelper.sin(par3 * 0.067F) * 0.05F;
214            this.bipedLeftArm.rotateAngleX -= MathHelper.sin(par3 * 0.067F) * 0.05F;
215    
216            if (this.aimedBow)
217            {
218                var8 = 0.0F;
219                var9 = 0.0F;
220                this.bipedRightArm.rotateAngleZ = 0.0F;
221                this.bipedLeftArm.rotateAngleZ = 0.0F;
222                this.bipedRightArm.rotateAngleY = -(0.1F - var8 * 0.6F) + this.bipedHead.rotateAngleY;
223                this.bipedLeftArm.rotateAngleY = 0.1F - var8 * 0.6F + this.bipedHead.rotateAngleY + 0.4F;
224                this.bipedRightArm.rotateAngleX = -((float)Math.PI / 2F) + this.bipedHead.rotateAngleX;
225                this.bipedLeftArm.rotateAngleX = -((float)Math.PI / 2F) + this.bipedHead.rotateAngleX;
226                this.bipedRightArm.rotateAngleX -= var8 * 1.2F - var9 * 0.4F;
227                this.bipedLeftArm.rotateAngleX -= var8 * 1.2F - var9 * 0.4F;
228                this.bipedRightArm.rotateAngleZ += MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F;
229                this.bipedLeftArm.rotateAngleZ -= MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F;
230                this.bipedRightArm.rotateAngleX += MathHelper.sin(par3 * 0.067F) * 0.05F;
231                this.bipedLeftArm.rotateAngleX -= MathHelper.sin(par3 * 0.067F) * 0.05F;
232            }
233        }
234    
235        /**
236         * renders the ears (specifically, deadmau5's)
237         */
238        public void renderEars(float par1)
239        {
240            this.bipedEars.rotateAngleY = this.bipedHead.rotateAngleY;
241            this.bipedEars.rotateAngleX = this.bipedHead.rotateAngleX;
242            this.bipedEars.rotationPointX = 0.0F;
243            this.bipedEars.rotationPointY = 0.0F;
244            this.bipedEars.render(par1);
245        }
246    
247        /**
248         * Renders the cloak of the current biped (in most cases, it's a player)
249         */
250        public void renderCloak(float par1)
251        {
252            this.bipedCloak.render(par1);
253        }
254    }