package client.renderer.blockmodel;

import java.util.Arrays;

import client.renderer.texture.Sprite;

public class BreakingFour extends BakedQuad
{
    private final Sprite texture;

    public BreakingFour(BakedQuad quad, Sprite texture) {
        super(Arrays.copyOf(quad.getVertexData(), quad.getVertexData().length), quad.tint, 
        		FaceBakery.getFacingFromVertexData(quad.getVertexData()));
        this.texture = texture;
        for(int z = 0; z < 4; z++) {
        	int i = 7 * z;
            float f = Float.intBitsToFloat(this.data[i]);
            float f1 = Float.intBitsToFloat(this.data[i + 1]);
            float f2 = Float.intBitsToFloat(this.data[i + 2]);
            float f3 = 0.0F;
            float f4 = 0.0F;

            switch(this.face) {
                case DOWN:
                    f3 = f * 16.0F;
                    f4 = (1.0F - f2) * 16.0F;
                    break;

                case UP:
                    f3 = f * 16.0F;
                    f4 = f2 * 16.0F;
                    break;

                case NORTH:
                    f3 = (1.0F - f) * 16.0F;
                    f4 = (1.0F - f1) * 16.0F;
                    break;

                case SOUTH:
                    f3 = f * 16.0F;
                    f4 = (1.0F - f1) * 16.0F;
                    break;

                case WEST:
                    f3 = f2 * 16.0F;
                    f4 = (1.0F - f1) * 16.0F;
                    break;

                case EAST:
                    f3 = (1.0F - f2) * 16.0F;
                    f4 = (1.0F - f1) * 16.0F;
            }

            this.data[i + 4] = Float.floatToRawIntBits(this.texture.getInterpolatedU((double)f3));
            this.data[i + 4 + 1] = Float.floatToRawIntBits(this.texture.getInterpolatedV((double)f4));
		}
    }
}
