package client.renderer.layers;

import org.lwjgl.opengl.GL11;

import client.renderer.DefaultVertexFormats;
import client.renderer.GlState;
import client.renderer.ItemRenderer;
import client.renderer.RenderBuffer;
import client.renderer.Tessellator;
import common.entity.animal.EntityDragon;
import common.rng.Random;

public class LayerEntityBreak implements LayerRenderer<EntityDragon>
{
    public void doRenderLayer(EntityDragon 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.deathTime > 0)
        {
//            Tessellator tessellator = Tessellator.getInstance();
            RenderBuffer worldrenderer = Tessellator.getBuffer();
            ItemRenderer.disableStandardItemLighting();
            float f = ((float)entitylivingbaseIn.deathTime + partialTicks) / 200.0F;
            float f1 = 0.0F;

            if (f > 0.8F)
            {
                f1 = (f - 0.8F) / 0.2F;
            }

            Random random = new Random(432L);
            GlState.disableTexture2D();
            GlState.shadeModel(GL11.GL_SMOOTH);
            GlState.enableBlend();
            GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
            GlState.disableAlpha();
            GlState.enableCull();
            GlState.depthMask(false);
            GL11.glPushMatrix();
            GL11.glTranslatef(0.0F, -1.0F, -2.0F);

            for (int i = 0; (float)i < (f + f * f) / 2.0F * 60.0F; ++i)
            {
                GL11.glRotatef(random.floatv() * 360.0F, 1.0F, 0.0F, 0.0F);
                GL11.glRotatef(random.floatv() * 360.0F, 0.0F, 1.0F, 0.0F);
                GL11.glRotatef(random.floatv() * 360.0F, 0.0F, 0.0F, 1.0F);
                GL11.glRotatef(random.floatv() * 360.0F, 1.0F, 0.0F, 0.0F);
                GL11.glRotatef(random.floatv() * 360.0F, 0.0F, 1.0F, 0.0F);
                GL11.glRotatef(random.floatv() * 360.0F + f * 90.0F, 0.0F, 0.0F, 1.0F);
                float f2 = random.floatv() * 20.0F + 5.0F + f1 * 10.0F;
                float f3 = random.floatv() * 2.0F + 1.0F + f1 * 2.0F;
                worldrenderer.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR);
                worldrenderer.pos(0.0D, 0.0D, 0.0D).color(255, 255, 255, (int)(255.0F * (1.0F - f1))).endVertex();
                worldrenderer.pos(-0.866D * (double)f3, (double)f2, (double)(-0.5F * f3)).color(255, 0, 255, 0).endVertex();
                worldrenderer.pos(0.866D * (double)f3, (double)f2, (double)(-0.5F * f3)).color(255, 0, 255, 0).endVertex();
                worldrenderer.pos(0.0D, (double)f2, (double)(1.0F * f3)).color(255, 0, 255, 0).endVertex();
                worldrenderer.pos(-0.866D * (double)f3, (double)f2, (double)(-0.5F * f3)).color(255, 0, 255, 0).endVertex();
                Tessellator.draw();
            }

            GL11.glPopMatrix();
            GlState.depthMask(true);
            GlState.disableCull();
            GlState.disableBlend();
            GlState.shadeModel(GL11.GL_FLAT);
            GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
            GlState.enableTexture2D();
            GlState.enableAlpha();
            ItemRenderer.enableStandardItemLighting();
        }
    }

    public boolean shouldCombineTextures()
    {
        return false;
    }
}
