package com.zivilon.cinder_loe.client.render.projectile;

import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;

import com.zivilon.cinder_loe.entity.SarumanWhiteFireball;

public class RenderSarumanWhiteFireball extends Render {
    public static final ResourceLocation particlesTexture = new ResourceLocation("cinder_loe:misc/particles.png");

    protected ResourceLocation getEntityTexture(Entity entity) {
        return particlesTexture;
    }
    
    public void doRender(Entity entity, double d, double d1, double d2, float f, float f1) {
        GL11.glPushMatrix();
        GL11.glTranslatef((float)d, (float)d1, (float)d2);
        GL11.glEnable(32826);
        bindEntityTexture(entity);
        Tessellator tessellator = Tessellator.instance;
        drawSprite(tessellator, 32 + ((SarumanWhiteFireball)entity).animationTick);
        GL11.glDisable(32826);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glPopMatrix();
    }
    
    private void drawSprite(Tessellator tessellator, int index) {
        float f = (index % 8 * 16 + 0) / 128.0F;
        float f1 = (index % 8 * 16 + 16) / 128.0F;
        float f2 = (index / 8 * 16 + 0) / 128.0F;
        float f3 = (index / 8 * 16 + 16) / 128.0F;
        float f4 = 1.0F;
        float f5 = 0.5F;
        float f6 = 0.25F;
        GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 1.0F, 0.0F);
        tessellator.setBrightness(15728880);
        tessellator.addVertexWithUV((0.0F - f5), (0.0F - f6), 0.0D, f, f3);
        tessellator.addVertexWithUV((f4 - f5), (0.0F - f6), 0.0D, f1, f3);
        tessellator.addVertexWithUV((f4 - f5), (f4 - f6), 0.0D, f1, f2);
        tessellator.addVertexWithUV((0.0F - f5), (f4 - f6), 0.0D, f, f2);
        tessellator.draw();
    }
}