
package studio.halbear.hem.entity.renderer;

import studio.halbear.hem.procedures.FluffaloShavedEntityShakingConditionProcedure;
import studio.halbear.hem.entity.FluffaloShavedEntity;

import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraft.world.World;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.entity.MobRenderer;

import java.util.Collections;

import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.mojang.blaze3d.matrix.MatrixStack;

@OnlyIn(Dist.CLIENT)
public class FluffaloShavedRenderer {
	public static class ModelRegisterHandler {
		@SubscribeEvent
		@OnlyIn(Dist.CLIENT)
		public void registerModels(ModelRegistryEvent event) {
			RenderingRegistry.registerEntityRenderingHandler(FluffaloShavedEntity.entity, renderManager -> {
				return new MobRenderer(renderManager, new ModelFluffaloShaved(), 1.5f) {

					@Override
					public ResourceLocation getEntityTexture(Entity entity) {
						return new ResourceLocation("hem:textures/entities/fluffalo.png");
					}

					@Override
					protected boolean func_230495_a_(LivingEntity _ent) {
						Entity entity = _ent;
						World world = entity.world;
						double x = entity.getPosX();
						double y = entity.getPosY();
						double z = entity.getPosZ();
						return FluffaloShavedEntityShakingConditionProcedure.executeProcedure(Collections.emptyMap());
					}
				};
			});
		}
	}

	// Made with Blockbench 5.0.3
	// Exported for Minecraft version 1.15 - 1.16 with MCP mappings
	// Paste this class into your mod and generate all required imports
	public static class ModelFluffaloShaved extends EntityModel<Entity> {
		private final ModelRenderer Body;
		private final ModelRenderer Tail2;
		private final ModelRenderer Tail;
		private final ModelRenderer cube_r1;
		private final ModelRenderer Head;
		private final ModelRenderer horn;
		private final ModelRenderer cube_r2;
		private final ModelRenderer LeftFoot1;
		private final ModelRenderer RightFoot1;
		private final ModelRenderer LeftFoot2;
		private final ModelRenderer RightFoot2;
		private final ModelRenderer LeftFoot3;
		private final ModelRenderer RightFoot3;

