package client.renderer.entity;

import org.lwjgl.opengl.GL11;

import client.Client;
import client.renderer.texture.TextureMap;
import common.entity.Entity;
import common.world.State;


public class RenderBlockEntity extends Render<Entity>
{
	private final State state;
	
    public RenderBlockEntity(RenderManager renderManagerIn, State state)
    {
        super(renderManagerIn);
//        this.shadowSize = 0.5F;
        this.state = state;
    }

    /**
     * Renders the desired {@code T} type Entity.
     */
    public void doRender(Entity entity, double x, double y, double z, float partialTicks)
    {
//    	if(entity.isInvisible()) {
//    		return;
//    	}
        GL11.glPushMatrix();
        GL11.glTranslatef((float)x, (float)y + 0.5F, (float)z);

//        if ((float)entity.fuse - partialTicks + 1.0F < 10.0F)
//        {
//            float f = 1.0F - ((float)entity.fuse - partialTicks + 1.0F) / 10.0F;
//            f = MathHelper.clamp_float(f, 0.0F, 1.0F);
//            f = f * f;
//            f = f * f;
//            float f1 = 1.0F + f * 0.3F;
//            GlStateManager.scale(f1, f1, f1);
//        }

//        float f2 = (1.0F - ((float)entity.fuse - partialTicks + 1.0F) / 100.0F) * 0.8F;
        this.bindEntityTexture(entity);
        GL11.glTranslatef(-0.5F, -0.5F, 0.5F);
        Client.CLIENT.renderer.renderBlockEntity(this.state, getBrightness(entity));
        GL11.glTranslatef(0.0F, 0.0F, 1.0F);

//        if (entity.fuse / 5 % 2 == 0)
//        {
//            GlStateManager.disableTexture2D();
//            GlStateManager.disableLighting();
//            GlStateManager.enableBlend();
//            GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_ALPHA);
//            GlStateManager.color(1.0F, 1.0F, 1.0F, f2);
//            GlStateManager.doPolygonOffset(-3.0F, -3.0F);
//            GlStateManager.enablePolygonOffset();
//            blockrendererdispatcher.renderBlockBrightness(state, 1.0F);
//            GlStateManager.doPolygonOffset(0.0F, 0.0F);
//            GlStateManager.disablePolygonOffset();
//            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
//            GlStateManager.disableBlend();
//            GlStateManager.enableLighting();
//            GlStateManager.enableTexture2D();
//        }

        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(Entity entity)
    {
        return TextureMap.BLOCKS;
    }
}
