    001package net.minecraft.client.model;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.renderer.Tessellator;
    006import net.minecraft.util.Vec3;
    007
    008public class TexturedQuad
    009{
    010    public PositionTextureVertex[] vertexPositions;
    011    public int nVertices;
    012    private boolean invertNormal;
    013
    014    public TexturedQuad(PositionTextureVertex[] par1ArrayOfPositionTextureVertex)
    015    {
    016        this.nVertices = 0;
    017        this.invertNormal = false;
    018        this.vertexPositions = par1ArrayOfPositionTextureVertex;
    019        this.nVertices = par1ArrayOfPositionTextureVertex.length;
    020    }
    021
    022    public TexturedQuad(PositionTextureVertex[] par1ArrayOfPositionTextureVertex, int par2, int par3, int par4, int par5, float par6, float par7)
    023    {
    024        this(par1ArrayOfPositionTextureVertex);
    025        float f2 = 0.0F / par6;
    026        float f3 = 0.0F / par7;
    027        par1ArrayOfPositionTextureVertex[0] = par1ArrayOfPositionTextureVertex[0].setTexturePosition((float)par4 / par6 - f2, (float)par3 / par7 + f3);
    028        par1ArrayOfPositionTextureVertex[1] = par1ArrayOfPositionTextureVertex[1].setTexturePosition((float)par2 / par6 + f2, (float)par3 / par7 + f3);
    029        par1ArrayOfPositionTextureVertex[2] = par1ArrayOfPositionTextureVertex[2].setTexturePosition((float)par2 / par6 + f2, (float)par5 / par7 - f3);
    030        par1ArrayOfPositionTextureVertex[3] = par1ArrayOfPositionTextureVertex[3].setTexturePosition((float)par4 / par6 - f2, (float)par5 / par7 - f3);
    031    }
    032
    033    public void flipFace()
    034    {
    035        PositionTextureVertex[] apositiontexturevertex = new PositionTextureVertex[this.vertexPositions.length];
    036
    037        for (int i = 0; i < this.vertexPositions.length; ++i)
    038        {
    039            apositiontexturevertex[i] = this.vertexPositions[this.vertexPositions.length - i - 1];
    040        }
    041
    042        this.vertexPositions = apositiontexturevertex;
    043    }
    044
    045    public void draw(Tessellator par1Tessellator, float par2)
    046    {
    047        Vec3 vec3 = this.vertexPositions[1].vector3D.subtract(this.vertexPositions[0].vector3D);
    048        Vec3 vec31 = this.vertexPositions[1].vector3D.subtract(this.vertexPositions[2].vector3D);
    049        Vec3 vec32 = vec31.crossProduct(vec3).normalize();
    050        par1Tessellator.startDrawingQuads();
    051
    052        if (this.invertNormal)
    053        {
    054            par1Tessellator.setNormal(-((float)vec32.xCoord), -((float)vec32.yCoord), -((float)vec32.zCoord));
    055        }
    056        else
    057        {
    058            par1Tessellator.setNormal((float)vec32.xCoord, (float)vec32.yCoord, (float)vec32.zCoord);
    059        }
    060
    061        for (int i = 0; i < 4; ++i)
    062        {
    063            PositionTextureVertex positiontexturevertex = this.vertexPositions[i];
    064            par1Tessellator.addVertexWithUV((double)((float)positiontexturevertex.vector3D.xCoord * par2), (double)((float)positiontexturevertex.vector3D.yCoord * par2), (double)((float)positiontexturevertex.vector3D.zCoord * par2), (double)positiontexturevertex.texturePositionX, (double)positiontexturevertex.texturePositionY);
    065        }
    066
    067        par1Tessellator.draw();
    068    }
    069}