package client.renderer.model;

import org.lwjgl.opengl.GL11;

import common.entity.Entity;
import common.entity.types.EntityLiving;
import common.util.ExtMath;

public class ModelMouse extends ModelBase
{
    ModelRenderer backLeftLeg;
    ModelRenderer backRightLeg;
    ModelRenderer frontLeftLeg;
    ModelRenderer frontRightLeg;
    ModelRenderer tail;
    ModelRenderer tail2;
    ModelRenderer head;
    ModelRenderer body;
    int speed = 1;

    public ModelMouse()
    {
        this.textureWidth = 32;
        this.textureHeight = 32;
        this.setTextureOffset("head.main", 0, 0);
        this.setTextureOffset("head.nose", 22, 12);
        this.setTextureOffset("head.ear1", 0, 9);
        this.setTextureOffset("head.ear2", 8, 9);
        this.setTextureOffset("head.whiskers", 22, 14);
        this.head = new ModelRenderer(this, "head");
        this.head.addBox("main", -2.5F, -2.0F, -3.0F, 5, 4, 5);
        this.head.addBox("nose", -1.0F, 0.0F, -4.0F, 2, 1, 1);
        this.head.addBox("ear1", -4.0F, -4.0F, 0.0F, 3, 3, 1);
        this.head.addBox("ear2", 1.0F, -4.0F, 0.0F, 3, 3, 1);
        this.head.addBox("whiskers", -3.0F, -1.5F, -3.25F, 6, 4);
        this.head.setRotationPoint(0.0F, 16.5F, -8.5F);
        this.body = new ModelRenderer(this, 0, 13);
        this.body.addBox(-3.0F, 3.0F, -8.0F, 6, 14, 5, 0.0F);
        this.body.setRotationPoint(0.0F, 12.0F, -10.0F);
        this.tail = new ModelRenderer(this, 28, 9);
        this.tail.addBox(-0.5F, 0.0F, 0.0F, 1, 8, 1);
        this.tail.rotateAngleX = 0.9F;
        this.tail.setRotationPoint(0.0F, 16.0F, 6.0F);
        this.tail2 = new ModelRenderer(this, 28, 0);
        this.tail2.addBox(-0.5F, 0.0F, 0.0F, 1, 8, 1);
        this.tail2.setRotationPoint(0.0F, 21.0F, 12.0F);
        this.backLeftLeg = new ModelRenderer(this, 20, 0);
        this.backLeftLeg.addBox(-1.0F, 0.0F, 1.0F, 2, 4, 2);
        this.backLeftLeg.setRotationPoint(1.5F, 18.0F, 2.0F);
        this.backRightLeg = new ModelRenderer(this, 22, 18);
        this.backRightLeg.addBox(-1.0F, 0.0F, 1.0F, 2, 4, 2);
        this.backRightLeg.setRotationPoint(-1.5F, 18.0F, 2.0F);
        this.frontLeftLeg = new ModelRenderer(this, 20, 6);
        this.frontLeftLeg.addBox(-1.0F, 0.0F, 0.0F, 2, 4, 2);
        this.frontLeftLeg.setRotationPoint(1.5F, 18.0F, -5.0F);
        this.frontRightLeg = new ModelRenderer(this, 22, 24);
        this.frontRightLeg.addBox(-1.0F, 0.0F, 0.0F, 2, 4, 2);
        this.frontRightLeg.setRotationPoint(-1.5F, 18.0F, -5.0F);
    }
    
    public void render(Entity entityIn, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale)
    {
        this.setRotationAngles(p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, scale, entityIn);

        float s = this.isChild ? 0.125f : 0.25f;
        GL11.glPushMatrix();
        GL11.glScalef(s, s, s);
        GL11.glTranslatef(0.0f, (this.isChild ? 171.0f : 74.5f) * scale, 0.0f);
//        if (this.isChild)
//        {
//            float f = 2.0F;
//            GlState.pushMatrix();
//            GlState.scale(1.5F / f, 1.5F / f, 1.5F / f);
//            GlState.translate(0.0F, 10.0F * scale, 4.0F * scale);
//            this.head.render(scale);
//            GlState.popMatrix();
//            GlState.pushMatrix();
//            GlState.scale(1.0F / f, 1.0F / f, 1.0F / f);
//            GlState.translate(0.0F, 24.0F * scale, 0.0F);
//            this.body.render(scale);
//            this.backLeftLeg.render(scale);
//            this.backRightLeg.render(scale);
//            this.frontLeftLeg.render(scale);
//            this.frontRightLeg.render(scale);
//            this.tail.render(scale);
//            this.tail2.render(scale);
//            GlState.popMatrix();
//        }
//        else
//        {
            this.head.render(scale);
            this.body.render(scale);
            this.tail.render(scale);
            this.tail2.render(scale);
            this.backLeftLeg.render(scale);
            this.backRightLeg.render(scale);
            this.frontLeftLeg.render(scale);
            this.frontRightLeg.render(scale);
//        }
        GL11.glPopMatrix();
    }
    
