
package studio.halbear.hem.entity.renderer;

import studio.halbear.hem.procedures.TigerFishEntityShakingConditionProcedure;
import studio.halbear.hem.entity.TigerFishEntity;

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.stream.Stream;
import java.util.Map;
import java.util.HashMap;
import java.util.AbstractMap;

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

@OnlyIn(Dist.CLIENT)
public class TigerFishRenderer {
	public static class ModelRegisterHandler {
		@SubscribeEvent
		@OnlyIn(Dist.CLIENT)
		public void registerModels(ModelRegistryEvent event) {
			RenderingRegistry.registerEntityRenderingHandler(TigerFishEntity.entity, renderManager -> {
				return new MobRenderer(renderManager, new ModelTigerFish(), 0.5f) {

					@Override
					public ResourceLocation getEntityTexture(Entity entity) {
						return new ResourceLocation("hem:textures/entities/tigerfish.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 TigerFishEntityShakingConditionProcedure.executeProcedure(Stream.of(new AbstractMap.SimpleEntry<>("entity", entity))
								.collect(HashMap::new, (_m, _e) -> _m.put(_e.getKey(), _e.getValue()), Map::putAll));
					}
				};
			});
		}
	}

	// 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 ModelTigerFish extends EntityModel<Entity> {
		private final ModelRenderer OuterBody;
		private final ModelRenderer Body;
		private final ModelRenderer HeadY;
		private final ModelRenderer leftWhisker;
		private final ModelRenderer leftWhisker_r1;
		private final ModelRenderer RightWhisker;
		private final ModelRenderer RightWhisker_r1;
		private final ModelRenderer RightFin;
		private final ModelRenderer TailFin3;
		private final ModelRenderer TailFin;
		private final ModelRenderer TailFin2;
		private final ModelRenderer leftFin;

		public ModelTigerFish() {
			textureWidth = 128;
			textureHeight = 128;
			OuterBody = new ModelRenderer(this);
			OuterBody.setRotationPoint(0.0F, 21.0F, 8.0F);
			Body = new ModelRenderer(this);
			Body.setRotationPoint(0.0F, 0.0F, 0.0F);
			OuterBody.addChild(Body);
			HeadY = new ModelRenderer(this);
			HeadY.setRotationPoint(0.0F, 0.0F, -12.0F);
			Body.addChild(HeadY);
			HeadY.setTextureOffset(0, 0).addBox(-5.0F, -2.0F, -4.0F, 10.0F, 4.0F, 16.0F, 0.0F, false);
			HeadY.setTextureOffset(0, 20).addBox(-5.0F, -2.0F, -4.0F, 10.0F, 4.0F, 16.0F, 0.2F, false);
			HeadY.setTextureOffset(52, 16).addBox(0.0F, -7.0F, -4.0F, 0.0F, 11.0F, 16.0F, 0.0F, false);
			leftWhisker = new ModelRenderer(this);
			leftWhisker.setRotationPoint(2.0F, -1.0F, -4.05F);
			HeadY.addChild(leftWhisker);
			leftWhisker_r1 = new ModelRenderer(this);
			leftWhisker_r1.setRotationPoint(0.0F, 0.0F, 0.0F);
			leftWhisker.addChild(leftWhisker_r1);
			setRotationAngle(leftWhisker_r1, 0.119F, 0.734F, 0.1767F);
			leftWhisker_r1.setTextureOffset(0, 56).addBox(0.0F, -4.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F, false);
			RightWhisker = new ModelRenderer(this);
			RightWhisker.setRotationPoint(-2.0F, -1.0F, -4.05F);
			HeadY.addChild(RightWhisker);
			RightWhisker_r1 = new ModelRenderer(this);
			RightWhisker_r1.setRotationPoint(0.0F, 0.0F, 0.0F);
			RightWhisker.addChild(RightWhisker_r1);
			setRotationAngle(RightWhisker_r1, 0.1578F, -0.7279F, -0.2348F);
			RightWhisker_r1.setTextureOffset(16, 56).addBox(-8.0F, -4.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F, false);
			RightFin = new ModelRenderer(this);
			RightFin.setRotationPoint(-5.0F, 2.0F, 4.0F);
			HeadY.addChild(RightFin);
			RightFin.setTextureOffset(0, 40).addBox(-10.0F, 0.0F, -8.0F, 10.0F, 0.0F, 16.0F, 0.0F, false);
			TailFin3 = new ModelRenderer(this);
			TailFin3.setRotationPoint(0.0F, 0.0F, 12.0F);
			HeadY.addChild(TailFin3);
			TailFin = new ModelRenderer(this);
			TailFin.setRotationPoint(0.0F, 0.0F, 0.0F);
			TailFin3.addChild(TailFin);
			TailFin2 = new ModelRenderer(this);
			TailFin2.setRotationPoint(0.0F, 0.0F, 0.0F);
			TailFin.addChild(TailFin2);
			TailFin2.setTextureOffset(52, 43).addBox(0.0F, -7.0F, 0.0F, 0.0F, 11.0F, 16.0F, 0.0F, false);
			leftFin = new ModelRenderer(this);
			leftFin.setRotationPoint(5.0F, 2.0F, 4.0F);
			HeadY.addChild(leftFin);
			leftFin.setTextureOffset(0, 40).addBox(0.0F, 0.0F, -8.0F, 10.0F, 0.0F, 16.0F, 0.0F, true);
		}

		@Override
		public void render(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue,
				float alpha) {
			OuterBody.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.TailFin.rotateAngleY = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.leftWhisker.rotateAngleY = MathHelper.cos(f * 0.6662F + (float) Math.PI) * f1;
			this.OuterBody.rotateAngleY = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.TailFin3.rotateAngleY = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.RightWhisker.rotateAngleY = MathHelper.cos(f * 0.6662F) * f1;
			this.TailFin2.rotateAngleY = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.leftFin.rotateAngleZ = MathHelper.cos(f * 0.6662F + (float) Math.PI) * f1;
			this.HeadY.rotateAngleX = f4 / (180F / (float) Math.PI);
			this.Body.rotateAngleY = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.RightFin.rotateAngleZ = MathHelper.cos(f * 0.6662F) * f1;
		}
	}

}
