// Date: 4/25/2012 10:28:13 PM
// Template version 1.1
// Java generated by Techne
// Keep in mind that you still need to fill in some blanks
// - ZeuX

package twilightforest.client.model.entity;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.MathHelper;
import twilightforest.entity.passive.EntityTFBird;

public class ModelTFTinyBird extends ModelBase {
	//fields
	ModelRenderer beak;
	ModelRenderer head;
	ModelRenderer body;
	ModelRenderer rightarm;
	ModelRenderer leftarm;
	ModelRenderer rightleg;
	ModelRenderer leftleg;
	ModelRenderer tail;

	public ModelTFTinyBird() {
		textureWidth = 32;
		textureHeight = 32;

		head = new ModelRenderer(this, 0, 0);
		head.addBox(-1.5F, -1.5F, -1.5F, 3, 3, 3);
		head.setRotationPoint(0F, 20.5F, -0.5F);
		head.setTextureSize(32, 32);
		head.mirror = true;
		setRotation(head, 0F, 0F, 0F);

		beak = new ModelRenderer(this, 12, 0);
		beak.addBox(-0.5F, -0.5F, -0.5F, 1, 1, 1);
		beak.setRotationPoint(0F, 0.5F, -2F);

		head.addChild(beak);


		body = new ModelRenderer(this, 0, 6);
		body.addBox(-1.5F, 0F, -1F, 3, 3, 3);
		body.setRotationPoint(0F, 20F, 0F);
		body.setTextureSize(32, 32);
		body.mirror = true;
		setRotation(body, 0F, 0F, 0F);
		rightarm = new ModelRenderer(this, 12, 2);
		rightarm.addBox(-1F, 0F, -1.5F, 1, 2, 3);
		rightarm.setRotationPoint(-1.5F, 20.5F, 1F);
		rightarm.setTextureSize(32, 32);
		rightarm.mirror = true;
		setRotation(rightarm, 0F, 0F, 0F);
		leftarm = new ModelRenderer(this, 12, 2);
		leftarm.addBox(0F, 0F, -1.5F, 1, 2, 3);
		leftarm.setRotationPoint(1.5F, 20.5F, 1F);
		leftarm.setTextureSize(32, 32);
		leftarm.mirror = true;
		setRotation(leftarm, 0F, 0F, 0F);
		rightleg = new ModelRenderer(this, 0, 12);
		rightleg.addBox(0F, 0F, 0F, 1, 1, 1);
		rightleg.setRotationPoint(-1.5F, 23F, 0F);
		rightleg.setTextureSize(32, 32);
		rightleg.mirror = true;
		setRotation(rightleg, 0F, 0F, 0F);
		leftleg = new ModelRenderer(this, 0, 12);
		leftleg.addBox(0.5F, 0F, 0F, 1, 1, 1);
		leftleg.setRotationPoint(0F, 23F, 0F);
		leftleg.setTextureSize(32, 32);
		leftleg.mirror = true;
		setRotation(leftleg, 0F, 0F, 0F);
		tail = new ModelRenderer(this, 0, 14);
		tail.addBox(-1.5F, -0.5F, 0F, 3, 1, 2);
		tail.setRotationPoint(0F, 22F, 2F);
		tail.setTextureSize(32, 32);
		tail.mirror = true;
		setRotation(tail, 0F, 0F, 0F);
	}

	/**
	 * Sets the models various rotation angles then renders the model.
	 */
	@Override
	public void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
		setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entity);

		if (isChild) {
			float f = 2.0F;
			GlStateManager.pushMatrix();
			GlStateManager.translate(0.0F, 5F * scale, 0.75F * scale);
			head.render(scale);
			GlStateManager.popMatrix();
			GlStateManager.pushMatrix();
			GlStateManager.scale(1.0F / f, 1.0F / f, 1.0F / f);
			GlStateManager.translate(0.0F, 24F * scale, 0.0F);
			body.render(scale);
			rightleg.render(scale);
			leftleg.render(scale);
			rightarm.render(scale);
			leftarm.render(scale);
			GlStateManager.popMatrix();
		} else {
			head.render(scale);
			body.render(scale);
			rightleg.render(scale);
			leftleg.render(scale);
			rightarm.render(scale);
			leftarm.render(scale);
			tail.render(scale);
//			beak.render(scale);
		}
	}

	private void setRotation(ModelRenderer model, float x, float y, float z) {
		model.rotateAngleX = x;
		model.rotateAngleY = y;
		model.rotateAngleZ = z;
	}


	/**
	 * Sets the models various rotation angles.
	 */
	@Override
	public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entity) {
		head.rotateAngleX = headPitch / (180F / (float) Math.PI);
		head.rotateAngleY = netHeadYaw / (180F / (float) Math.PI);

		rightleg.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
		leftleg.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + (float) Math.PI) * 1.4F * limbSwingAmount;

		rightarm.rotateAngleZ = ageInTicks;
		leftarm.rotateAngleZ = -ageInTicks;

		if (((EntityTFBird) entity).isBirdLanded()) {
			rightleg.rotationPointY = 23;
			leftleg.rotationPointY = 23;
		} else {
			rightleg.rotationPointY = 22.5F;
			leftleg.rotationPointY = 22.5F;
		}

	}
}
