package client.renderer.layers;

import org.lwjgl.opengl.GL11;

import client.renderer.GlState;
import client.renderer.entity.RenderHumanoid;
import client.renderer.model.ModelCharge;
import common.entity.npc.EntityNPC;


public class LayerCharge implements LayerRenderer<EntityNPC>
{
    private static final String LIGHTNING_TEXTURE = "textures/npc/charge.png";
    
    private final RenderHumanoid main;
    private final ModelCharge charge = new ModelCharge(2.0F);

    public LayerCharge(RenderHumanoid main)
    {
        this.main = main;
    }

    public void doRenderLayer(EntityNPC entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale)
    {
        if (entitylivingbaseIn.isCharged())
        {
//            boolean flag = entitylivingbaseIn.isInvisible();
            GlState.depthMask(true);
            this.main.bindTexture(LIGHTNING_TEXTURE);
            GL11.glMatrixMode(GL11.GL_TEXTURE);
            GL11.glLoadIdentity();
            float f = (float)entitylivingbaseIn.ticksExisted + partialTicks;
            GL11.glTranslatef(f * 0.01F, f * 0.01F, 0.0F);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GlState.enableBlend();
            float f1 = 0.5F;
            GlState.color(f1, f1, f1, 1.0F);
            GlState.disableLighting();
            GlState.blendFunc(GL11.GL_ONE, GL11.GL_ONE);
            this.charge.setModelAttributes(this.main.getMainModel());
            GL11.glScalef(entitylivingbaseIn.height, entitylivingbaseIn.height, entitylivingbaseIn.height);
            GL11.glTranslatef(0.0f, -0.25f, 0.0f);
            this.charge.render(entitylivingbaseIn, p_177141_2_, p_177141_3_, p_177141_5_, p_177141_6_, p_177141_7_, scale);
            GL11.glMatrixMode(GL11.GL_TEXTURE);
            GL11.glLoadIdentity();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GlState.enableLighting();
            GlState.disableBlend();
            GlState.depthMask(false);
        }
    }

    public boolean shouldCombineTextures()
    {
        return false;
    }
}
