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.Entity;
import common.util.BoundingBox;


public class RenderEntity extends Render<Entity>
{
    public static void renderOffsetAABB(BoundingBox bb, double x, double y, double z)
    {
        GlState.disableTexture2D();
        RenderBuffer rb = Tessellator.getBuffer();
        GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
        rb.setTranslation(x, y, z);
        rb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_NORMAL);
        rb.pos(bb.minX, bb.maxY, bb.minZ).normal(0.0F, 0.0F, -1.0F).endVertex();
        rb.pos(bb.maxX, bb.maxY, bb.minZ).normal(0.0F, 0.0F, -1.0F).endVertex();
        rb.pos(bb.maxX, bb.minY, bb.minZ).normal(0.0F, 0.0F, -1.0F).endVertex();
        rb.pos(bb.minX, bb.minY, bb.minZ).normal(0.0F, 0.0F, -1.0F).endVertex();
        rb.pos(bb.minX, bb.minY, bb.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex();
        rb.pos(bb.maxX, bb.minY, bb.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex();
        rb.pos(bb.maxX, bb.maxY, bb.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex();
        rb.pos(bb.minX, bb.maxY, bb.maxZ).normal(0.0F, 0.0F, 1.0F).endVertex();
        rb.pos(bb.minX, bb.minY, bb.minZ).normal(0.0F, -1.0F, 0.0F).endVertex();
        rb.pos(bb.maxX, bb.minY, bb.minZ).normal(0.0F, -1.0F, 0.0F).endVertex();
        rb.pos(bb.maxX, bb.minY, bb.maxZ).normal(0.0F, -1.0F, 0.0F).endVertex();
        rb.pos(bb.minX, bb.minY, bb.maxZ).normal(0.0F, -1.0F, 0.0F).endVertex();
        rb.pos(bb.minX, bb.maxY, bb.maxZ).normal(0.0F, 1.0F, 0.0F).endVertex();
        rb.pos(bb.maxX, bb.maxY, bb.maxZ).normal(0.0F, 1.0F, 0.0F).endVertex();
        rb.pos(bb.maxX, bb.maxY, bb.minZ).normal(0.0F, 1.0F, 0.0F).endVertex();
        rb.pos(bb.minX, bb.maxY, bb.minZ).normal(0.0F, 1.0F, 0.0F).endVertex();
        rb.pos(bb.minX, bb.minY, bb.maxZ).normal(-1.0F, 0.0F, 0.0F).endVertex();
        rb.pos(bb.minX, bb.maxY, bb.maxZ).normal(-1.0F, 0.0F, 0.0F).endVertex();
        rb.pos(bb.minX, bb.maxY, bb.minZ).normal(-1.0F, 0.0F, 0.0F).endVertex();
        rb.pos(bb.minX, bb.minY, bb.minZ).normal(-1.0F, 0.0F, 0.0F).endVertex();
        rb.pos(bb.maxX, bb.minY, bb.minZ).normal(1.0F, 0.0F, 0.0F).endVertex();
        rb.pos(bb.maxX, bb.maxY, bb.minZ).normal(1.0F, 0.0F, 0.0F).endVertex();
        rb.pos(bb.maxX, bb.maxY, bb.maxZ).normal(1.0F, 0.0F, 0.0F).endVertex();
        rb.pos(bb.maxX, bb.minY, bb.maxZ).normal(1.0F, 0.0F, 0.0F).endVertex();
        Tessellator.draw();
        rb.setTranslation(0.0D, 0.0D, 0.0D);
        GlState.enableTexture2D();
    }
    
    public RenderEntity(RenderManager renderManagerIn)
    {
        super(renderManagerIn);
    }

    public void doRender(Entity entity, double x, double y, double z, float partialTicks)
    {
        GL11.glPushMatrix();
        renderOffsetAABB(entity.getEntityBoundingBox(), x - entity.lastTickPosX, y - entity.lastTickPosY, z - entity.lastTickPosZ);
        GL11.glPopMatrix();
        super.doRender(entity, x, y, z, partialTicks);
    }

    protected String getEntityTexture(Entity entity)
    {
        return null;
    }
}
