Created
June 23, 2014 12:51
-
-
Save marchermans/74729af46efc39458cae to your computer and use it in GitHub Desktop.
Model not rendering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.Orion.OrionsBelt.Client.Models; | |
/* | |
* CustomArmorModel | |
* Created by: Orion | |
* Created on: 23-6-2014 | |
*/ | |
import net.minecraft.client.model.ModelBiped; | |
import net.minecraft.client.model.ModelRenderer; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.util.MathHelper; | |
import org.lwjgl.opengl.GL11; | |
public class CustomArmorModel extends ModelBiped | |
{ | |
//Fields added to add custom armor parts on the body, removes the need of multiple texture files. | |
public ModelRenderer bipedRightFoot; | |
public ModelRenderer bipedLeftFoot; | |
public ModelRenderer bipedWaist; | |
public CustomArmorModel() | |
{ | |
this(0.0F); | |
} | |
public CustomArmorModel(float pScale) | |
{ | |
this(pScale, 0.0F, 64, 64); | |
} | |
public CustomArmorModel(float pScale, float pYOffSet, int pTextureSizeX, int pTextureSizeY) | |
{ | |
super(pScale, pYOffSet, pTextureSizeX, pTextureSizeY); | |
//Setting the texture size. | |
this.textureWidth = pTextureSizeX; | |
this.textureHeight = pTextureSizeY; | |
//Setting the individial renderboxes of the model: | |
/* These are part of the vanilla model but are not represented on the texture sheet anymore. | |
* Leaving them out for now! | |
* TODO: Find a way to implement these properly | |
//-> Cloak | |
this.bipedCloak = new ModelRenderer(this, 0, 0); | |
this.bipedCloak.addBox(-5.0F, 0.0F, -1.0F, 10, 16, 1, pScale); | |
//-> Ears | |
this.bipedEars = new ModelRenderer(this, 24, 0); | |
this.bipedEars.addBox(-3.0F, -6.0F, -1.0F, 6, 6, 1, pScale); | |
*/ | |
//-> Head | |
bipedHead = new ModelRenderer(this, 0, 0); | |
bipedHead.addBox(-4F, -8F, -4F, 8, 8, 8, pScale); | |
bipedHead.setRotationPoint(0F, 0F, 0F); | |
bipedHead.setTextureSize(pTextureSizeX, pTextureSizeY); | |
bipedHead.mirror = true; | |
/* The following part is not needed as this is a ARMOR model. There is no need to render the hair. | |
* But for completeness and comparability to the original I will leave it hear, maybe i can use it for something else. | |
//-> HeadWear (Hair in you skin etc) | |
this.bipedHeadwear = new ModelRenderer(this, 32, 0); | |
this.bipedHeadwear.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, pScale + 0.5F); | |
this.bipedHeadwear.setRotationPoint(0.0F, 0.0F + pYOffSet, 0.0F); | |
*/ | |
//-> Body | |
bipedBody = new ModelRenderer(this, 0, 16); | |
bipedBody.addBox(-4F, 0F, -2F, 8, 12, 4, pScale); | |
bipedBody.setRotationPoint(0F, 0F, 0F); | |
bipedBody.setTextureSize(pTextureSizeX, pTextureSizeY); | |
bipedBody.mirror = true; | |
//-> Right arm | |
bipedRightArm = new ModelRenderer(this, 32, 16); | |
bipedRightArm.addBox(-3F, -2F, -2F, 4, 12, 4, pScale); | |
bipedRightArm.setRotationPoint(-5F, 2F, 0F); | |
bipedRightArm.setTextureSize(pTextureSizeX, pTextureSizeY); | |
bipedRightArm.mirror = true; | |
//-> Left arm | |
bipedLeftArm = new ModelRenderer(this, 32, 0); | |
bipedLeftArm.addBox(-1F, -2F, -2F, 4, 12, 4, pScale); | |
bipedLeftArm.setRotationPoint(5F, 2F, 0F); | |
bipedLeftArm.setTextureSize(pTextureSizeX, pTextureSizeY); | |
bipedLeftArm.mirror = true; | |
//-> Right leg | |
bipedRightLeg = new ModelRenderer(this, 0, 32); | |
bipedRightLeg.addBox(-2F, 0F, -2F, 4, 8, 4, pScale); | |
bipedRightLeg.setRotationPoint(-2F, 12F, 0F); | |
bipedRightLeg.setTextureSize(pTextureSizeX, pTextureSizeY); | |
bipedRightLeg.mirror = true; | |
//-> Left leg | |
bipedLeftLeg = new ModelRenderer(this, 16, 32); | |
bipedLeftLeg.addBox(-2F, 0F, -2F, 4, 8, 4, pScale); | |
bipedLeftLeg.setRotationPoint(2F, 12F, 0F); | |
bipedLeftLeg.setTextureSize(pTextureSizeX, pTextureSizeY); | |
bipedLeftLeg.mirror = true; | |
//Now the initialisation of the custom armor parts: | |
//-> Right foot | |
bipedRightFoot = new ModelRenderer(this, 0, 52); | |
bipedRightFoot.addBox(-2F, 8F, -2F, 4, 5, 4, pScale); | |
bipedRightFoot.setRotationPoint(-2F, 11F, 0F); | |
bipedRightFoot.setTextureSize(pTextureSizeX, pTextureSizeY); | |
bipedRightFoot.mirror = true; | |
//-> Left foot | |
bipedLeftFoot = new ModelRenderer(this, 16, 52); | |
bipedLeftFoot.addBox(-2F, 8F, -2F, 4, 5, 4, pScale); | |
bipedLeftFoot.setRotationPoint(2F, 11F, 0F); | |
bipedLeftFoot.setTextureSize(pTextureSizeX, pTextureSizeY); | |
bipedLeftFoot.mirror = true; | |
//-> Waist | |
bipedWaist = new ModelRenderer(this, 0, 44); | |
bipedWaist.addBox(-4F, 8F, -2F, 8, 4, 4, pScale); | |
bipedWaist.setRotationPoint(0F, 0F, 0F); | |
bipedWaist.setTextureSize(pTextureSizeX, pTextureSizeY); | |
bipedWaist.mirror = true; | |
} | |
//There are a lot of unknown parameter here. I copied the behaviour of the vanilla renderer. | |
//TODO: Figure out what there parameters are. | |
@Override | |
public void render(Entity pEntity, float par2, float par3, float par4, float pYOffSet, float pRotationPitch, float par7) | |
{ | |
this.setRotationAngles(par2, par3, par4, pYOffSet, pRotationPitch, par7, pEntity); | |
if (this.isChild) | |
{ | |
float f6 = 2.0F; | |
GL11.glPushMatrix(); | |
GL11.glScalef(1.5F / f6, 1.5F / f6, 1.5F / f6); | |
GL11.glTranslatef(0.0F, 16.0F * par7, 0.0F); | |
this.bipedHead.render(par7); | |
GL11.glPopMatrix(); | |
GL11.glPushMatrix(); | |
GL11.glScalef(1.0F / f6, 1.0F / f6, 1.0F / f6); | |
GL11.glTranslatef(0.0F, 24.0F * par7, 0.0F); | |
this.bipedBody.render(par7); | |
this.bipedWaist.render(par7); | |
this.bipedRightArm.render(par7); | |
this.bipedLeftArm.render(par7); | |
this.bipedRightLeg.render(par7); | |
this.bipedRightFoot.render(par7); | |
this.bipedLeftFoot.render(par7); | |
this.bipedLeftLeg.render(par7); | |
// Not needed! | |
// this.bipedHeadwear.render(par7); | |
GL11.glPopMatrix(); | |
} | |
else | |
{ | |
//GL11.glPushMatrix(); | |
//GL11.glScalef(1F, 1F, 1F); | |
this.bipedHead.render(par7); | |
this.bipedBody.render(par7); | |
this.bipedWaist.render(par7); | |
this.bipedRightArm.render(par7); | |
this.bipedLeftArm.render(par7); | |
this.bipedRightLeg.render(par7); | |
this.bipedRightFoot.render(par7); | |
this.bipedLeftFoot.render(par7); | |
this.bipedLeftLeg.render(par7); | |
// Not needed! | |
// this.bipedHeadwear.render(par7); | |
//GL11.glPopMatrix(); | |
} | |
} | |
/**Vanilla modified function to allow the new parts to be turned respectivly to there counterparts | |
* A lot of unknown parameters in here | |
* TODO: Figure out what the parameters are | |
* | |
* Vanilla commentary: | |
* Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms | |
* and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how | |
* "far" arms and legs can swing at most. | |
*/ | |
@Override | |
public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity) | |
{ | |
this.bipedHead.rotateAngleY = par4 / (180F / (float)Math.PI); | |
this.bipedHead.rotateAngleX = par5 / (180F / (float)Math.PI); | |
//Not needed! | |
//this.bipedHeadwear.rotateAngleY = this.bipedHead.rotateAngleY; | |
//this.bipedHeadwear.rotateAngleX = this.bipedHead.rotateAngleX; | |
this.bipedRightArm.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float) Math.PI) * 2.0F * par2 * 0.5F; | |
this.bipedLeftArm.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 2.0F * par2 * 0.5F; | |
this.bipedRightArm.rotateAngleZ = 0.0F; | |
this.bipedLeftArm.rotateAngleZ = 0.0F; | |
this.bipedRightLeg.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 1.4F * par2; | |
this.bipedLeftLeg.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float)Math.PI) * 1.4F * par2; | |
this.bipedRightLeg.rotateAngleY = 0.0F; | |
this.bipedLeftLeg.rotateAngleY = 0.0F; | |
if (this.isRiding) | |
{ | |
this.bipedRightArm.rotateAngleX += -((float)Math.PI / 5F); | |
this.bipedLeftArm.rotateAngleX += -((float)Math.PI / 5F); | |
this.bipedRightLeg.rotateAngleX = -((float)Math.PI * 2F / 5F); | |
this.bipedLeftLeg.rotateAngleX = -((float)Math.PI * 2F / 5F); | |
this.bipedRightLeg.rotateAngleY = ((float)Math.PI / 10F); | |
this.bipedLeftLeg.rotateAngleY = -((float)Math.PI / 10F); | |
} | |
if (this.heldItemLeft != 0) | |
{ | |
this.bipedLeftArm.rotateAngleX = this.bipedLeftArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F) * (float)this.heldItemLeft; | |
} | |
if (this.heldItemRight != 0) | |
{ | |
this.bipedRightArm.rotateAngleX = this.bipedRightArm.rotateAngleX * 0.5F - ((float)Math.PI / 10F) * (float)this.heldItemRight; | |
} | |
this.bipedRightArm.rotateAngleY = 0.0F; | |
this.bipedLeftArm.rotateAngleY = 0.0F; | |
float f6; | |
float f7; | |
if (this.onGround > -9990.0F) | |
{ | |
f6 = this.onGround; | |
this.bipedBody.rotateAngleY = MathHelper.sin(MathHelper.sqrt_float(f6) * (float)Math.PI * 2.0F) * 0.2F; | |
this.bipedRightArm.rotationPointZ = MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F; | |
this.bipedRightArm.rotationPointX = -MathHelper.cos(this.bipedBody.rotateAngleY) * 5.0F; | |
this.bipedLeftArm.rotationPointZ = -MathHelper.sin(this.bipedBody.rotateAngleY) * 5.0F; | |
this.bipedLeftArm.rotationPointX = MathHelper.cos(this.bipedBody.rotateAngleY) * 5.0F; | |
this.bipedRightArm.rotateAngleY += this.bipedBody.rotateAngleY; | |
this.bipedLeftArm.rotateAngleY += this.bipedBody.rotateAngleY; | |
this.bipedLeftArm.rotateAngleX += this.bipedBody.rotateAngleY; | |
f6 = 1.0F - this.onGround; | |
f6 *= f6; | |
f6 *= f6; | |
f6 = 1.0F - f6; | |
f7 = MathHelper.sin(f6 * (float)Math.PI); | |
float f8 = MathHelper.sin(this.onGround * (float)Math.PI) * -(this.bipedHead.rotateAngleX - 0.7F) * 0.75F; | |
this.bipedRightArm.rotateAngleX = (float)((double)this.bipedRightArm.rotateAngleX - ((double)f7 * 1.2D + (double)f8)); | |
this.bipedRightArm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F; | |
this.bipedRightArm.rotateAngleZ = MathHelper.sin(this.onGround * (float)Math.PI) * -0.4F; | |
} | |
if (this.isSneak) | |
{ | |
this.bipedBody.rotateAngleX = 0.5F; | |
this.bipedRightArm.rotateAngleX += 0.4F; | |
this.bipedLeftArm.rotateAngleX += 0.4F; | |
this.bipedRightLeg.rotationPointZ = 4.0F; | |
this.bipedLeftLeg.rotationPointZ = 4.0F; | |
this.bipedRightLeg.rotationPointY = 9.0F; | |
this.bipedLeftLeg.rotationPointY = 9.0F; | |
this.bipedHead.rotationPointY = 1.0F; | |
this.bipedHeadwear.rotationPointY = 1.0F; | |
} | |
else | |
{ | |
this.bipedBody.rotateAngleX = 0.0F; | |
this.bipedRightLeg.rotationPointZ = 0.1F; | |
this.bipedLeftLeg.rotationPointZ = 0.1F; | |
this.bipedRightLeg.rotationPointY = 12.0F; | |
this.bipedLeftLeg.rotationPointY = 12.0F; | |
this.bipedHead.rotationPointY = 0.0F; | |
this.bipedHeadwear.rotationPointY = 0.0F; | |
} | |
this.bipedRightArm.rotateAngleZ += MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F; | |
this.bipedLeftArm.rotateAngleZ -= MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F; | |
this.bipedRightArm.rotateAngleX += MathHelper.sin(par3 * 0.067F) * 0.05F; | |
this.bipedLeftArm.rotateAngleX -= MathHelper.sin(par3 * 0.067F) * 0.05F; | |
if (this.aimedBow) | |
{ | |
f6 = 0.0F; | |
f7 = 0.0F; | |
this.bipedRightArm.rotateAngleZ = 0.0F; | |
this.bipedLeftArm.rotateAngleZ = 0.0F; | |
this.bipedRightArm.rotateAngleY = -(0.1F - f6 * 0.6F) + this.bipedHead.rotateAngleY; | |
this.bipedLeftArm.rotateAngleY = 0.1F - f6 * 0.6F + this.bipedHead.rotateAngleY + 0.4F; | |
this.bipedRightArm.rotateAngleX = -((float)Math.PI / 2F) + this.bipedHead.rotateAngleX; | |
this.bipedLeftArm.rotateAngleX = -((float)Math.PI / 2F) + this.bipedHead.rotateAngleX; | |
this.bipedRightArm.rotateAngleX -= f6 * 1.2F - f7 * 0.4F; | |
this.bipedLeftArm.rotateAngleX -= f6 * 1.2F - f7 * 0.4F; | |
this.bipedRightArm.rotateAngleZ += MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F; | |
this.bipedLeftArm.rotateAngleZ -= MathHelper.cos(par3 * 0.09F) * 0.05F + 0.05F; | |
this.bipedRightArm.rotateAngleX += MathHelper.sin(par3 * 0.067F) * 0.05F; | |
this.bipedLeftArm.rotateAngleX -= MathHelper.sin(par3 * 0.067F) * 0.05F; | |
} | |
//To copy the behaviour from the corresponding body parts they belong to, the new parts are set at the end. | |
// Waist -> Body | |
this.bipedWaist.rotateAngleX = this.bipedBody.rotateAngleX; | |
this.bipedWaist.rotateAngleY = this.bipedBody.rotateAngleY; | |
this.bipedWaist.rotateAngleZ = this.bipedBody.rotateAngleZ; | |
//Right foot -> Right leg | |
this.bipedRightFoot.rotateAngleX = this.bipedRightLeg.rotateAngleX; | |
this.bipedRightFoot.rotateAngleY = this.bipedRightLeg.rotateAngleY; | |
this.bipedRightFoot.rotateAngleZ = this.bipedRightLeg.rotateAngleZ; | |
//Left foot -> Left leg | |
this.bipedLeftFoot.rotateAngleX = this.bipedLeftLeg.rotateAngleX; | |
this.bipedLeftFoot.rotateAngleY = this.bipedLeftLeg.rotateAngleY; | |
this.bipedLeftFoot.rotateAngleZ = this.bipedLeftLeg.rotateAngleZ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment