package com.zivilon.cinder_loe.client.model.npc;

import lotr.common.LOTRMod;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
import org.lwjgl.opengl.GL11;

import com.zivilon.cinder_loe.entity.npc.radagast.FangornElk;

public class ModelFangornElk extends ModelBase {
  private ModelRenderer body;
  
  private ModelRenderer leg1;
  
  private ModelRenderer leg2;
  
  private ModelRenderer leg3;
  
  private ModelRenderer leg4;
  
  private ModelRenderer head;
  
  private ModelRenderer nose;
  
  private ModelRenderer antlersRight_1;
  
  private ModelRenderer antlersRight_2;
  
  private ModelRenderer antlersRight_3;
  
  private ModelRenderer antlersRight_4;
  
  private ModelRenderer antlersLeft_1;
  
  private ModelRenderer antlersLeft_2;
  
  private ModelRenderer antlersLeft_3;
  
  private ModelRenderer antlersLeft_4;
  
  public ModelFangornElk() {
    this(0.0F);
  }
  
  public ModelFangornElk(float f) {
    this.textureWidth = 128;
    this.textureHeight = 64;
    this.body = new ModelRenderer(this, 0, 0);
    this.body.setRotationPoint(0.0F, 4.0F, 9.0F);
    this.body.addBox(-6.0F, -4.0F, -21.0F, 12, 11, 26, f);
    ModelRenderer tail = new ModelRenderer(this, 0, 54);
    tail.addBox(-1.0F, -5.0F, 2.0F, 2, 2, 8, f);
    tail.rotateAngleX = (float)Math.toRadians(-60.0D);
    this.body.addChild(tail);
    this.leg1 = new ModelRenderer(this, 42, 37);
    this.leg1.setRotationPoint(-4.0F, 3.0F, 8.0F);
    this.leg1.addBox(-5.5F, 0.0F, -3.0F, 7, 11, 8, f);
    this.leg1.setTextureOffset(26, 37).addBox(-4.0F, 11.0F, -1.0F, 4, 10, 4, f);
    this.leg2 = new ModelRenderer(this, 42, 37);
    this.leg2.mirror = true;
    this.leg2.setRotationPoint(4.0F, 3.0F, 8.0F);
    this.leg2.addBox(-1.5F, 0.0F, -3.0F, 7, 11, 8, f);
    this.leg2.setTextureOffset(26, 37).addBox(0.0F, 11.0F, -1.0F, 4, 10, 4, f);
    this.leg3 = new ModelRenderer(this, 0, 37);
    this.leg3.setRotationPoint(-4.0F, 4.0F, -6.0F);
    this.leg3.addBox(-4.5F, 0.0F, -3.0F, 6, 10, 7, f);
    this.leg3.setTextureOffset(26, 37).addBox(-3.5F, 10.0F, -2.0F, 4, 10, 4, f);
    this.leg4 = new ModelRenderer(this, 0, 37);
    this.leg4.mirror = true;
    this.leg4.setRotationPoint(4.0F, 4.0F, -6.0F);
    this.leg4.addBox(-1.5F, 0.0F, -3.0F, 6, 10, 7, f);
    this.leg4.setTextureOffset(26, 37).addBox(-0.5F, 10.0F, -2.0F, 4, 10, 4, f);
    this.head = new ModelRenderer(this, 50, 0);
    this.head.setRotationPoint(0.0F, 4.0F, -10.0F);
    this.head.addBox(-2.0F, -10.0F, -4.0F, 4, 12, 8, f);
    this.head.setTextureOffset(74, 0).addBox(-3.0F, -16.0F, -8.0F, 6, 6, 13, f);
    this.head.setTextureOffset(50, 20);
    this.head.addBox(-2.0F, -18.0F, 3.0F, 1, 2, 1, f);
    this.head.mirror = true;
    this.head.addBox(1.0F, -18.0F, 3.0F, 1, 2, 1, f);
    this.nose = new ModelRenderer(this, 56, 20);
    this.nose.addBox(-1.0F, -14.5F, -9.0F, 2, 2, 1, f);
    this.antlersRight_1 = new ModelRenderer(this, 0, 0);
    this.antlersRight_1.addBox(10.0F, -19.0F, 2.5F, 1, 12, 1, f);
    this.antlersRight_1.rotateAngleZ = (float)Math.toRadians(-65.0D);
    this.antlersRight_2 = new ModelRenderer(this, 4, 0);
    this.antlersRight_2.addBox(-3.0F, -23.6F, 2.5F, 1, 8, 1, f);
    this.antlersRight_2.rotateAngleZ = (float)Math.toRadians(-15.0D);
    this.antlersRight_3 = new ModelRenderer(this, 8, 0);
    this.antlersRight_3.addBox(-8.0F, -36.0F, 2.5F, 1, 16, 1, f);
    this.antlersRight_3.rotateAngleZ = (float)Math.toRadians(-15.0D);
    this.antlersRight_4 = new ModelRenderer(this, 12, 0);
    this.antlersRight_4.addBox(7.5F, -35.0F, 2.5F, 1, 10, 1, f);
    this.antlersRight_4.rotateAngleZ = (float)Math.toRadians(-50.0D);
    this.head.addChild(this.antlersRight_1);
    this.head.addChild(this.antlersRight_2);
    this.head.addChild(this.antlersRight_3);
    this.head.addChild(this.antlersRight_4);
    this.antlersLeft_1 = new ModelRenderer(this, 0, 0);
    this.antlersLeft_1.mirror = true;
    this.antlersLeft_1.addBox(-11.0F, -19.0F, 2.5F, 1, 12, 1, f);
    this.antlersLeft_1.rotateAngleZ = (float)Math.toRadians(65.0D);
    this.antlersLeft_2 = new ModelRenderer(this, 4, 0);
    this.antlersLeft_2.mirror = true;
    this.antlersLeft_2.addBox(2.0F, -23.6F, 2.5F, 1, 8, 1, f);
    this.antlersLeft_2.rotateAngleZ = (float)Math.toRadians(15.0D);
    this.antlersLeft_3 = new ModelRenderer(this, 8, 0);
    this.antlersLeft_3.mirror = true;
    this.antlersLeft_3.addBox(7.0F, -36.0F, 2.5F, 1, 16, 1, f);
    this.antlersLeft_3.rotateAngleZ = (float)Math.toRadians(15.0D);
    this.antlersLeft_4 = new ModelRenderer(this, 12, 0);
    this.antlersLeft_4.mirror = true;
    this.antlersLeft_4.addBox(-8.5F, -35.0F, 2.5F, 1, 10, 1, f);
    this.antlersLeft_4.rotateAngleZ = (float)Math.toRadians(50.0D);
    this.head.addChild(this.antlersLeft_1);
    this.head.addChild(this.antlersLeft_2);
    this.head.addChild(this.antlersLeft_3);
    this.head.addChild(this.antlersLeft_4);
  }
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
    FangornElk elk = (FangornElk)entity;
    setRotationAngles(f, f1, f2, f3, f4, f5, (Entity)elk);
    GL11.glPushMatrix();
    float scale = 1.0F;
    GL11.glTranslatef(0.0F, 24.0F * (1.0F - scale) * f5, 0.0F);
    GL11.glScalef(scale, scale, scale);
    boolean showAntlers = (scale > 0.75F);
    this.antlersRight_1.showModel = showAntlers;
    this.antlersRight_2.showModel = showAntlers;
    this.antlersRight_3.showModel = showAntlers;
    this.antlersRight_4.showModel = showAntlers;
    this.antlersLeft_1.showModel = showAntlers;
    this.antlersLeft_2.showModel = showAntlers;
    this.antlersLeft_3.showModel = showAntlers;
    this.antlersLeft_4.showModel = showAntlers;
    this.body.render(f5);
    this.leg1.render(f5);
    this.leg2.render(f5);
    this.leg3.render(f5);
    this.leg4.render(f5);
    this.head.render(f5);
    if (LOTRMod.isChristmas())
      GL11.glColor3f(1.0F, 0.0F, 0.0F); 
    this.nose.render(f5);
    if (LOTRMod.isChristmas())
      GL11.glColor3f(1.0F, 1.0F, 1.0F); 
    GL11.glPopMatrix();
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) {
    float rearAmount = 0.0F;
    float antiRearAmount = 1.0F - rearAmount;
    this.head.rotationPointY = 4.0F;
    this.head.rotationPointZ = -10.0F;
    this.head.rotateAngleX = (float)Math.toRadians(20.0D);
    this.head.rotateAngleY = 0.0F;
    this.head.rotationPointY = rearAmount * -6.0F + antiRearAmount * this.head.rotationPointY;
    this.head.rotationPointZ = rearAmount * -1.0F + antiRearAmount * this.head.rotationPointZ;
    this.head.rotateAngleX = (float)(this.head.rotateAngleX + Math.toRadians(f4));
    this.head.rotateAngleY = (float)(this.head.rotateAngleY + Math.toRadians(f3));
    this.head.rotateAngleX = antiRearAmount * this.head.rotateAngleX;
    this.head.rotateAngleY = antiRearAmount * this.head.rotateAngleY;
    if (f1 > 0.2F)
      this.head.rotateAngleX += MathHelper.cos(f * 0.3F) * 0.1F * f1; 
    this.nose.setRotationPoint(this.head.rotationPointX, this.head.rotationPointY, this.head.rotationPointZ);
    this.nose.rotateAngleX = this.head.rotateAngleX;
    this.nose.rotateAngleY = this.head.rotateAngleY;
    this.nose.rotateAngleZ = this.head.rotateAngleZ;
    this.body.rotateAngleX = 0.0F;
    this.body.rotateAngleX = rearAmount * -0.7853982F + antiRearAmount * this.body.rotateAngleX;
    float legRotation = MathHelper.cos(f * 0.4F + 3.1415927F) * f1;
    float f17 = -1.0471976F;
    float f18 = 0.2617994F * rearAmount;
    float f19 = MathHelper.cos(f2 * 0.4F + 3.1415927F);
    this.leg4.rotationPointY = -2.0F * rearAmount + 4.0F * antiRearAmount;
    this.leg4.rotationPointZ = -2.0F * rearAmount + -6.0F * antiRearAmount;
    this.leg3.rotationPointY = this.leg4.rotationPointY;
    this.leg3.rotationPointZ = this.leg4.rotationPointZ;
    this.leg1.rotateAngleX = f18 + legRotation * antiRearAmount;
    this.leg2.rotateAngleX = f18 + -legRotation * antiRearAmount;
    this.leg3.rotateAngleX = (f17 + -f19) * rearAmount + -legRotation * 0.8F * antiRearAmount;
    this.leg4.rotateAngleX = (f17 + f19) * rearAmount + legRotation * 0.8F * antiRearAmount;
  }
}
