
package studio.halbear.hem.entity.renderer;

import studio.halbear.hem.entity.LadyBugInFlightEntity;

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.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
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 com.mojang.blaze3d.vertex.IVertexBuilder;
import com.mojang.blaze3d.matrix.MatrixStack;

@OnlyIn(Dist.CLIENT)
public class LadyBugInFlightRenderer {
	public static class ModelRegisterHandler {
		@SubscribeEvent
		@OnlyIn(Dist.CLIENT)
		public void registerModels(ModelRegistryEvent event) {
			RenderingRegistry.registerEntityRenderingHandler(LadyBugInFlightEntity.entity, renderManager -> {
				return new MobRenderer(renderManager, new ModelLadyBirdInFlight(), 0.3f) {

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

	// Made with Blockbench 4.12.4
	// 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 ModelLadyBirdInFlight extends EntityModel<Entity> {
		private final ModelRenderer Body;
		private final ModelRenderer RightLeg;
		private final ModelRenderer cube_r1;
		private final ModelRenderer LeftLeg;
		private final ModelRenderer cube_r2;
		private final ModelRenderer RightLeg2;
		private final ModelRenderer cube_r3;
		private final ModelRenderer LeftLeg2;
		private final ModelRenderer cube_r4;
		private final ModelRenderer rightwing;
		private final ModelRenderer cube_r5;
		private final ModelRenderer leftwing;
		private final ModelRenderer cube_r6;
		private final ModelRenderer head;
		private final ModelRenderer cube_r7;

		public ModelLadyBirdInFlight() {
			textureWidth = 32;
			textureHeight = 32;
			Body = new ModelRenderer(this);
			Body.setRotationPoint(0.0F, 21.0F, -2.0F);
			setRotationAngle(Body, -0.2182F, 0.0F, 0.0F);
			Body.setTextureOffset(0, 0).addBox(-2.0F, 0.0F, 0.0F, 4.0F, 3.0F, 5.0F, 0.0F, false);
			RightLeg = new ModelRenderer(this);
			RightLeg.setRotationPoint(-2.0F, 2.25F, 2.5F);
			Body.addChild(RightLeg);
			cube_r1 = new ModelRenderer(this);
			cube_r1.setRotationPoint(0.0F, 0.0F, -0.5F);
			RightLeg.addChild(cube_r1);
			setRotationAngle(cube_r1, 0.0F, 0.0F, -0.5236F);
			cube_r1.setTextureOffset(19, 2).addBox(-2.0F, 0.0F, 2.0F, 2.0F, 0.0F, 1.0F, 0.0F, false);
			cube_r1.setTextureOffset(19, 0).addBox(-2.0F, 0.0F, -2.0F, 2.0F, 0.0F, 1.0F, 0.0F, false);
			LeftLeg = new ModelRenderer(this);
			LeftLeg.setRotationPoint(2.0F, 2.25F, 2.5F);
			Body.addChild(LeftLeg);
			cube_r2 = new ModelRenderer(this);
			cube_r2.setRotationPoint(0.0F, 0.0F, -0.5F);
			LeftLeg.addChild(cube_r2);
			setRotationAngle(cube_r2, 0.0F, 0.0F, 0.5236F);
			cube_r2.setTextureOffset(22, 20).addBox(0.0F, 0.0F, 2.0F, 2.0F, 0.0F, 1.0F, 0.0F, false);
			cube_r2.setTextureOffset(19, 6).addBox(0.0F, 0.0F, -2.0F, 2.0F, 0.0F, 1.0F, 0.0F, false);
			RightLeg2 = new ModelRenderer(this);
			RightLeg2.setRotationPoint(2.0F, 2.25F, 2.5F);
			Body.addChild(RightLeg2);
			cube_r3 = new ModelRenderer(this);
			cube_r3.setRotationPoint(0.0F, 0.0F, -0.5F);
			RightLeg2.addChild(cube_r3);
			setRotationAngle(cube_r3, 0.0F, 0.0F, 0.5236F);
			cube_r3.setTextureOffset(22, 18).addBox(0.0F, 0.0F, 0.0F, 2.0F, 0.0F, 1.0F, 0.0F, false);
			LeftLeg2 = new ModelRenderer(this);
			LeftLeg2.setRotationPoint(-2.0F, 2.25F, 2.5F);
			Body.addChild(LeftLeg2);
			cube_r4 = new ModelRenderer(this);
			cube_r4.setRotationPoint(0.0F, 0.0F, -0.5F);
			LeftLeg2.addChild(cube_r4);
			setRotationAngle(cube_r4, 0.0F, 0.0F, -0.5236F);
			cube_r4.setTextureOffset(19, 4).addBox(-2.0F, 0.0F, 0.0F, 2.0F, 0.0F, 1.0F, 0.0F, false);
			rightwing = new ModelRenderer(this);
			rightwing.setRotationPoint(-0.1F, 20.95F, -2.15F);
			setRotationAngle(rightwing, 0.108F, -0.404F, 0.7438F);
			cube_r5 = new ModelRenderer(this);
			cube_r5.setRotationPoint(-2.101F, 0.2457F, -0.1112F);
			rightwing.addChild(cube_r5);
			setRotationAngle(cube_r5, 0.0451F, -0.1289F, -0.0229F);
			cube_r5.setTextureOffset(0, 9).addBox(0.0F, 0.0F, 0.0F, 2.0F, 3.0F, 5.0F, 0.2F, false);
			leftwing = new ModelRenderer(this);
			leftwing.setRotationPoint(0.1F, 20.95F, -2.1F);
			setRotationAngle(leftwing, 0.127F, 0.532F, -0.6743F);
			cube_r6 = new ModelRenderer(this);
			cube_r6.setRotationPoint(2.1007F, 0.243F, -0.164F);
			leftwing.addChild(cube_r6);
			setRotationAngle(cube_r6, 0.0451F, 0.1289F, 0.0229F);
			cube_r6.setTextureOffset(15, 9).addBox(-2.0F, 0.0F, 0.0F, 2.0F, 3.0F, 5.0F, 0.2F, false);
			head = new ModelRenderer(this);
			head.setRotationPoint(0.0F, 22.5F, -2.25F);
			head.setTextureOffset(13, 18).addBox(-1.0F, -1.0F, -2.0F, 2.0F, 2.0F, 2.0F, 0.0F, false);
			cube_r7 = new ModelRenderer(this);
			cube_r7.setRotationPoint(0.5F, -1.0F, -2.0F);
			head.addChild(cube_r7);
			setRotationAngle(cube_r7, 0.48F, 0.0F, 0.0F);
			cube_r7.setTextureOffset(0, 18).addBox(-3.0F, -4.0F, 0.0F, 5.0F, 4.0F, 0.0F, 0.0F, false);
		}

		@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);
			rightwing.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
			leftwing.render(matrixStack, buffer, packedLight, packedOverlay, red, green, blue, alpha);
			head.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.LeftLeg.rotateAngleZ = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.RightLeg2.rotateAngleZ = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.LeftLeg2.rotateAngleZ = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.rightwing.rotateAngleY = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.leftwing.rotateAngleY = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.head.rotateAngleY = f3 / (180F / (float) Math.PI);
			this.head.rotateAngleX = f4 / (180F / (float) Math.PI);
			this.RightLeg.rotateAngleZ = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.Body.rotateAngleX = MathHelper.cos(f * 0.6662F + (float) Math.PI) * f1;
		}
	}

}
