| 1 | package net.minecraft.client.model;
|
| 2 |
|
| 3 | import net.minecraft.client.renderer.GlStateManager;
|
| 4 | import net.minecraft.entity.Entity;
|
| 5 | import net.minecraft.util.MathHelper;
|
| 6 |
|
| 7 | public class ModelBiped extends ModelBase
|
| 8 | {
|
| 9 | public ModelRenderer bipedHead;
|
| 10 |
|
| 11 | /** The Biped's Headwear. Used for the outer layer of player skins. */
|
| 12 | public ModelRenderer bipedHeadwear;
|
| 13 | public ModelRenderer bipedBody;
|
| 14 |
|
| 15 | /** The Biped's Right Arm */
|
| 16 | public ModelRenderer bipedRightArm;
|
| 17 |
|
| 18 | /** The Biped's Left Arm */
|
| 19 | public ModelRenderer bipedLeftArm;
|
| 20 |
|
| 21 | /** The Biped's Right Leg */
|
| 22 | public ModelRenderer bipedRightLeg;
|
| 23 |
|
| 24 | /** The Biped's Left Leg */
|
| 25 | public ModelRenderer bipedLeftLeg;
|
| 26 |
|
| 27 | /**
|
| 28 | * Records whether the model should be rendered holding an item in the left hand, and if that item is a block.
|
| 29 | */
|
| 30 | public int heldItemLeft;
|
| 31 |
|
| 32 | /**
|
| 33 | * Records whether the model should be rendered holding an item in the right hand, and if that item is a block.
|
| 34 | */
|
| 35 | public int heldItemRight;
|
| 36 | public boolean isSneak;
|
| 37 |
|
| 38 | /** Records whether the model should be rendered aiming a bow. */
|
| 39 | public boolean aimedBow;
|
| 40 |
|
| 41 | public ModelBiped()
|
| 42 | {
|
| 43 | this(0.0F);
|
| 44 | }
|
| 45 |
|
| 46 | public ModelBiped(float modelSize)
|
| 47 | {
|
| 48 | this(modelSize, 0.0F, 64, 32);
|
| 49 | }
|
| 50 |
|
| 51 | public ModelBiped(float modelSize, float p_i1149_2_, int textureWidthIn, int textureHeightIn)
|
| 52 | {
|
| 53 | this.textureWidth = textureWidthIn;
|
| 54 | this.textureHeight = textureHeightIn;
|
| 55 | this.bipedHead = new ModelRenderer(this, 0, 0);
|
| 56 | this.bipedHead.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, modelSize);
|
| 57 | this.bipedHead.setRotationPoint(0.0F, 0.0F + p_i1149_2_, 0.0F);
|
| 58 | this.bipedHeadwear = new ModelRenderer(this, 32, 0);
|
| 59 | this.bipedHeadwear.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, modelSize + 0.5F);
|
| 60 | this.bipedHeadwear.setRotationPoint(0.0F, 0.0F + p_i1149_2_, 0.0F);
|
| 61 | this.bipedBody = new ModelRenderer(this, 16, 16);
|
| 62 | this.bipedBody.addBox(-4.0F, 0.0F, -2.0F, 8, 12, 4, modelSize);
|
| 63 | this.bipedBody.setRotationPoint(0.0F, 0.0F + p_i1149_2_, 0.0F);
|
| 64 | this.bipedRightArm = new ModelRenderer(this, 40, 16);
|
| 65 | this.bipedRightArm.addBox(-3.0F, -2.0F, -2.0F, 4, 12, 4, modelSize);
|
| 66 | this.bipedRightArm.setRotationPoint(-5.0F, 2.0F + p_i1149_2_, 0.0F);
|
| 67 | this.bipedLeftArm = new ModelRenderer(this, 40, 16);
|
| 68 | this.bipedLeftArm.mirror = true;
|
| 69 | this.bipedLeftArm.addBox(-1.0F, -2.0F, -2.0F, 4, 12, 4, modelSize);
|
| 70 | this.bipedLeftArm.setRotationPoint(5.0F, 2.0F + p_i1149_2_, 0.0F);
|
| 71 | this.bipedRightLeg = new ModelRenderer(this, 0, 16);
|
| 72 | this.bipedRightLeg.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, modelSize);
|
| 73 | this.bipedRightLeg.setRotationPoint(-1.9F, 12.0F + p_i1149_2_, 0.0F);
|
| 74 | this.bipedLeftLeg = new ModelRenderer(this, 0, 16);
|
| 75 | this.bipedLeftLeg.mirror = true;
|
| 76 | this.bipedLeftLeg.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, modelSize);
|
| 77 | this.bipedLeftLeg.setRotationPoint(1.9F, 12.0F + p_i1149_2_, 0.0F);
|
| 78 | }
|
| 79 |
|
| 80 | /**
|
| 81 | * Sets the models various rotation angles then renders the model.
|
| 82 | */
|
| 83 | public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale)
|
| 84 | {
|
| 85 | this.setRotationAngles(p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, scale, entityIn);
|
| 86 | GlStateManager.pushMatrix();
|
| 87 |
|
| 88 | if (this.isChild)
|
| 89 | {
|
| 90 | float f = 2.0F;
|
| 91 | GlStateManager.scale(1.5F / f, 1.5F / f, 1.5F / f);
|
| 92 | GlStateManager.translate(0.0F, 16.0F * scale, 0.0F);
|
| 93 | this.bipedHead.render(scale);
|
| 94 | GlStateManager.popMatrix();
|
| 95 | GlStateManager.pushMatrix();
|
| 96 | GlStateManager.scale(1.0F / f, 1.0F / f, 1.0F / f);
|
| 97 | GlStateManager.translate(0.0F, 24.0F * scale, 0.0F);
|
| 98 | this.bipedBody.render(scale);
|
| 99 | this.bipedRightArm.render(scale);
|
| 100 | this.bipedLeftArm.render(scale);
|
| 101 | this.bipedRightLeg.render(scale);
|
| 102 | this.bipedLeftLeg.render(scale);
|
| 103 | this.bipedHeadwear.render(scale);
|
| 104 | }
|
| 105 | else
|
| 106 | {
|
| 107 | if (entityIn.isSneaking())
|
| 108 | {
|
| 109 | GlStateManager.translate(0.0F, 0.2F, 0.0F);
|
| 110 | }
|
| 111 |
|
| 112 | this.bipedHead.render(scale);
|
| 113 | this.bipedBody.render(scale);
|
| 114 | this.bipedRightArm.render(scale);
|
| 115 | this.bipedLeftArm.render(scale);
|
| 116 | this.bipedRightLeg.render(scale);
|
| 117 | this.bipedLeftLeg.render(scale);
|
| 118 | this.bipedHeadwear.render(scale);
|
| 119 | }
|
| 120 |
|
| 121 | GlStateManager.popMatrix();
|
| 122 | }
|
| 123 |
|
| 124 | /**
|
| 125 | * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms
|
| 126 | * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how
|
| 127 | * "far" arms and legs can swing at most.
|
| 128 | */
|
| 129 | public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn)
|
| 130 | {
|
| 131 | this.bipedHead.rotateAngleY = netHeadYaw / (180F / (float)Math.PI);
|
| 132 | this.bipedHead.rotateAngleX = headPitch / (180F / (float)Math.PI);
|
| 133 | this.bipedRightArm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 2.0F * limbSwingAmount * 0.5F;
|
| 134 | this.bipedLeftArm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 2.0F * limbSwingAmount * 0.5F;
|
| 135 | this.bipedRightArm.rotateAngleZ = 0.0F;
|
| 136 | this.bipedLeftArm.rotateAngleZ = 0.0F;
|
| 137 | this.bipedRightLeg.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
|
| 138 | this.bipedLeftLeg.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.4F * limbSwingAmount;
|
| 139 | this.bipedRightLeg.rotateAngleY = 0.0F;
|
| 140 | this.bipedLeftLeg.rotateAngleY = 0.0F;
|
| 141 |
|
| 142 | if (this.isRiding)
|
| 143 | {
|
| 144 | this.bipedRightArm.rotateAngleX += -((float)Math.PI / 5F);
|
| 145 | this.bipedLeftArm.rotateAngleX += -((float)Math.PI / 5F);
|
| 146 | this.bipedRightLeg.rotateAngleX = -((float)Math.PI * 2F / 5F);
|
| 147 | this.bipedLeftLeg.rotateAngleX = -((float)Math.PI * 2F / 5F);
|
| 148 | this.bipedRightLeg.rotateAngleY = ((float)Math.PI / 10F);
|
| 149 | this.bipedLeftLeg.rotateAngleY = -((float)Math.PI / 10F);
|
| 150 | }
|
| 151 |
|
| 152 | if (this.heldItemLeft != 0)
|
| 153 | {
|
| 154 | this.bipedLeftArm.rotateAngleX = this.bipedLeftArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F) * (float)this.heldItemLeft;
|
| 155 | }
|
| 156 |
|
| 157 | this.bipedRightArm.rotateAngleY = 0.0F;
|
| 158 | this.bipedRightArm.rotateAngleZ = 0.0F;
|
| 159 |
|
| 160 | switch (this.heldItemRight)
|
| 161 | {
|
| 162 | case 0:
|
| 163 | case 2:
|
| 164 | default:
|
| 165 | break;
|
| 166 |
|
| 167 | case 1:
|
| 168 | this.bipedRightArm.rotateAngleX = this.bipedRightArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F) * (float)this.heldItemRight;
|
| 169 | break;
|
| 170 |
|
| 171 | case 3:
|
| 172 | this.bipedRightArm.rotateAngleX = this.bipedRightArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F) * (float)this.heldItemRight;
|
| 173 | this.bipedRightArm.rotateAngleY = -0.5235988F;
|
| 174 | }
|
| 175 |
|
| 176 | this.bipedLeftArm.rotateAngleY = 0.0F;
|
| 177 |
|
| 178 | if (this.swingProgress > -9990.0F)
|
| 179 | {
|
| 180 | float f = this.swingProgress;
|
| 181 | this.bipedBody.rotateAngleY = MathHelper.sin(MathHelper.sqrt_float(f) * (float)Math.PI * 2.0F) * 0.2F;
|
| 182 | this.bipedRightArm.rotationPointZ = MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F;
|
| 183 | this.bipedRightArm.rotationPointX = -MathHelper.cos(this.bipedBody.rotateAngleY) * 5.0F;
|
| 184 | this.bipedLeftArm.rotationPointZ = -MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F;
|
| 185 | this.bipedLeftArm.rotationPointX = MathHelper.cos(this.bipedBody.rotateAngleY) * 5.0F;
|
| 186 | this.bipedRightArm.rotateAngleY += this.bipedBody.rotateAngleY;
|
| 187 | this.bipedLeftArm.rotateAngleY += this.bipedBody.rotateAngleY;
|
| 188 | this.bipedLeftArm.rotateAngleX += this.bipedBody.rotateAngleY;
|
| 189 | f = 1.0F - this.swingProgress;
|
| 190 | f = f * f;
|
| 191 | f = f * f;
|
| 192 | f = 1.0F - f;
|
| 193 | float f1 = MathHelper.sin(f * (float)Math.PI);
|
| 194 | float f2 = MathHelper.sin(this.swingProgress * (float)Math.PI) * -(this.bipedHead.rotateAngleX - 0.7F) * 0.75F;
|
| 195 | this.bipedRightArm.rotateAngleX = (float)((double)this.bipedRightArm.rotateAngleX - ((double)f1 * 1.2D + (double)f2));
|
| 196 | this.bipedRightArm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F;
|
| 197 | this.bipedRightArm.rotateAngleZ += MathHelper.sin(this.swingProgress * (float)Math.PI) * -0.4F;
|
| 198 | }
|
| 199 |
|
| 200 | if (this.isSneak)
|
| 201 | {
|
| 202 | this.bipedBody.rotateAngleX = 0.5F;
|
| 203 | this.bipedRightArm.rotateAngleX += 0.4F;
|
| 204 | this.bipedLeftArm.rotateAngleX += 0.4F;
|
| 205 | this.bipedRightLeg.rotationPointZ = 4.0F;
|
| 206 | this.bipedLeftLeg.rotationPointZ = 4.0F;
|
| 207 | this.bipedRightLeg.rotationPointY = 9.0F;
|
| 208 | this.bipedLeftLeg.rotationPointY = 9.0F;
|
| 209 | this.bipedHead.rotationPointY = 1.0F;
|
| 210 | }
|
| 211 | else
|
| 212 | {
|
| 213 | this.bipedBody.rotateAngleX = 0.0F;
|
| 214 | this.bipedRightLeg.rotationPointZ = 0.1F;
|
| 215 | this.bipedLeftLeg.rotationPointZ = 0.1F;
|
| 216 | this.bipedRightLeg.rotationPointY = 12.0F;
|
| 217 | this.bipedLeftLeg.rotationPointY = 12.0F;
|
| 218 | this.bipedHead.rotationPointY = 0.0F;
|
| 219 | }
|
| 220 |
|
| 221 | this.bipedRightArm.rotateAngleZ += MathHelper.cos(ageInTicks * 0.09F) * 0.05F + 0.05F;
|
| 222 | this.bipedLeftArm.rotateAngleZ -= MathHelper.cos(ageInTicks * 0.09F) * 0.05F + 0.05F;
|
| 223 | this.bipedRightArm.rotateAngleX += MathHelper.sin(ageInTicks * 0.067F) * 0.05F;
|
| 224 | this.bipedLeftArm.rotateAngleX -= MathHelper.sin(ageInTicks * 0.067F) * 0.05F;
|
| 225 |
|
| 226 | if (this.aimedBow)
|
| 227 | {
|
| 228 | float f3 = 0.0F;
|
| 229 | float f4 = 0.0F;
|
| 230 | this.bipedRightArm.rotateAngleZ = 0.0F;
|
| 231 | this.bipedLeftArm.rotateAngleZ = 0.0F;
|
| 232 | this.bipedRightArm.rotateAngleY = -(0.1F - f3 * 0.6F) + this.bipedHead.rotateAngleY;
|
| 233 | this.bipedLeftArm.rotateAngleY = 0.1F - f3 * 0.6F + this.bipedHead.rotateAngleY + 0.4F;
|
| 234 | this.bipedRightArm.rotateAngleX = -((float)Math.PI / 2F) + this.bipedHead.rotateAngleX;
|
| 235 | this.bipedLeftArm.rotateAngleX = -((float)Math.PI / 2F) + this.bipedHead.rotateAngleX;
|
| 236 | this.bipedRightArm.rotateAngleX -= f3 * 1.2F - f4 * 0.4F;
|
| 237 | this.bipedLeftArm.rotateAngleX -= f3 * 1.2F - f4 * 0.4F;
|
| 238 | this.bipedRightArm.rotateAngleZ += MathHelper.cos(ageInTicks * 0.09F) * 0.05F + 0.05F;
|
| 239 | this.bipedLeftArm.rotateAngleZ -= MathHelper.cos(ageInTicks * 0.09F) * 0.05F + 0.05F;
|
| 240 | this.bipedRightArm.rotateAngleX += MathHelper.sin(ageInTicks * 0.067F) * 0.05F;
|
| 241 | this.bipedLeftArm.rotateAngleX -= MathHelper.sin(ageInTicks * 0.067F) * 0.05F;
|
| 242 | }
|
| 243 |
|
| 244 | copyModelAngles(this.bipedHead, this.bipedHeadwear);
|
| 245 | }
|
| 246 |
|
| 247 | public void setModelAttributes(ModelBase model)
|
| 248 | {
|
| 249 | super.setModelAttributes(model);
|
| 250 |
|
| 251 | if (model instanceof ModelBiped)
|
| 252 | {
|
| 253 | ModelBiped modelbiped = (ModelBiped)model;
|
| 254 | this.heldItemLeft = modelbiped.heldItemLeft;
|
| 255 | this.heldItemRight = modelbiped.heldItemRight;
|
| 256 | this.isSneak = modelbiped.isSneak;
|
| 257 | this.aimedBow = modelbiped.aimedBow;
|
| 258 | }
|
| 259 | }
|
| 260 |
|
| 261 | public void setInvisible(boolean invisible)
|
| 262 | {
|
| 263 | this.bipedHead.showModel = invisible;
|
| 264 | this.bipedHeadwear.showModel = invisible;
|
| 265 | this.bipedBody.showModel = invisible;
|
| 266 | this.bipedRightArm.showModel = invisible;
|
| 267 | this.bipedLeftArm.showModel = invisible;
|
| 268 | this.bipedRightLeg.showModel = invisible;
|
| 269 | this.bipedLeftLeg.showModel = invisible;
|
| 270 | }
|
| 271 |
|
| 272 | public void postRenderArm(float scale)
|
| 273 | {
|
| 274 | this.bipedRightArm.postRender(scale);
|
| 275 | }
|
| 276 | }
|
| 277 |
|