package client.renderer.entity;

import org.lwjgl.opengl.GL11;

import client.renderer.DefaultVertexFormats;
import client.renderer.GlState;
import client.renderer.RenderBuffer;
import client.renderer.Tessellator;
import common.entity.projectile.EntityBullet;


public class RenderBullet extends Render<EntityBullet>
{
    private static final String bulletTextures = "textures/object/bullet.png";

    public RenderBullet(RenderManager renderManagerIn)
    {
        super(renderManagerIn);
    }
    
    public void doRender(EntityBullet entity, double x, double y, double z, float partialTicks)
    {
        this.bindEntityTexture(entity);
        GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glPushMatrix();
        GL11.glTranslatef((float)x, (float)y, (float)z);
        GL11.glRotatef(entity.prevYaw + (entity.rotYaw - entity.prevYaw) * partialTicks - 90.0F, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(entity.prevPitch + (entity.rotPitch - entity.prevPitch) * partialTicks, 0.0F, 0.0F, 1.0F);
        RenderBuffer worldrenderer = Tessellator.getBuffer();
        float f = 0.0F;
        float f1 = 0.5F;
        float f2 = (float)0 / 32.0F;
        float f3 = (float)5 / 32.0F;
        float f4 = 0.0F;
        float f5 = 0.15625F;
        float f6 = (float)5 / 32.0F;
        float f7 = (float)10 / 32.0F;
        float f8 = 0.05625F;
        GlState.enableRescaleNormal();

        GL11.glRotatef(45.0F, 1.0F, 0.0F, 0.0F);
        GL11.glScalef(f8, f8, f8);
        GL11.glTranslatef(-4.0F, 0.0F, 0.0F);
        GL11.glNormal3f(f8, 0.0F, 0.0F);
        worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        worldrenderer.pos(-7.0D, -2.0D, -2.0D).tex((double)f4, (double)f6).endVertex();
        worldrenderer.pos(-7.0D, -2.0D, 2.0D).tex((double)f5, (double)f6).endVertex();
        worldrenderer.pos(-7.0D, 2.0D, 2.0D).tex((double)f5, (double)f7).endVertex();
        worldrenderer.pos(-7.0D, 2.0D, -2.0D).tex((double)f4, (double)f7).endVertex();
        Tessellator.draw();
        GL11.glNormal3f(-f8, 0.0F, 0.0F);
        worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        worldrenderer.pos(-7.0D, 2.0D, -2.0D).tex((double)f4, (double)f6).endVertex();
        worldrenderer.pos(-7.0D, 2.0D, 2.0D).tex((double)f5, (double)f6).endVertex();
        worldrenderer.pos(-7.0D, -2.0D, 2.0D).tex((double)f5, (double)f7).endVertex();
        worldrenderer.pos(-7.0D, -2.0D, -2.0D).tex((double)f4, (double)f7).endVertex();
        Tessellator.draw();

        for (int j = 0; j < 4; ++j)
        {
            GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
            GL11.glNormal3f(0.0F, 0.0F, f8);
            worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
            worldrenderer.pos(-8.0D, -2.0D, 0.0D).tex((double)f, (double)f2).endVertex();
            worldrenderer.pos(8.0D, -2.0D, 0.0D).tex((double)f1, (double)f2).endVertex();
            worldrenderer.pos(8.0D, 2.0D, 0.0D).tex((double)f1, (double)f3).endVertex();
            worldrenderer.pos(-8.0D, 2.0D, 0.0D).tex((double)f, (double)f3).endVertex();
            Tessellator.draw();
        }

        GlState.disableRescaleNormal();
        GL11.glPopMatrix();
        super.doRender(entity, x, y, z, partialTicks);
    }
    
    protected String getEntityTexture(EntityBullet entity)
    {
        return bulletTextures;
    }
}
