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