package client.renderer.ticked;

import client.renderer.texture.TextureTicked;


public class TextureWaterFlow extends TextureTicked
{
	private final int color;

    public TextureWaterFlow(int color)
    {
    	this.color = color;
        field_1138_g = new float[256];
        field_1137_h = new float[256];
        field_1136_i = new float[256];
        field_1135_j = new float[256];
        field_1134_k = 0;
    }

    public void renderStep(int textureData[])
    {
        field_1134_k++;
        for(int i = 0; i < 16; i++)
        {
            for(int k = 0; k < 16; k++)
            {
                float f = 0.0F;
                for(int j1 = k - 2; j1 <= k; j1++)
                {
                    int k1 = i & 0xf;
                    int i2 = j1 & 0xf;
                    f += field_1138_g[k1 + i2 * 16];
                }

                field_1137_h[i + k * 16] = f / 3.2F + field_1136_i[i + k * 16] * 0.8F;
            }

        }

        for(int j = 0; j < 16; j++)
        {
            for(int l = 0; l < 16; l++)
            {
                field_1136_i[j + l * 16] += field_1135_j[j + l * 16] * 0.05F;
                if(field_1136_i[j + l * 16] < 0.0F)
                {
                    field_1136_i[j + l * 16] = 0.0F;
                }
                field_1135_j[j + l * 16] -= 0.3F;
                if(Math.random() < 0.20000000000000001D)
                {
                    field_1135_j[j + l * 16] = 0.5F;
                }
            }

        }

        float af[] = field_1137_h;
        field_1137_h = field_1138_g;
        field_1138_g = af;
        for(int i1 = 0; i1 < 256; i1++)
        {
            float f1 = field_1138_g[i1 - field_1134_k * 16 & 0xff];
            if(f1 > 1.0F)
            {
                f1 = 1.0F;
            }
            if(f1 < 0.0F)
            {
                f1 = 0.0F;
            }
            float v = f1 * f1;
            int r = (int)(32F + v * 32F);
            int g = (int)(50F + v * 64F);
            int b = 255;
            int a = (int)(146F + v * 50F);
            if(this.color != 0xffffffff)
            {
                r = (r * ((this.color >> 16) & 0xff)) / 255;
                g = (g * ((this.color >> 8) & 0xff)) / 255;
                b = (b * (this.color & 0xff)) / 255;
                a = (a * ((this.color >> 24) & 0xff)) / 255;
            }
            r = (r * a) / 255;
            g = (g * a) / 255;
            b = (b * a) / 255;
            textureData[(i1 & 0x0f) | ((i1 & 0xf0) * 2)] = textureData[((i1 & 0x0f) + 16) | ((i1 & 0xf0) * 2)] = 
            		textureData[(i1 & 0x0f) | (((i1 & 0xf0) + 256) * 2)] = textureData[((i1 & 0x0f) + 16) | (((i1 & 0xf0) + 256) * 2)] = 
            		0xff000000 | (r << 16) | (g << 8) | b;
        }

    }
    
    public int getSize() {
    	return 32;
    }

    protected float field_1138_g[];
    protected float field_1137_h[];
    protected float field_1136_i[];
    protected float field_1135_j[];
    private int field_1134_k;
}
