package client.renderer.layers;

import org.lwjgl.opengl.GL11;

import client.Client;
import client.renderer.BlockRenderer;
import client.renderer.GlState;
import client.renderer.entity.RenderMooshroom;
import client.renderer.model.ModelQuadruped;
import client.renderer.texture.TextureMap;
import common.entity.animal.EntityMooshroom;
import common.init.Blocks;

public class LayerMooshroomMushroom implements LayerRenderer<EntityMooshroom>
{
    private final RenderMooshroom mooshroomRenderer;

    public LayerMooshroomMushroom(RenderMooshroom mooshroomRendererIn)
    {
        this.mooshroomRenderer = mooshroomRendererIn;
    }

    public void doRenderLayer(EntityMooshroom 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.isChild()) // && !entitylivingbaseIn.isInvisible())
        {
            BlockRenderer blockrendererdispatcher = Client.CLIENT.getBlockRendererDispatcher();
            this.mooshroomRenderer.bindTexture(TextureMap.locationBlocksTexture);
            GlState.enableCull();
            GlState.cullFace(GL11.GL_FRONT);
            GL11.glPushMatrix();
            GL11.glScalef(1.0F, -1.0F, 1.0F);
            GL11.glTranslatef(0.2F, 0.35F, 0.5F);
            GL11.glRotatef(42.0F, 0.0F, 1.0F, 0.0F);
            GL11.glPushMatrix();
            GL11.glTranslatef(-0.5F, -0.5F, 0.5F);
            blockrendererdispatcher.renderBlockBrightness(Blocks.red_mushroom.getState(), 1.0F);
            GL11.glPopMatrix();
            GL11.glPushMatrix();
            GL11.glTranslatef(0.1F, 0.0F, -0.6F);
            GL11.glRotatef(42.0F, 0.0F, 1.0F, 0.0F);
            GL11.glTranslatef(-0.5F, -0.5F, 0.5F);
            blockrendererdispatcher.renderBlockBrightness(Blocks.red_mushroom.getState(), 1.0F);
            GL11.glPopMatrix();
            GL11.glPopMatrix();
            GL11.glPushMatrix();
            ((ModelQuadruped)this.mooshroomRenderer.getMainModel()).head.postRender(0.0625F);
            GL11.glScalef(1.0F, -1.0F, 1.0F);
            GL11.glTranslatef(0.0F, 0.7F, -0.2F);
            GL11.glRotatef(12.0F, 0.0F, 1.0F, 0.0F);
            GL11.glTranslatef(-0.5F, -0.5F, 0.5F);
            blockrendererdispatcher.renderBlockBrightness(Blocks.red_mushroom.getState(), 1.0F);
            GL11.glPopMatrix();
            GlState.cullFace(GL11.GL_BACK);
            GlState.disableCull();
        }
    }

    public boolean shouldCombineTextures()
    {
        return true;
    }
}
