diff options
| author | Foghrye4 <foghrye4@gmail.com> | 2016-04-11 19:44:54 +0300 |
|---|---|---|
| committer | Foghrye4 <foghrye4@gmail.com> | 2016-04-11 19:44:54 +0300 |
| commit | 05c78126859231a68e199dc34613689bd0978e2f (patch) | |
| tree | 050bea104a18c72905095d29f31bec2935a27a24 /ihl/model/IHLModelRenderer.java | |
Initial commit
Diffstat (limited to 'ihl/model/IHLModelRenderer.java')
| -rw-r--r-- | ihl/model/IHLModelRenderer.java | 366 |
1 files changed, 366 insertions, 0 deletions
diff --git a/ihl/model/IHLModelRenderer.java b/ihl/model/IHLModelRenderer.java new file mode 100644 index 0000000..c9b1b77 --- /dev/null +++ b/ihl/model/IHLModelRenderer.java @@ -0,0 +1,366 @@ +package ihl.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.lwjgl.opengl.GL11;
+
+import net.minecraft.client.model.ModelBase;
+import net.minecraft.client.model.ModelRenderer;
+import net.minecraft.client.model.TextureOffset;
+import net.minecraft.client.renderer.GLAllocation;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraftforge.common.util.ForgeDirection;
+
+public class IHLModelRenderer {
+ /** The size of the texture file's width in pixels. */
+ public float textureWidth;
+
+ /** The size of the texture file's height in pixels. */
+ public float textureHeight;
+
+ /** The X offset into the texture used for displaying this model */
+ private int textureOffsetX;
+
+ /** The Y offset into the texture used for displaying this model */
+ private int textureOffsetY;
+ public float rotationPointX;
+ public float rotationPointY;
+ public float rotationPointZ;
+ public float rotateAngleX;
+ public float rotateAngleY;
+ public float rotateAngleZ;
+ private boolean compiled;
+
+ /** The GL display list rendered by the Tessellator for this model */
+ private int displayList;
+ public boolean mirror;
+ public boolean showModel;
+
+ /** Hides the model. */
+ public boolean isHidden;
+ public List cubeList;
+ public List childModels;
+ public final String boxName;
+ private ModelBase baseModel;
+ public float offsetX;
+ public float offsetY;
+ public float offsetZ;
+
+ public boolean drawFromInside=false;
+ private static final String __OBFID = "CL_00000874";
+
+ public IHLModelRenderer(ModelBase par1ModelBase, String par2Str)
+ {
+ this.textureWidth = 64.0F;
+ this.textureHeight = 32.0F;
+ this.showModel = true;
+ this.cubeList = new ArrayList();
+ this.baseModel = par1ModelBase;
+ par1ModelBase.boxList.add(this);
+ this.boxName = par2Str;
+ this.setTextureSize(par1ModelBase.textureWidth, par1ModelBase.textureHeight);
+ }
+
+ public IHLModelRenderer(ModelBase par1ModelBase)
+ {
+ this(par1ModelBase, (String)null);
+ }
+
+ public IHLModelRenderer(ModelBase par1ModelBase, int par2, int par3)
+ {
+ this(par1ModelBase);
+ this.setTextureOffset(par2, par3);
+ }
+
+ /**
+ * Sets the current box's rotation points and rotation angles to another box.
+ */
+ public void addChild(ModelRenderer par1ModelRenderer)
+ {
+ if (this.childModels == null)
+ {
+ this.childModels = new ArrayList();
+ }
+
+ this.childModels.add(par1ModelRenderer);
+ }
+
+ public IHLModelRenderer setTextureOffset(int par1, int par2)
+ {
+ this.textureOffsetX = par1;
+ this.textureOffsetY = par2;
+ return this;
+ }
+
+ public IHLModelRenderer addBox(String par1Str, float par2, float par3, float par4, int par5, int par6, int par7, boolean inverted, boolean[] renderFace)
+ {
+ par1Str = this.boxName + "." + par1Str;
+ TextureOffset var8 = this.baseModel.getTextureOffset(par1Str);
+ this.setTextureOffset(var8.textureOffsetX, var8.textureOffsetY);
+ this.cubeList.add((new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par2, par3, par4, par5, par6, par7, 0.0F, inverted, renderFace)).func_78244_a(par1Str));
+ return this;
+ }
+
+ public IHLModelRenderer addBox(String par1Str, float par2, float par3, float par4, int par5, int par6, int par7, boolean inverted)
+ {
+ boolean[] renderFace={true,true,true,true,true,true};
+ par1Str = this.boxName + "." + par1Str;
+ TextureOffset var8 = this.baseModel.getTextureOffset(par1Str);
+ this.setTextureOffset(var8.textureOffsetX, var8.textureOffsetY);
+ this.cubeList.add((new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par2, par3, par4, par5, par6, par7, 0.0F, inverted, renderFace)).func_78244_a(par1Str));
+ return this;
+ }
+
+ public IHLModelRenderer addBox(float par1, float par2, float par3, int par4, int par5, int par6, boolean inverted, boolean[] renderFace)
+ {
+ this.cubeList.add(new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, 0.0F, inverted, renderFace));
+ return this;
+ }
+
+ public IHLModelRenderer addTube(String par1Str, float par1, float par2, float par3, int par4, int par5, int par6, float radius1, float radius2, ForgeDirection direction)
+ {
+ par1Str = this.boxName + "." + par1Str;
+ TextureOffset var8 = this.baseModel.getTextureOffset(par1Str);
+ this.setTextureOffset(var8.textureOffsetX, var8.textureOffsetY);
+ this.cubeList.add(new ModelTube(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, 0.0F, radius1,radius2, direction));
+ return this;
+ }
+
+ public IHLModelRenderer addKnee(String par1Str, float par1, float par2, float par3, int par4, int par5, int par6, float radius1, float radius2, ForgeDirection direction, ForgeDirection direction2)
+ {
+ par1Str = this.boxName + "." + par1Str;
+ TextureOffset var8 = this.baseModel.getTextureOffset(par1Str);
+ this.setTextureOffset(var8.textureOffsetX, var8.textureOffsetY);
+ this.cubeList.add(new ModelKnee(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, 0.0F, radius1,radius2, direction, direction2));
+ return this;
+ }
+
+ public IHLModelRenderer addBox(float par1, float par2, float par3, int par4, int par5, int par6)
+ {
+ boolean[] renderFace={true,true,true,true,true,true};
+ this.cubeList.add(new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, 0.0F, false, renderFace));
+ return this;
+ }
+
+ /**
+ * Creates a textured box. Args: originX, originY, originZ, width, height, depth, scaleFactor.
+ */
+ public void addBox(float par1, float par2, float par3, int par4, int par5, int par6, float par7, boolean inverted, boolean[] renderFace)
+ {
+ this.cubeList.add(new ModelToplessBox(this, this.textureOffsetX, this.textureOffsetY, par1, par2, par3, par4, par5, par6, par7, inverted, renderFace));
+ }
+
+ public void setRotationPoint(float par1, float par2, float par3)
+ {
+ this.rotationPointX = par1;
+ this.rotationPointY = par2;
+ this.rotationPointZ = par3;
+ }
+
+ public void render(float par1)
+ {
+ if (!this.isHidden)
+ {
+ if (this.showModel)
+ {
+ if (!this.compiled)
+ {
+ this.compileDisplayList(par1);
+ }
+
+ GL11.glTranslatef(this.offsetX, this.offsetY, this.offsetZ);
+ int var2;
+
+ if (this.rotateAngleX == 0.0F && this.rotateAngleY == 0.0F && this.rotateAngleZ == 0.0F)
+ {
+ if (this.rotationPointX == 0.0F && this.rotationPointY == 0.0F && this.rotationPointZ == 0.0F)
+ {
+ GL11.glCallList(this.displayList);
+
+ if (this.childModels != null)
+ {
+ for (var2 = 0; var2 < this.childModels.size(); ++var2)
+ {
+ ((ModelRenderer)this.childModels.get(var2)).render(par1);
+ }
+ }
+ }
+ else
+ {
+ GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);
+ GL11.glCallList(this.displayList);
+
+ if (this.childModels != null)
+ {
+ for (var2 = 0; var2 < this.childModels.size(); ++var2)
+ {
+ ((ModelRenderer)this.childModels.get(var2)).render(par1);
+ }
+ }
+
+ GL11.glTranslatef(-this.rotationPointX * par1, -this.rotationPointY * par1, -this.rotationPointZ * par1);
+ }
+ }
+ else
+ {
+ GL11.glPushMatrix();
+ GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);
+
+ if (this.rotateAngleZ != 0.0F)
+ {
+ GL11.glRotatef(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
+ }
+
+ if (this.rotateAngleY != 0.0F)
+ {
+ GL11.glRotatef(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
+ }
+
+ if (this.rotateAngleX != 0.0F)
+ {
+ GL11.glRotatef(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
+ }
+
+ GL11.glCallList(this.displayList);
+
+ if (this.childModels != null)
+ {
+ for (var2 = 0; var2 < this.childModels.size(); ++var2)
+ {
+ ((ModelRenderer)this.childModels.get(var2)).render(par1);
+ }
+ }
+
+ GL11.glPopMatrix();
+ }
+
+ GL11.glTranslatef(-this.offsetX, -this.offsetY, -this.offsetZ);
+ }
+ }
+ }
+
+ public void renderWithRotation(float par1)
+ {
+ if (!this.isHidden)
+ {
+ if (this.showModel)
+ {
+ if (!this.compiled)
+ {
+ this.compileDisplayList(par1);
+ }
+
+ GL11.glPushMatrix();
+ GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);
+
+ if (this.rotateAngleY != 0.0F)
+ {
+ GL11.glRotatef(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
+ }
+
+ if (this.rotateAngleX != 0.0F)
+ {
+ GL11.glRotatef(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
+ }
+
+ if (this.rotateAngleZ != 0.0F)
+ {
+ GL11.glRotatef(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
+ }
+
+ GL11.glCallList(this.displayList);
+ GL11.glPopMatrix();
+ }
+ }
+ }
+
+ /**
+ * Allows the changing of Angles after a box has been rendered
+ */
+ public void postRender(float par1)
+ {
+ if (!this.isHidden)
+ {
+ if (this.showModel)
+ {
+ if (!this.compiled)
+ {
+ this.compileDisplayList(par1);
+ }
+
+ if (this.rotateAngleX == 0.0F && this.rotateAngleY == 0.0F && this.rotateAngleZ == 0.0F)
+ {
+ if (this.rotationPointX != 0.0F || this.rotationPointY != 0.0F || this.rotationPointZ != 0.0F)
+ {
+ GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);
+ }
+ }
+ else
+ {
+ GL11.glTranslatef(this.rotationPointX * par1, this.rotationPointY * par1, this.rotationPointZ * par1);
+
+ if (this.rotateAngleZ != 0.0F)
+ {
+ GL11.glRotatef(this.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
+ }
+
+ if (this.rotateAngleY != 0.0F)
+ {
+ GL11.glRotatef(this.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
+ }
+
+ if (this.rotateAngleX != 0.0F)
+ {
+ GL11.glRotatef(this.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Compiles a GL display list for this model
+ */
+ private void compileDisplayList(float par1)
+ {
+ this.displayList = GLAllocation.generateDisplayLists(1);
+ GL11.glNewList(this.displayList, GL11.GL_COMPILE);
+ Tessellator var2 = Tessellator.instance;
+
+ for (int var3 = 0; var3 < this.cubeList.size(); ++var3)
+ {
+ if(this.cubeList.get(var3) instanceof ModelToplessBox)
+ {
+ ((ModelToplessBox)this.cubeList.get(var3)).render(var2, par1);
+ }
+ else if(this.cubeList.get(var3) instanceof ModelTube)
+ {
+ ((ModelTube)this.cubeList.get(var3)).render(var2, par1);
+ }
+ else if(this.cubeList.get(var3) instanceof ModelKnee)
+ {
+ ((ModelKnee)this.cubeList.get(var3)).render(var2, par1);
+ }
+ }
+
+ GL11.glEndList();
+ this.compiled = true;
+ }
+
+ /**
+ * Returns the model renderer with the new texture parameters.
+ */
+ public IHLModelRenderer setTextureSize(int par1, int par2)
+ {
+ this.textureWidth = par1;
+ this.textureHeight = par2;
+ return this;
+ }
+
+ public void addBox(String string, float f, float g, float h, int i, int j, int k) {
+ this.addBox(string, f, g, h, i, j, k, false);
+ }
+
+
+}
|