    public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn)
    {
        this.head.rotateAngleX = headPitch / (180F / (float)Math.PI);
        this.head.rotateAngleY = netHeadYaw / (180F / (float)Math.PI);
        this.body.rotateAngleX = ((float)Math.PI / 2F);

        if (this.speed == 2)
        {
            this.backLeftLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F) * 1.0F * limbSwingAmount;
            this.backRightLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + 0.3F) * 1.0F * limbSwingAmount;
            this.frontLeftLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI + 0.3F) * 1.0F * limbSwingAmount;
            this.frontRightLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.0F * limbSwingAmount;
            this.tail2.rotateAngleX = 1.7278761F + ((float)Math.PI / 10F) * ExtMath.cos(limbSwing) * limbSwingAmount;
        }
        else
        {
            this.backLeftLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F) * 1.0F * limbSwingAmount;
            this.backRightLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.0F * limbSwingAmount;
            this.frontLeftLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.0F * limbSwingAmount;
            this.frontRightLeg.rotateAngleX = ExtMath.cos(limbSwing * 0.6662F) * 1.0F * limbSwingAmount;

            if (this.speed == 1)
            {
                this.tail2.rotateAngleX = 1.7278761F + ((float)Math.PI / 4F) * ExtMath.cos(limbSwing) * limbSwingAmount;
            }
            else
            {
                this.tail2.rotateAngleX = 1.7278761F + 0.47123894F * ExtMath.cos(limbSwing) * limbSwingAmount;
            }
        }
    }
    
    public void setLivingAnimations(EntityLiving entitylivingbaseIn, float p_78086_2_, float p_78086_3_, float partialTickTime)
    {
        this.body.rotationPointY = 12.0F;
        this.body.rotationPointZ = -10.0F;
        this.head.rotationPointY = 16.5F;
        this.head.rotationPointZ = -8.5F;
        this.tail.rotationPointY = 16.0F;
        this.tail.rotationPointZ = 6.0F;
        this.tail2.rotationPointY = 21.0F;
        this.tail2.rotationPointZ = 12.0F;
        this.frontLeftLeg.rotationPointY = this.frontRightLeg.rotationPointY = 18.0F;
        this.frontLeftLeg.rotationPointZ = this.frontRightLeg.rotationPointZ = -5.0F;
        this.backLeftLeg.rotationPointY = this.backRightLeg.rotationPointY = 18.0F;
        this.backLeftLeg.rotationPointZ = this.backRightLeg.rotationPointZ = 2.0F;
        this.tail.rotateAngleX = 0.9F;

        if (entitylivingbaseIn.isSneakingVisually())
        {
            ++this.body.rotationPointY;
            this.head.rotationPointY += 2.0F;
            ++this.tail.rotationPointY;
            this.tail2.rotationPointY += -4.0F;
            this.tail2.rotationPointZ += 2.0F;
            this.tail.rotateAngleX = ((float)Math.PI / 2F);
            this.tail2.rotateAngleX = ((float)Math.PI / 2F);
            this.speed = 0;
        }
        else if (entitylivingbaseIn.isSprinting())
        {
            this.tail2.rotationPointY = this.tail.rotationPointY;
            this.tail2.rotationPointZ += 2.0F;
            this.tail.rotateAngleX = ((float)Math.PI / 2F);
            this.tail2.rotateAngleX = ((float)Math.PI / 2F);
            this.speed = 2;
        }
        else
        {
            this.speed = 1;
        }
    }
}
