package client.renderer.entity;

import org.lwjgl.opengl.GL11;

import client.renderer.GlState;
import client.renderer.layers.LayerEnderDragonEyes;
import client.renderer.model.ModelDragon;
import common.entity.animal.EntityDragon;
import common.util.ExtMath;


public class RenderDragon extends RenderLiving<EntityDragon>
{
    private static final String enderDragonTextures = "textures/creature/dragon.png";

    /** An instance of the dragon model in RenderDragon */
    protected ModelDragon modelDragon;

    public RenderDragon(RenderManager renderManagerIn)
    {
        super(renderManagerIn, new ModelDragon(0.0F));
        this.modelDragon = (ModelDragon)this.mainModel;
        this.addLayer(new LayerEnderDragonEyes(this));
//        this.addLayer(new LayerEntityBreak());
    }

    protected void rotateCorpse(EntityDragon bat, float p_77043_2_, float p_77043_3_, float partialTicks)
    {
        float f = (float)bat.getMovementOffsets(7, partialTicks)[0];
        float f1 = (float)(bat.getMovementOffsets(5, partialTicks)[1] - bat.getMovementOffsets(10, partialTicks)[1]);
        GL11.glRotatef(-f, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(f1 * 10.0F, 1.0F, 0.0F, 0.0F);
        GL11.glTranslatef(0.0F, 0.0F, 1.0F);

        if (bat.deathTime > 0)
        {
            float f2 = ((float)bat.deathTime + partialTicks - 1.0F) / 20.0F * 1.6F;
            f2 = ExtMath.sqrtf(f2);

            if (f2 > 1.0F)
            {
                f2 = 1.0F;
            }

            GL11.glRotatef(f2 * this.getDeathMaxRotation(bat), 0.0F, 0.0F, 1.0F);
        }
    }

    /**
     * Renders the model in RenderLiving
     */
    protected void renderModel(EntityDragon entitylivingbaseIn, float p_77036_2_, float p_77036_3_, float p_77036_4_, float p_77036_5_, float p_77036_6_, float scaleFactor)
    {
//        if (entitylivingbaseIn.deathTicks > 0)
//        {
//            float f = (float)entitylivingbaseIn.deathTicks / 200.0F;
//            GlState.depthFunc(GL11.GL_LEQUAL);
//            GlState.enableAlpha();
//            GlState.alphaFunc(GL11.GL_GREATER, f);
//            this.bindTexture(enderDragonExplodingTextures);
//            this.mainModel.render(entitylivingbaseIn, p_77036_2_, p_77036_3_, p_77036_4_, p_77036_5_, p_77036_6_, scaleFactor);
//            GlState.alphaFunc(GL11.GL_GREATER, 0.1F);
//            GlState.depthFunc(GL11.GL_EQUAL);
//        }

        this.bindEntityTexture(entitylivingbaseIn);
        this.mainModel.render(entitylivingbaseIn, p_77036_2_, p_77036_3_, p_77036_4_, p_77036_5_, p_77036_6_, scaleFactor);

        if (entitylivingbaseIn.hurtTime > 0)
        {
            GlState.depthFunc(GL11.GL_EQUAL);
            GlState.disableTexture2D();
            GlState.enableBlend();
            GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
            GlState.color(1.0F, 0.0F, 0.0F, 0.5F);
            this.mainModel.render(entitylivingbaseIn, p_77036_2_, p_77036_3_, p_77036_4_, p_77036_5_, p_77036_6_, scaleFactor);
            GlState.enableTexture2D();
            GlState.disableBlend();
            GlState.depthFunc(GL11.GL_LEQUAL);
        }
    }

//    /**
//     * Renders the desired {@code T} type Entity.
//     */
//    public void doRender(EntityDragon entity, double x, double y, double z, float entityYaw, float partialTicks)
//    {
//        BossStatus.setBossStatus(entity);
//        super.doRender(entity, x, y, z, entityYaw, partialTicks);
//
////        if (entity.healingEnderCrystal != null)
////        {
////            this.drawRechargeRay(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(EntityDragon entity)
    {
        return enderDragonTextures;
    }
}
