package client.renderer.ticked;

import client.renderer.texture.TextureTicked;


public class TextureWater extends TextureTicked
{
	private final int color;

    public TextureWater(int color)
    {
    	this.color = color;
        field_1158_g = new float[256];
        field_1157_h = new float[256];
        field_1156_i = new float[256];
        field_1155_j = new float[256];
        tickCounter = 0;
    }

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

                field_1157_h[i + k * 16] = f / 3.3F + field_1156_i[i + k * 16] * 0.8F;
            }

        }

        for(int j = 0; j < 16; j++)
        {
            for(int l = 0; l < 16; l++)
            {
                field_1156_i[j + l * 16] += field_1155_j[j + l * 16] * 0.05F;
                if(field_1156_i[j + l * 16] < 0.0F)
                {
                    field_1156_i[j + l * 16] = 0.0F;
                }
                field_1155_j[j + l * 16] -= 0.1F;
                if(Math.random() < 0.050000000000000003D)
                {
                    field_1155_j[j + l * 16] = 0.5F;
                }
            }

        }

        float af[] = field_1157_h;
        field_1157_h = field_1158_g;
        field_1158_g = af;
        for(int i1 = 0; i1 < 256; i1++)
        {
            float f1 = field_1158_g[i1];
            if(f1 > 1.0F)
            {
                f1 = 1.0F;
            }
            if(f1 < 0.0F)
            {
                f1 = 0.0F;
            }
            float f2 = f1 * f1;
            int r = (int)(32F + f2 * 32F);
            int g = (int)(50F + f2 * 64F);
            int b = 255;
            int a = (int)(146F + f2 * 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] = 0xff000000 | (r << 16) | (g << 8) | b;
        }

    }

    protected float field_1158_g[];
    protected float field_1157_h[];
    protected float field_1156_i[];
    protected float field_1155_j[];
    private int tickCounter;
}
