package client.renderer.entity;

import org.lwjgl.opengl.GL11;

import client.Client;
import client.renderer.DefaultVertexFormats;
import client.renderer.GlState;
import client.renderer.RenderBuffer;
import client.renderer.Tessellator;
import client.renderer.texture.Sprite;
import client.renderer.texture.TextureMap;
import common.entity.projectile.EntityProjectile;
import common.init.Items;


public class RenderFireball extends Render<EntityProjectile>
{
    private float scale;

    public RenderFireball(RenderManager renderManagerIn, float scaleIn)
    {
        super(renderManagerIn);
        this.scale = scaleIn;
    }

    /**
     * Renders the desired {@code T} type Entity.
     */
    public void doRender(EntityProjectile entity, double x, double y, double z, float partialTicks)
    {
        GL11.glPushMatrix();
        this.bindEntityTexture(entity);
        GL11.glTranslatef((float)x, (float)y, (float)z);
        GlState.enableRescaleNormal();
        GL11.glScalef(this.scale, this.scale, this.scale);
        Sprite textureatlassprite = Client.CLIENT.getRenderItem().getItemModelMesher().getParticleIcon(Items.fireball);
//        Tessellator tessellator = Tessellator.getInstance();
        RenderBuffer worldrenderer = Tessellator.getBuffer();
        float f = textureatlassprite.getMinU();
        float f1 = textureatlassprite.getMaxU();
        float f2 = textureatlassprite.getMinV();
        float f3 = textureatlassprite.getMaxV();
        float f4 = 1.0F;
        float f5 = 0.5F;
        float f6 = 0.25F;
        GL11.glRotatef(180.0F - this.manager.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(-this.manager.playerViewX, 1.0F, 0.0F, 0.0F);
        worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL);
        worldrenderer.pos(-0.5D, -0.25D, 0.0D).tex((double)f, (double)f3).normal(0.0F, 1.0F, 0.0F).endVertex();
        worldrenderer.pos(0.5D, -0.25D, 0.0D).tex((double)f1, (double)f3).normal(0.0F, 1.0F, 0.0F).endVertex();
        worldrenderer.pos(0.5D, 0.75D, 0.0D).tex((double)f1, (double)f2).normal(0.0F, 1.0F, 0.0F).endVertex();
        worldrenderer.pos(-0.5D, 0.75D, 0.0D).tex((double)f, (double)f2).normal(0.0F, 1.0F, 0.0F).endVertex();
        Tessellator.draw();
        GlState.disableRescaleNormal();
        GL11.glPopMatrix();
        super.doRender(entity, x, y, z, partialTicks);
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected String getEntityTexture(EntityProjectile entity)
    {
        return TextureMap.BLOCKS;
    }
}
