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