package tamaized.voidcraft.client.entity.boss.extra;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.MathHelper;
import tamaized.voidcraft.common.entity.boss.xia.finalphase.EntityWitherbrine;

public class ModelWitherbrine extends ModelBase {

	private final ModelRenderer[] upperBodyParts;
	private final ModelRenderer[] heads;

	public ModelWitherbrine(float p_i46302_1_) {
		this.textureWidth = 64;
		this.textureHeight = 64;
		this.upperBodyParts = new ModelRenderer[3];
		this.upperBodyParts[0] = new ModelRenderer(this, 0, 16);
		this.upperBodyParts[0].addBox(-10.0F, 3.9F, -0.5F, 20, 3, 3, p_i46302_1_);
		this.upperBodyParts[1] = (new ModelRenderer(this)).setTextureSize(this.textureWidth, this.textureHeight);
		this.upperBodyParts[1].setRotationPoint(-2.0F, 6.9F, -0.5F);
		this.upperBodyParts[1].setTextureOffset(0, 22).addBox(0.0F, 0.0F, 0.0F, 3, 10, 3, p_i46302_1_);
		this.upperBodyParts[1].setTextureOffset(24, 22).addBox(-4.0F, 1.5F, 0.5F, 11, 2, 2, p_i46302_1_);
		this.upperBodyParts[1].setTextureOffset(24, 22).addBox(-4.0F, 4.0F, 0.5F, 11, 2, 2, p_i46302_1_);
		this.upperBodyParts[1].setTextureOffset(24, 22).addBox(-4.0F, 6.5F, 0.5F, 11, 2, 2, p_i46302_1_);
		this.upperBodyParts[2] = new ModelRenderer(this, 12, 22);
		this.upperBodyParts[2].addBox(0.0F, 0.0F, 0.0F, 3, 6, 3, p_i46302_1_);
		this.heads = new ModelRenderer[3];
		this.heads[0] = new ModelRenderer(this, 0, 0);
		this.heads[0].addBox(-4.0F, -4.0F, -4.0F, 8, 8, 8, p_i46302_1_);
		this.heads[1] = new ModelRenderer(this, 32, 0);
		this.heads[1].addBox(-4.0F, -4.0F, -4.0F, 6, 6, 6, p_i46302_1_);
		this.heads[1].rotationPointX = -8.0F;
		this.heads[1].rotationPointY = 4.0F;
		this.heads[2] = new ModelRenderer(this, 32, 0);
		this.heads[2].addBox(-4.0F, -4.0F, -4.0F, 6, 6, 6, p_i46302_1_);
		this.heads[2].rotationPointX = 10.0F;
		this.heads[2].rotationPointY = 4.0F;
	}

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

		for (ModelRenderer modelrenderer : this.heads) {
			modelrenderer.render(scale);
		}

		for (ModelRenderer modelrenderer1 : this.upperBodyParts) {
			modelrenderer1.render(scale);
		}
	}

	/**
	 * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how "far" arms and legs can swing at most.
	 */
	@Override
	public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) {
		float f = MathHelper.cos(ageInTicks * 0.1F);
		this.upperBodyParts[1].rotateAngleX = (0.065F + 0.05F * f) * (float) Math.PI;
		this.upperBodyParts[2].setRotationPoint(-2.0F, 6.9F + MathHelper.cos(this.upperBodyParts[1].rotateAngleX) * 10.0F, -0.5F + MathHelper.sin(this.upperBodyParts[1].rotateAngleX) * 10.0F);
		this.upperBodyParts[2].rotateAngleX = (0.265F + 0.1F * f) * (float) Math.PI;
		this.heads[0].rotateAngleY = netHeadYaw * 0.017453292F;
		this.heads[0].rotateAngleX = headPitch * 0.017453292F;
	}

	@Override
	public void setLivingAnimations(EntityLivingBase entitylivingbaseIn, float p_78086_2_, float p_78086_3_, float partialTickTime) {
		EntityWitherbrine entitywither = (EntityWitherbrine) entitylivingbaseIn;

		for (int i = 1; i < 3; ++i) {
			this.heads[i].rotateAngleY = (entitywither.getHeadYRotation(i - 1) - entitylivingbaseIn.renderYawOffset) * 0.017453292F;
			this.heads[i].rotateAngleX = entitywither.getHeadXRotation(i - 1) * 0.017453292F;
		}
	}

}