		public ModelFluffaloShaved() {
			textureWidth = 256;
			textureHeight = 256;
			Body = new ModelRenderer(this);
			Body.setRotationPoint(-0.5F, 12.0F, -3.25F);
			Body.setTextureOffset(0, 199).addBox(-11.5F, -14.0F, -15.75F, 24.0F, 21.0F, 36.0F, -0.5F, false);
			Tail2 = new ModelRenderer(this);
			Tail2.setRotationPoint(0.5F, -7.0F, 21.75F);
			Body.addChild(Tail2);
			Tail = new ModelRenderer(this);
			Tail.setRotationPoint(0.0F, 0.0F, 0.0F);
			Tail2.addChild(Tail);
			cube_r1 = new ModelRenderer(this);
			cube_r1.setRotationPoint(0.0F, 0.0F, -2.0F);
			Tail.addChild(cube_r1);
			setRotationAngle(cube_r1, 0.0873F, 0.0F, 0.0F);
			cube_r1.setTextureOffset(148, 131).addBox(-3.0F, -2.0F, 0.0F, 6.0F, 21.0F, 0.0F, 0.0F, false);
			Head = new ModelRenderer(this);
			Head.setRotationPoint(0.0F, -2.0F, -15.0F);
			Body.addChild(Head);
			Head.setTextureOffset(148, 160).addBox(-3.5F, -1.0F, -10.75F, 7.0F, 6.0F, 2.0F, 0.0F, false);
			Head.setTextureOffset(120, 63).addBox(-5.5F, -6.0F, -8.75F, 11.0F, 11.0F, 9.0F, 0.0F, false);
			horn = new ModelRenderer(this);
			horn.setRotationPoint(0.0F, 2.0F, -11.0F);
			Head.addChild(horn);
			cube_r2 = new ModelRenderer(this);
			cube_r2.setRotationPoint(0.0F, 0.0F, 0.0F);
			horn.addChild(cube_r2);
			setRotationAngle(cube_r2, -0.4363F, 0.0F, 0.0F);
			cube_r2.setTextureOffset(120, 120).addBox(-8.5F, -2.0F, 0.0F, 17.0F, 11.0F, 0.0F, 0.0F, false);
			LeftFoot1 = new ModelRenderer(this);
			LeftFoot1.setRotationPoint(7.0F, 17.0F, -12.0F);
			LeftFoot1.setTextureOffset(120, 131).addBox(-4.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.0F, false);
			LeftFoot1.setTextureOffset(120, 145).addBox(-4.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.25F, false);
			RightFoot1 = new ModelRenderer(this);
			RightFoot1.setRotationPoint(-7.0F, 17.0F, -12.0F);
			RightFoot1.setTextureOffset(120, 131).addBox(-3.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.0F, true);
			RightFoot1.setTextureOffset(120, 145).addBox(-3.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.25F, true);
			LeftFoot2 = new ModelRenderer(this);
			LeftFoot2.setRotationPoint(7.0F, 17.0F, 0.0F);
			LeftFoot2.setTextureOffset(120, 131).addBox(-4.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.0F, false);
			LeftFoot2.setTextureOffset(120, 145).addBox(-4.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.25F, false);
			RightFoot2 = new ModelRenderer(this);
			RightFoot2.setRotationPoint(-7.0F, 17.0F, 0.0F);
			RightFoot2.setTextureOffset(120, 131).addBox(-3.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.0F, true);
			RightFoot2.setTextureOffset(120, 145).addBox(-3.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.25F, true);
			LeftFoot3 = new ModelRenderer(this);
			LeftFoot3.setRotationPoint(7.0F, 17.0F, 11.0F);
			LeftFoot3.setTextureOffset(120, 131).addBox(-4.0F, 0.0F, -3.0F, 7.0F, 7.0F, 7.0F, 0.0F, false);
			LeftFoot3.setTextureOffset(120, 145).addBox(-4.0F, 0.0F, -3.0F, 7.0F, 7.0F, 7.0F, 0.25F, false);
			RightFoot3 = new ModelRenderer(this);
			RightFoot3.setRotationPoint(-7.0F, 17.0F, 12.0F);
			RightFoot3.setTextureOffset(120, 131).addBox(-3.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.0F, true);
			RightFoot3.setTextureOffset(120, 145).addBox(-3.0F, 0.0F, -4.0F, 7.0F, 7.0F, 7.0F, 0.25F, true);
		}

		@Override
		public void render(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue,
				float alpha) {
			Body.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
			LeftFoot1.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
			RightFoot1.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
			LeftFoot2.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
			RightFoot2.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
			LeftFoot3.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
			RightFoot3.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
		}

		public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
			modelRenderer.rotateAngleX = x;
			modelRenderer.rotateAngleY = y;
			modelRenderer.rotateAngleZ = z;
		}

		public void setRotationAngles(Entity e, float f, float f1, float f2, float f3, float f4) {
			this.Head.rotateAngleY = f3 / (180F / (float) Math.PI);
			this.Head.rotateAngleX = f4 / (180F / (float) Math.PI);
			this.Tail2.rotateAngleZ = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.RightFoot3.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.RightFoot2.rotateAngleX = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.horn.rotateAngleX = MathHelper.cos(f * 0.6662F + (float) Math.PI) * f1;
			this.Tail.rotateAngleZ = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.Body.rotateAngleZ = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.LeftFoot3.rotateAngleX = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.RightFoot1.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.LeftFoot2.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.LeftFoot1.rotateAngleX = MathHelper.cos(f * 1.0F) * -1.0F * f1;
		}
	}

}
