package client.renderer.layers;

import client.renderer.GlState;
import client.renderer.entity.RenderHumanoid;
import client.renderer.model.ModelRenderer;
import common.entity.npc.EntityNPC;
import common.util.ExtMath;

public class LayerPowerRods implements LayerRenderer<EntityNPC>
{
    private static final String ROD_TEXTURE = "textures/npc/power_rod.png";
    
    private final RenderHumanoid renderer;
    private ModelRenderer powerRod;

    public LayerPowerRods(RenderHumanoid npcRendererIn)
    {
        this.renderer = npcRendererIn;
        this.powerRod = new ModelRenderer(0, 0, 16, 16);
        this.powerRod.addBox(0.0F, 0.0F, 0.0F, 2, 6, 2);
    }

    public void doRenderLayer(EntityNPC entitylivingbaseIn, float p_177141_2_, float p_177141_3_, float partialTicks, float time, float p_177141_6_, float p_177141_7_, float scale)
    {
    	if(entitylivingbaseIn.hasPowerRods()) { // && !entitylivingbaseIn.isInvisible()) {
            GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
            this.renderer.bindTexture(ROD_TEXTURE);
//            SKC.glPushMatrix();
//            SKC.glTranslatef(0.0F, 0.0F, 0.125F);
//            SKC.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
//            this.renderer.getMainModel().renderRods(0.0625F, time);
        	float f = time * (float)Math.PI * -0.1F;

            for (int i = 0; i < 4; ++i)
            {
                this.powerRod.rotationPointY = 0.0F + ExtMath.cos(((float)(i * 8) + time) * 0.25F);
                this.powerRod.rotationPointX = ExtMath.cos(f) * 14.0F;
                this.powerRod.rotationPointZ = ExtMath.sin(f) * 14.0F;
                this.powerRod.render(0.0625F);
                ++f;
            }

            f = 0.47123894F + time * (float)Math.PI * 0.05F;

            for (int k = 4; k < 8; ++k)
            {
                this.powerRod.rotationPointY = 12.0f + ExtMath.cos(((float)k * 1.5F + time) * 0.5F);
                this.powerRod.rotationPointX = ExtMath.cos(f) * 8.0F;
                this.powerRod.rotationPointZ = ExtMath.sin(f) * 8.0F;
                this.powerRod.render(0.0625F);
                ++f;
            }

            f = ((float)Math.PI / 4F) + time * (float)Math.PI * 0.03F;

            for (int j = 8; j < 16; ++j)
            {
                this.powerRod.rotationPointY = -18.0f + ExtMath.cos(((float)(j * 4) + time) * 0.25F);
                this.powerRod.rotationPointX = ExtMath.cos(f) * 11.0F;
                this.powerRod.rotationPointZ = ExtMath.sin(f) * 11.0F;
                this.powerRod.render(0.0625F);
                f += Math.PI / 4F;
            }
//            SKC.glPopMatrix();
    	}
    }

    public boolean shouldCombineTextures()
    {
        return false;
    }
}
