Cleanups!

This commit is contained in:
Aidan Brady 2013-07-31 23:54:08 -04:00
parent 7bbcc1c178
commit d56eed2204
3 changed files with 47 additions and 29 deletions

View file

@ -9,10 +9,13 @@ import net.minecraft.client.renderer.Tessellator;
public class ModelBoxSelectiveFace
{
private PositionTextureVertex[] vertexPositions;
private TexturedQuad[] quadList;
public final float posX1;
public final float posY1;
public final float posZ1;
public final float posX2;
public final float posY2;
public final float posZ2;
@ -22,14 +25,18 @@ public class ModelBoxSelectiveFace
posX1 = xMin;
posY1 = yMin;
posZ1 = zMin;
posX2 = xMin + (float)xSize;
posY2 = yMin + (float)ySize;
posZ2 = zMin + (float)zSize;
vertexPositions = new PositionTextureVertex[8];
quadList = new TexturedQuad[6];
float xMax = xMin + (float)xSize;
float yMax = yMin + (float)ySize;
float zMax = zMin + (float)zSize;
xMin -= scaleFactor;
yMin -= scaleFactor;
zMin -= scaleFactor;
@ -37,7 +44,7 @@ public class ModelBoxSelectiveFace
yMax += scaleFactor;
zMax += scaleFactor;
if (modelRenderer.mirror)
if(modelRenderer.mirror)
{
float placeholder = xMax;
xMax = xMin;
@ -52,6 +59,7 @@ public class ModelBoxSelectiveFace
PositionTextureVertex positiontexturevertex5 = new PositionTextureVertex(xMax, yMin, zMax, 0.0F, 8.0F);
PositionTextureVertex positiontexturevertex6 = new PositionTextureVertex(xMax, yMax, zMax, 8.0F, 8.0F);
PositionTextureVertex positiontexturevertex7 = new PositionTextureVertex(xMin, yMax, zMax, 8.0F, 0.0F);
vertexPositions[0] = positiontexturevertex0;
vertexPositions[1] = positiontexturevertex1;
vertexPositions[2] = positiontexturevertex2;
@ -60,6 +68,7 @@ public class ModelBoxSelectiveFace
vertexPositions[5] = positiontexturevertex5;
vertexPositions[6] = positiontexturevertex6;
vertexPositions[7] = positiontexturevertex7;
quadList[0] = new TexturedQuad(new PositionTextureVertex[] {positiontexturevertex2, positiontexturevertex3, positiontexturevertex7, positiontexturevertex6}, textureOffsetU + zSize + xSize, textureOffsetV + zSize, textureOffsetU + zSize + xSize + xSize, textureOffsetV, modelRenderer.textureWidth, modelRenderer.textureHeight);
quadList[1] = new TexturedQuad(new PositionTextureVertex[] {positiontexturevertex5, positiontexturevertex4, positiontexturevertex0, positiontexturevertex1}, textureOffsetU + zSize, textureOffsetV, textureOffsetU + zSize + xSize, textureOffsetV + zSize, modelRenderer.textureWidth, modelRenderer.textureHeight);
quadList[2] = new TexturedQuad(new PositionTextureVertex[] {positiontexturevertex4, positiontexturevertex5, positiontexturevertex6, positiontexturevertex7}, textureOffsetU + zSize + xSize + zSize, textureOffsetV + zSize, textureOffsetU + zSize + xSize + zSize + xSize, textureOffsetV + zSize + ySize, modelRenderer.textureWidth, modelRenderer.textureHeight);
@ -67,28 +76,25 @@ public class ModelBoxSelectiveFace
quadList[4] = new TexturedQuad(new PositionTextureVertex[] {positiontexturevertex0, positiontexturevertex4, positiontexturevertex7, positiontexturevertex3}, textureOffsetU, textureOffsetV + zSize, textureOffsetU + zSize, textureOffsetV + zSize + ySize, modelRenderer.textureWidth, modelRenderer.textureHeight);
quadList[5] = new TexturedQuad(new PositionTextureVertex[] {positiontexturevertex5, positiontexturevertex1, positiontexturevertex2, positiontexturevertex6}, textureOffsetU + zSize + xSize, textureOffsetV + zSize, textureOffsetU + zSize + xSize + zSize, textureOffsetV + zSize + ySize, modelRenderer.textureWidth, modelRenderer.textureHeight);
if (modelRenderer.mirror)
if(modelRenderer.mirror)
{
for (int j1 = 0; j1 < quadList.length; ++j1)
for(int quad = 0; quad < quadList.length; quad++)
{
quadList[j1].flipFace();
quadList[quad].flipFace();
}
}
}
/**
* Draw the six sided box defined by this ModelBox
*/
@SideOnly(Side.CLIENT)
public void render(Tessellator par1Tessellator, boolean[] connected, float par2)
public void render(Tessellator tessellator, boolean[] connected, float f)
{
if(connected.length == quadList.length)
{
for (int i = 0; i < connected.length; ++i)
for(int i = 0; i < connected.length; ++i)
{
if(!connected[i])
{
quadList[i].draw(par1Tessellator, par2);
quadList[i].draw(tessellator, f);
}
}
}

View file

@ -20,37 +20,46 @@ public class ModelRendererSelectiveFace
public float offsetX;
public float offsetY;
public float offsetZ;
public float rotationPointX;
public float rotationPointY;
public float rotationPointZ;
public float rotateAngleX;
public float rotateAngleY;
public float rotateAngleZ;
public boolean[] connectedFaces;
public boolean mirror;
public boolean showModel;
public boolean isHidden;
public List cubeList;
private int textureOffsetX;
private int textureOffsetY;
private int displayList;
private boolean compiled;
private ModelBase baseModel;
public ModelRendererSelectiveFace(ModelBase par1ModelBase)
public ModelRendererSelectiveFace(ModelBase modelBase)
{
textureWidth = 64.0F;
textureHeight = 32.0F;
showModel = true;
cubeList = new ArrayList();
baseModel = par1ModelBase;
setTextureSize(par1ModelBase.textureWidth, par1ModelBase.textureHeight);
baseModel = modelBase;
setTextureSize(modelBase.textureWidth, modelBase.textureHeight);
}
public ModelRendererSelectiveFace(ModelBase par1ModelBase, int par2, int par3)
public ModelRendererSelectiveFace(ModelBase modelBase, int par2, int par3)
{
this(par1ModelBase);
this(modelBase);
setTextureOffset(par2, par3);
}
@ -58,6 +67,7 @@ public class ModelRendererSelectiveFace
{
textureOffsetX = par1;
textureOffsetY = par2;
return this;
}
@ -77,11 +87,11 @@ public class ModelRendererSelectiveFace
@SideOnly(Side.CLIENT)
public void render(boolean[] connected, float par1)
{
if (!isHidden)
if(!isHidden)
{
if (showModel)
if(showModel)
{
if (!(compiled && Arrays.areEqual(connected, connectedFaces)))
if(!(compiled && Arrays.areEqual(connected, connectedFaces)))
{
connectedFaces = connected;
compileDisplayList(par1);
@ -90,9 +100,9 @@ public class ModelRendererSelectiveFace
GL11.glTranslatef(offsetX, offsetY, offsetZ);
int i;
if (rotateAngleX == 0.0F && rotateAngleY == 0.0F && rotateAngleZ == 0.0F)
if(rotateAngleX == 0.0F && rotateAngleY == 0.0F && rotateAngleZ == 0.0F)
{
if (rotationPointX == 0.0F && rotationPointY == 0.0F && rotationPointZ == 0.0F)
if(rotationPointX == 0.0F && rotationPointY == 0.0F && rotationPointZ == 0.0F)
{
GL11.glCallList(displayList);
}
@ -108,17 +118,17 @@ public class ModelRendererSelectiveFace
GL11.glPushMatrix();
GL11.glTranslatef(rotationPointX * par1, rotationPointY * par1, rotationPointZ * par1);
if (rotateAngleZ != 0.0F)
if(rotateAngleZ != 0.0F)
{
GL11.glRotatef(rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
}
if (rotateAngleY != 0.0F)
if(rotateAngleY != 0.0F)
{
GL11.glRotatef(rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
}
if (rotateAngleX != 0.0F)
if(rotateAngleX != 0.0F)
{
GL11.glRotatef(rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
}
@ -133,25 +143,26 @@ public class ModelRendererSelectiveFace
}
@SideOnly(Side.CLIENT)
private void compileDisplayList(float par1)
private void compileDisplayList(float size)
{
displayList = GLAllocation.generateDisplayLists(1);
GL11.glNewList(displayList, GL11.GL_COMPILE);
Tessellator tessellator = Tessellator.instance;
for (int i = 0; i < cubeList.size(); ++i)
for(int i = 0; i < cubeList.size(); i++)
{
((ModelBoxSelectiveFace)cubeList.get(i)).render(tessellator, connectedFaces, par1);
((ModelBoxSelectiveFace)cubeList.get(i)).render(tessellator, connectedFaces, size);
}
GL11.glEndList();
compiled = true;
}
public ModelRendererSelectiveFace setTextureSize(int par1, int par2)
public ModelRendererSelectiveFace setTextureSize(int width, int height)
{
textureWidth = (float)par1;
textureHeight = (float)par2;
textureWidth = width;
textureHeight = height;
return this;
}
}

View file

@ -18,6 +18,7 @@ public class ModelTransmitter extends ModelBase
{true, true, false, false, false, false},
{true, true, false, false, false, false},
};
ModelRendererSelectiveFace Center;
ModelRendererSelectiveFace Up;
ModelRendererSelectiveFace Down;