// Date: 4/28/2012 9:46:20 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.HierarchicalModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.model.geom.builders.PartDefinition;
import net.minecraft.util.Mth;
import twilightforest.client.JappaPackReloadListener;
import twilightforest.entity.passive.Raven;

public class RavenModel extends HierarchicalModel<Raven> {
	private final ModelPart root;
	private final ModelPart head;
	private final ModelPart rightWing;
	private final ModelPart leftWing;
	private final ModelPart rightLeg;
	private final ModelPart leftLeg;

	public RavenModel(ModelPart root) {
		this.root = root;

		this.head = root.getChild("head");
		var body = root.getChild("body");
		this.rightWing = body.getChild("right_wing");
		this.leftWing = body.getChild("left_wing");
		this.rightLeg = root.getChild("right_leg");
		this.leftLeg = root.getChild("left_leg");
	}

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

	private static LayerDefinition create() {
		MeshDefinition meshdefinition = new MeshDefinition();
		PartDefinition base = meshdefinition.getRoot();

		PartDefinition head = base.addOrReplaceChild("head", CubeListBuilder.create()
				.texOffs(0, 0)
				.addBox(-1.5F, -1.5F, -3.0F, 3.0F, 3.0F, 3.0F),
			PartPose.offset(0.0F, 18.0F, 0.0F));

		head.addOrReplaceChild("beak1", CubeListBuilder.create()
				.texOffs(12, 0)
				.addBox(-0.5F, -1.0F, -2.0F, 1.0F, 1.0F, 2.0F),
			PartPose.offsetAndRotation(0.0F, 0.0F, -2.5F, 0.2617994F, 0.0F, 0.0F));

		head.addOrReplaceChild("beak2", CubeListBuilder.create()
				.texOffs(12, 0)
				.addBox(-0.5F, 0.0F, -2.0F, 1.0F, 1.0F, 2.0F),
			PartPose.offsetAndRotation(0.0F, 0.0F, -2.5F, -0.2617994F, 0.0F, 0.0F));

		var body = base.addOrReplaceChild("body", CubeListBuilder.create()
				.texOffs(0, 6)
				.addBox(-1.5F, 0.0F, -1.0F, 3.0F, 4.0F, 6.0F),
			PartPose.offsetAndRotation(0.0F, 17.0F, 1.0F, -0.5235988F, 0.0F, 0.0F));

		body.addOrReplaceChild("right_wing", CubeListBuilder.create()
				.texOffs(0, 16)
				.addBox(-1.0F, 0.0F, -1.5F, 1.0F, 3.0F, 6.0F),
			PartPose.offset(-1.5F, 0.0F, 1.0F));

		body.addOrReplaceChild("left_wing", CubeListBuilder.create()
				.texOffs(0, 16)
				.addBox(0.0F, 0.0F, -1.5F, 1.0F, 3.0F, 6.0F),
			PartPose.offset(1.5F, 0.0F, 1.0F));

		PartDefinition rightLeg = base.addOrReplaceChild("right_leg", CubeListBuilder.create()
				.texOffs(14, 16)
				.addBox(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F),
			PartPose.offset(-1.5F, 21.0F, 1.0F));

		rightLeg.addOrReplaceChild("right_foot", CubeListBuilder.create()
				.texOffs(14, 20)
				.addBox(0.0F, -1.0F, -2.0F, 1.0F, 1.0F, 2.0F),
			PartPose.offsetAndRotation(0.0F, 2.0F, 1.0F, 0.5235988F, 0.0F, 0.0F));

		PartDefinition leftLeg = base.addOrReplaceChild("left_leg", CubeListBuilder.create()
				.texOffs(14, 16)
				.addBox(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F),
			PartPose.offset(0.5F, 21.0F, 1.0F));

		leftLeg.addOrReplaceChild("left_foot", CubeListBuilder.create()
				.texOffs(14, 20)
				.addBox(0.0F, -1.0F, -2.0F, 1.0F, 1.0F, 2.0F),
			PartPose.offsetAndRotation(0.0F, 2.0F, 1.0F, 0.5235988F, 0.0F, 0.0F));

		body.addOrReplaceChild("tail", CubeListBuilder.create()
				.texOffs(0, 25)
				.addBox(-1.5F, -0.5F, 0.0F, 3.0F, 1.0F, 3.0F),
			PartPose.offsetAndRotation(0.0F, 0.5F, 4.5F, 0.5235988F, 0.0F, 0.0F));

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

	private static LayerDefinition createJappaModel() {
		MeshDefinition meshdefinition = new MeshDefinition();
		PartDefinition partdefinition = meshdefinition.getRoot();

		partdefinition.addOrReplaceChild("head", CubeListBuilder.create()
				.texOffs(0, 0)
				.addBox(-1.5F, -1.0F, -2.0F, 3.0F, 3.0F, 3.0F)
				.texOffs(9, 0)
				.addBox(-0.5F, 0.0F, -3.0F, 1.0F, 2.0F, 1.0F),
			PartPose.offset(0.0F, 18.5F, -2.0F));

		var body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create()
				.texOffs(0, 6)
				.addBox(-2.0F, -1.5F, 0.0F, 4.0F, 3.0F, 6.0F),
			PartPose.offsetAndRotation(0.0F, 18.5F, -2.0F, -0.4363323129985824F, 0.0F, 0.0F));

		body.addOrReplaceChild("right_wing", CubeListBuilder.create()
				.texOffs(0, 15)
				.addBox(-1.0F, 0.0F, -1.0F, 1.0F, 3.0F, 6.0F),
			PartPose.offsetAndRotation(-2.0F, -1.0F, 2.0F, 0.2617993877991494F, 0.0F, 0.0F));

		body.addOrReplaceChild("left_wing", CubeListBuilder.create()
				.texOffs(14, 15)
				.addBox(0.0F, 0.0F, -1.0F, 1.0F, 3.0F, 6.0F),
			PartPose.offsetAndRotation(2.0F, -1.0F, 2.0F, 0.2617993877991494F, 0.0F, 0.0F));

		partdefinition.addOrReplaceChild("right_leg", CubeListBuilder.create()
				.texOffs(8, 15)
				.addBox(0.0F, 0.0F, -1.0F, 1.0F, 2.0F, 2.0F),
			PartPose.offsetAndRotation(-1.0F, 0.0F, 0.0F, 0.7853981633974483F, 0.0F, 0.0F));

		partdefinition.addOrReplaceChild("left_leg", CubeListBuilder.create()
				.texOffs(14, 15)
				.addBox(0.0F, 0.0F, -1.0F, 1.0F, 2.0F, 2.0F),
			PartPose.offsetAndRotation(1.0F, 0.0F, 0.0F, 0.7853981633974483F, 0.0F, 0.0F));

		body.addOrReplaceChild("tail", CubeListBuilder.create()
				.texOffs(8, 0)
				.addBox(-2.5F, 0.0F, 0.0F, 5.0F, 0.0F, 5.0F),
			PartPose.offsetAndRotation(0.0F, -1.5F, 6.0F, -0.4363323129985824F, 0.0F, 0.0F));

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

	@Override
	public ModelPart root() {
		return this.root;
	}

	@Override
	public void setupAnim(Raven 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.head.zRot = netHeadYaw > 5.0F ? -0.2617994F : 0.0F;

		this.rightLeg.xRot = Mth.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
		this.leftLeg.xRot = Mth.cos(limbSwing * 0.6662F + Mth.PI) * 1.4F * limbSwingAmount;

		this.rightWing.zRot = ageInTicks;
		this.leftWing.zRot = -ageInTicks;

		if (entity.isBirdLanded()) {
			this.rightLeg.y = 21.0F;
			this.leftLeg.y = 21.0F;
		} else {
			this.rightLeg.y = 20.0F;
			this.leftLeg.y = 20.0F;
		}
	}
}
