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 model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms
095 * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how
096 * "far" arms and legs can swing at most.
097 */
098 public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6)
099 {
100 this.bipedHead.rotateAngleY = par4 / (180F / (float)Math.PI);
101 this.bipedHead.rotateAngleX = par5 / (180F / (float)Math.PI);
102 this.bipedHeadwear.rotateAngleY = this.bipedHead.rotateAngleY;
103 this.bipedHeadwear.rotateAngleX = this.bipedHead.rotateAngleX;
104 this.bipedRightArm.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float)Math.PI) * 2.0F * par2 * 0.5F;
105 this.bipedLeftArm.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 2.0F * par2 * 0.5F;
106 this.bipedRightArm.rotateAngleZ = 0.0F;
107 this.bipedLeftArm.rotateAngleZ = 0.0F;
108 this.bipedRightLeg.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 1.4F * par2;
109 this.bipedLeftLeg.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float)Math.PI) * 1.4F * par2;
110 this.bipedRightLeg.rotateAngleY = 0.0F;
111 this.bipedLeftLeg.rotateAngleY = 0.0F;
112
113 if (this.isRiding)
114 {
115 this.bipedRightArm.rotateAngleX += -((float)Math.PI / 5F);
116 this.bipedLeftArm.rotateAngleX += -((float)Math.PI / 5F);
117 this.bipedRightLeg.rotateAngleX = -((float)Math.PI * 2F / 5F);
118 this.bipedLeftLeg.rotateAngleX = -((float)Math.PI * 2F / 5F);
119 this.bipedRightLeg.rotateAngleY = ((float)Math.PI / 10F);
120 this.bipedLeftLeg.rotateAngleY = -((float)Math.PI / 10F);
121 }
122
123 if (this.heldItemLeft != 0)
124 {
125 this.bipedLeftArm.rotateAngleX = this.bipedLeftArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F) * (float)this.heldItemLeft;
126 }
127
128 if (this.heldItemRight != 0)
129 {
130 this.bipedRightArm.rotateAngleX = this.bipedRightArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F) * (float)this.heldItemRight;
131 }
132
133 this.bipedRightArm.rotateAngleY = 0.0F;
134 this.bipedLeftArm.rotateAngleY = 0.0F;
135 float var7;
136 float var8;
137
138 if (this.onGround > -9990.0F)
139 {
140 var7 = this.onGround;
141 this.bipedBody.rotateAngleY = MathHelper.sin(MathHelper.sqrt_float(var7) * (float)Math.PI * 2.0F) * 0.2F;
142 this.bipedRightArm.rotationPointZ = MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F;
143 this.bipedRightArm.rotationPointX = -MathHelper.cos(this.bipedBody.rotateAngleY) * 5.0F;
144 this.bipedLeftArm.rotationPointZ = -MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F;
145 this.bipedLeftArm.rotationPointX = MathHelper.cos(this.bipedBody.rotateAngleY) * 5.0F;
146 this.bipedRightArm.rotateAngleY += this.bipedBody.rotateAngleY;
147 this.bipedLeftArm.rotateAngleY += this.bipedBody.rotateAngleY;
148 this.bipedLeftArm.rotateAngleX += this.bipedBody.rotateAngleY;
149 var7 = 1.0F - this.onGround;
150 var7 *= var7;
151 var7 *= var7;
152 var7 = 1.0F - var7;
153 var8 = MathHelper.sin(var7 * (float)Math.PI);
154 float var9 = MathHelper.sin(this.onGround * (float)Math.PI) * -(this.bipedHead.rotateAngleX - 0.7F) * 0.75F;
155 this.bipedRightArm.rotateAngleX = (float)((double)this.bipedRightArm.rotateAngleX - ((double)var8 * 1.2D + (double)var9));
156 this.bipedRightArm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F;
157 this.bipedRightArm.rotateAngleZ = MathHelper.sin(this.onGround * (float)Math.PI) * -0.4F;
158 }
159
160 if (this.isSneak)
161 {
162 this.bipedBody.rotateAngleX = 0.5F;
163 this.bipedRightArm.rotateAngleX += 0.4F;
164 this.bipedLeftArm.rotateAngleX += 0.4F;
165 this.bipedRightLeg.rotationPointZ = 4.0F;
166 this.bipedLeftLeg.rotationPointZ = 4.0F;
167 this.bipedRightLeg.rotationPointY = 9.0F;
168 this.bipedLeftLeg.rotationPointY = 9.0F;
169 this.bipedHead.rotationPointY = 1.0F;
170 }
171 else
172 {
173 this.bipedBody.rotateAngleX = 0.0F;
174 this.bipedRightLeg.rotationPointZ = 0.0F;
175 this.bipedLeftLeg.rotationPointZ = 0.0F;
176 this.bipedRightLeg.rotationPointY = 12.0F;
177 this.bipedLeftLeg.rotationPointY = 12.0F;
178 this.bipedHead.rotationPointY = 0.0F;
179 }
180
181 this.bipedRightArm.rotateAngleZ += MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F;
182 this.bipedLeftArm.rotateAngleZ -= MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F;
183 this.bipedRightArm.rotateAngleX += MathHelper.sin(par3 * 0.067F) * 0.05F;
184 this.bipedLeftArm.rotateAngleX -= MathHelper.sin(par3 * 0.067F) * 0.05F;
185
186 if (this.aimedBow)
187 {
188 var7 = 0.0F;
189 var8 = 0.0F;
190 this.bipedRightArm.rotateAngleZ = 0.0F;
191 this.bipedLeftArm.rotateAngleZ = 0.0F;
192 this.bipedRightArm.rotateAngleY = -(0.1F - var7 * 0.6F) + this.bipedHead.rotateAngleY;
193 this.bipedLeftArm.rotateAngleY = 0.1F - var7 * 0.6F + this.bipedHead.rotateAngleY + 0.4F;
194 this.bipedRightArm.rotateAngleX = -((float)Math.PI / 2F) + this.bipedHead.rotateAngleX;
195 this.bipedLeftArm.rotateAngleX = -((float)Math.PI / 2F) + this.bipedHead.rotateAngleX;
196 this.bipedRightArm.rotateAngleX -= var7 * 1.2F - var8 * 0.4F;
197 this.bipedLeftArm.rotateAngleX -= var7 * 1.2F - var8 * 0.4F;
198 this.bipedRightArm.rotateAngleZ += MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F;
199 this.bipedLeftArm.rotateAngleZ -= MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F;
200 this.bipedRightArm.rotateAngleX += MathHelper.sin(par3 * 0.067F) * 0.05F;
201 this.bipedLeftArm.rotateAngleX -= MathHelper.sin(par3 * 0.067F) * 0.05F;
202 }
203 }
204
205 /**
206 * renders the ears (specifically, deadmau5's)
207 */
208 public void renderEars(float par1)
209 {
210 this.bipedEars.rotateAngleY = this.bipedHead.rotateAngleY;
211 this.bipedEars.rotateAngleX = this.bipedHead.rotateAngleX;
212 this.bipedEars.rotationPointX = 0.0F;
213 this.bipedEars.rotationPointY = 0.0F;
214 this.bipedEars.render(par1);
215 }
216
217 /**
218 * Renders the cloak of the current biped (in most cases, it's a player)
219 */
220 public void renderCloak(float par1)
221 {
222 this.bipedCloak.render(par1);
223 }
224 }