package ru.dbotthepony.mc.otm.client.model;

// Made with Blockbench 4.1.3
// Exported for Minecraft version 1.17 with Mojang mappings
// Paste this class into your mod and generate all required imports


import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.event.EntityRenderersEvent;

import javax.annotation.ParametersAreNonnullByDefault;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class TritaniumArmorModel {
	// This layer location should be baked with EntityRendererProvider.Context in the entity renderer and passed into this model's constructor
	public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(ModelLayers.PLAYER_OUTER_ARMOR.getModel(), "otm_armor_main");
	public static final ModelLayerLocation LAYER_LOCATION_LEGS = new ModelLayerLocation(ModelLayers.PLAYER_OUTER_ARMOR.getModel(), "otm_armor_legs");

	private static HumanoidModel<?> model;
	private static HumanoidModel<?> modelLegs;
	private static LayerDefinition def;
	private static LayerDefinition defLegs;

	public static HumanoidModel<?> getModel() {
		if (model == null) {
			return model = new HumanoidModel<>(def.bakeRoot());
		}

		return model;
	}

	public static HumanoidModel<?> getModelLegs() {
		if (modelLegs == null) {
			return modelLegs = new HumanoidModel<>(defLegs.bakeRoot());
		}

		return modelLegs;
	}

	public static LayerDefinition createBodyLayer() {
		MeshDefinition meshdefinition = new MeshDefinition();
		PartDefinition partdefinition = meshdefinition.getRoot();

		PartDefinition head = partdefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -8.3F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.51F))
				.texOffs(0, 53).addBox(-4.0F, -0.3F, -5.0F, 8.0F, 0.0F, 1.0F, new CubeDeformation(0.52F))
				.texOffs(32, 0).addBox(-4.0F, -8.3F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.7F))
				.texOffs(46, 52).addBox(-3.0F, -7.6F, 4.4F, 6.0F, 2.0F, 1.0F, new CubeDeformation(0.5F))
				.texOffs(0, 58).addBox(-4.0F, -5.4F, -4.9F, 8.0F, 5.0F, 1.0F, new CubeDeformation(0.5F))
				.texOffs(0, 42).addBox(-5.5F, -3.7F, -4.0F, 2.0F, 4.0F, 7.0F, new CubeDeformation(0.0F))
				.texOffs(0, 42).addBox(3.5F, -3.7F, -4.0F, 2.0F, 4.0F, 7.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));

		PartDefinition cube_r1 = head.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(0, 55).addBox(-4.0F, -1.2F, -0.04F, 8.0F, 2.0F, 1.0F, new CubeDeformation(0.5F)), PartPose.offsetAndRotation(0.0F, -7.0F, -4.5F, -0.3054F, 0.0F, 0.0F));

		PartDefinition hat = partdefinition.addOrReplaceChild("hat", CubeListBuilder.create(), PartPose.offset(0.0F, 24.0F, 0.0F));

		PartDefinition body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create().texOffs(40, 16).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.41F))
				.texOffs(0, 32).addBox(-4.0F, 0.0F, -5.7F, 8.0F, 6.0F, 3.0F, new CubeDeformation(0.4F))
				.texOffs(44, 33).addBox(-4.0F, 0.0F, 2.8F, 8.0F, 6.0F, 2.0F, new CubeDeformation(0.4F))
				.texOffs(48, 2).addBox(-3.0F, -1.0F, 4.0F, 6.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));

		PartDefinition backpackslope_r1 = body.addOrReplaceChild("backpackslope_r1", CubeListBuilder.create().texOffs(44, 41).addBox(-4.0F, 0.4F, -2.4F, 8.0F, 3.0F, 2.0F, new CubeDeformation(0.39F)), PartPose.offsetAndRotation(0.0F, 6.4F, 5.2F, -1.0908F, 0.0F, 0.0F));

		PartDefinition chestplateslope_r1 = body.addOrReplaceChild("chestplateslope_r1", CubeListBuilder.create().texOffs(44, 41).addBox(-4.0F, 0.5F, 0.4F, 8.0F, 4.0F, 2.0F, new CubeDeformation(0.39F)), PartPose.offsetAndRotation(0.0F, 6.4F, -6.2F, 1.2217F, 0.0F, 0.0F));

		PartDefinition right_arm = partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(24, 32).addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.3F))
		.texOffs(42, 56).addBox(-4.0F, -3.0F, -2.0F, 4.0F, 4.0F, 4.0F, new CubeDeformation(0.4F)), PartPose.offset(-5.0F, 2.0F, 0.0F));

		PartDefinition left_arm = partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(24, 32).mirror().addBox(-1.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.3F)).mirror(false)
		.texOffs(42, 56).mirror().addBox(0.0F, -3.0F, -2.0F, 4.0F, 4.0F, 4.0F, new CubeDeformation(0.4F)).mirror(false), PartPose.offset(5.0F, 2.0F, 0.0F));

		PartDefinition right_leg = partdefinition.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(26, 48).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(1.0F)), PartPose.offset(-1.9F, 12.0F, 0.0F));

		PartDefinition left_leg = partdefinition.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(26, 48).mirror().addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(1.0F)).mirror(false), PartPose.offset(1.9F, 12.0F, 0.0F));

		model = null;
		return def = LayerDefinition.create(meshdefinition, 64, 64);
	}

	public static LayerDefinition createLegsLayer() {
		MeshDefinition meshdefinition = new MeshDefinition();
		PartDefinition partdefinition = meshdefinition.getRoot();

		partdefinition.addOrReplaceChild("body", CubeListBuilder.create().texOffs(16, 16).addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.31F)), PartPose.offset(0.0F, 0.0F, 0.0F));
		partdefinition.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(0, 16).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.3F)), PartPose.offset(-1.9F, 12.0F, 0.0F));
		partdefinition.addOrReplaceChild("left_leg", CubeListBuilder.create().texOffs(0, 16).mirror().addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, new CubeDeformation(0.3F)).mirror(false), PartPose.offset(1.9F, 12.0F, 0.0F));

		partdefinition.addOrReplaceChild("hat", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
		partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
		partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));
		partdefinition.addOrReplaceChild("head", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));

		modelLegs = null;
		return defLegs = LayerDefinition.create(meshdefinition, 64, 64);
	}

	public static void register(EntityRenderersEvent.RegisterLayerDefinitions event) {
		event.registerLayerDefinition(LAYER_LOCATION, TritaniumArmorModel::createBodyLayer);
		event.registerLayerDefinition(LAYER_LOCATION_LEGS, TritaniumArmorModel::createLegsLayer);
	}
}
