// Date: 4/27/2012 9:49:06 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.QuadrupedModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.util.Mth;
import twilightforest.client.JappaPackReloadListener;
import twilightforest.entity.passive.Squirrel;

public class SquirrelModel extends QuadrupedModel<Squirrel> {

	private final ModelPart tail;
	private final ModelPart tailPart1;
	private final ModelPart tailPart2;

	public SquirrelModel(ModelPart root) {
		super(root, false, 4.0F, 4.0F, 2.0F, 2.0F, 24);
		this.tail = this.body.getChild("tail");
		this.tailPart1 = this.tail.getChild("tail_1");
		this.tailPart2 = this.tailPart1.getChild("tail_2");
	}

	public static LayerDefinition checkForPack() {
		return JappaPackReloadListener.INSTANCE.isJappaPackLoaded() ? createJappaModel() : create();
	}

	private static LayerDefinition create() {
		MeshDefinition meshdefinition = QuadrupedModel.createBodyMesh(0, CubeDeformation.NONE);
		PartDefinition partdefinition = meshdefinition.getRoot();

		partdefinition.addOrReplaceChild("head", CubeListBuilder.create()
				.texOffs(0, 0)
				.addBox(-2.0F, -5.0F, -3.0F, 4.0F, 4.0F, 4.0F)
				.texOffs(16, 0)
				.addBox(-2.0F, -6.0F, -0.5F, 1.0F, 1.0F, 1.0F)
				.texOffs(16, 0)
				.addBox(1.0F, -6.0F, -0.5F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(0.0F, 22.0F, -2.0F));

		var body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create().mirror()
				.texOffs(0, 8)
				.addBox(-2.0F, -1.0F, -2.0F, 4.0F, 3.0F, 5.0F),
			PartPose.offset(0.0F, 21.0F, 0.0F));

		partdefinition.addOrReplaceChild("right_hind_leg", CubeListBuilder.create().mirror()
				.texOffs(0, 16)
				.addBox(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(-2.0F, 23.0F, 2.0F));

		partdefinition.addOrReplaceChild("left_hind_leg", CubeListBuilder.create().mirror()
				.texOffs(0, 16)
				.addBox(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(1.0F, 23.0F, 2.0F));

		partdefinition.addOrReplaceChild("right_front_leg", CubeListBuilder.create()
				.texOffs(0, 16)
				.addBox(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(-2.0F, 23.0F, -2.0F));

		partdefinition.addOrReplaceChild("left_front_leg", CubeListBuilder.create()
				.texOffs(0, 16)
				.addBox(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(1.0F, 23.0F, -2.0F));

		var tail = body.addOrReplaceChild("tail", CubeListBuilder.create()
				.texOffs(0, 18)
				.addBox(-0.5F, -1.5F, 0.5F, 1.0F, 1.0F, 1.0F)
				.texOffs(0, 20)
				.addBox(-1.5F, -4.0F, 1.0F, 3.0F, 3.0F, 3.0F),
			PartPose.offset(0.0F, 0.0F, 2.0F));

		var tail1 = tail.addOrReplaceChild("tail_1", CubeListBuilder.create()
				.texOffs(0, 20)
				.addBox(0.0F, -3.0F, -1.5F, 3.0F, 3.0F, 3.0F),
			PartPose.offset(-1.5F, -4.0F, 2.5F));

		tail1.addOrReplaceChild("tail_2", CubeListBuilder.create()
				.texOffs(0, 26)
				.addBox(1.5F, -3.0F, -1.5F, 3.0F, 3.0F, 3.0F),
			PartPose.offset(-1.5F, -3.0F, 0.0F));

		return LayerDefinition.create(meshdefinition, 32, 32);
	}

	private static LayerDefinition createJappaModel() {
		MeshDefinition meshdefinition = QuadrupedModel.createBodyMesh(1, CubeDeformation.NONE);
		PartDefinition partdefinition = meshdefinition.getRoot();

		partdefinition.addOrReplaceChild("head", CubeListBuilder.create()
				.texOffs(0, 0)
				.addBox(-2.0F, -2.0F, -3.0F, 4.0F, 4.0F, 4.0F)
				.addBox(-2.0F, -3.0F, -1.0F, 1.0F, 1.0F, 1.0F)
				.texOffs(0, 2)
				.addBox(1.0F, -3.0F, -1.0F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(0.0F, 20.0F, -3.0F));

		var body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create()
				.texOffs(0, 8)
				.addBox(-2.0F, -3.0F, -3.0F, 4.0F, 3.0F, 5.0F),
			PartPose.offset(0.0F, 23.0F, 0.0F));

		partdefinition.addOrReplaceChild("right_front_leg", CubeListBuilder.create()
				.texOffs(0, 16)
				.addBox(-0.5F, 0.0F, -0.5F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(-1.5F, 23.0F, -2.5F));

		partdefinition.addOrReplaceChild("left_front_leg", CubeListBuilder.create()
				.texOffs(4, 16)
				.addBox(-0.5F, 0.0F, -0.5F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(1.5F, 23.0F, -2.5F));

		partdefinition.addOrReplaceChild("right_hind_leg", CubeListBuilder.create()
				.texOffs(0, 18)
				.addBox(-0.5F, 0.0F, -0.5F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(-1.5F, 23.0F, 1.5F));

		partdefinition.addOrReplaceChild("left_hind_leg", CubeListBuilder.create()
				.texOffs(4, 18)
				.addBox(-0.5F, 0.0F, -0.5F, 1.0F, 1.0F, 1.0F),
			PartPose.offset(1.5F, 23.0F, 1.5F));

		var tail = body.addOrReplaceChild("tail", CubeListBuilder.create()
				.texOffs(18, 0)
				.addBox(-1.5F, 0.0F, -1.5F, 3.0F, 4.0F, 3.0F),
			PartPose.offset(0.0F, -3.0F, 2.0F));

		var tail1 = tail.addOrReplaceChild("tail_1", CubeListBuilder.create()
				.texOffs(13, 11)
				.addBox(-1.5F, -1.0F, 0.0F, 3.0F, 3.0F, 5.0F),
			PartPose.offset(0.0F, 4.0F, 0.5F));

		tail1.addOrReplaceChild("tail_2", CubeListBuilder.create(), PartPose.ZERO);

		return LayerDefinition.create(meshdefinition, 32, 32);
	}

	@Override
	public void setupAnim(Squirrel entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
		this.head.xRot = headPitch * Mth.DEG_TO_RAD;
		this.head.yRot = netHeadYaw * Mth.DEG_TO_RAD;
		this.rightHindLeg.xRot = Mth.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
		this.leftHindLeg.xRot = Mth.cos(limbSwing * 0.6662F + Mth.PI) * 1.4F * limbSwingAmount;
		this.rightFrontLeg.xRot = Mth.cos(limbSwing * 0.6662F + Mth.PI) * 1.4F * limbSwingAmount;
		this.leftFrontLeg.xRot = Mth.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;

		if (limbSwingAmount > 0.2) {
			float wiggle = Math.min(limbSwingAmount, 0.6F);
			this.tail.xRot = (JappaPackReloadListener.INSTANCE.isJappaPackLoaded() ? 2.5F : 0.2F) + (Mth.cos(ageInTicks * 0.6662F) - Mth.PI / 3.0F) * wiggle;
			this.tailPart1.xRot = Mth.cos(ageInTicks * 0.7774F) * 1.2F * wiggle;
			this.tailPart2.xRot = Mth.cos(ageInTicks * 0.8886F + Mth.PI / 2.0F) * 1.4F * wiggle;
		} else {
			this.tail.xRot = (JappaPackReloadListener.INSTANCE.isJappaPackLoaded() ? 2.5F : 0.2F) + Mth.cos(ageInTicks * 0.3335F) * 0.15F;
			this.tailPart1.xRot = 0.1F + Mth.cos(ageInTicks * 0.4445F) * 0.20F;
			this.tailPart2.xRot = 0.1F + Mth.cos(ageInTicks * 0.5555F) * 0.25F;
		}
	}
}
