
package studio.halbear.hem.entity.renderer;

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

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 GoldFishRenderer {
	public static class ModelRegisterHandler {
		@SubscribeEvent
		@OnlyIn(Dist.CLIENT)
		public void registerModels(ModelRegistryEvent event) {
			RenderingRegistry.registerEntityRenderingHandler(GoldFishEntity.entity, renderManager -> {
				return new MobRenderer(renderManager, new Modelgoldfish(), 0.2f) {

					@Override
					public ResourceLocation getEntityTexture(Entity entity) {
						return new ResourceLocation("hem:textures/entities/goldfish.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 Modelgoldfish extends EntityModel<Entity> {
		private final ModelRenderer Head;
		private final ModelRenderer Body;
		private final ModelRenderer LeftFin;
		private final ModelRenderer LeftFin_r1;
		private final ModelRenderer RightFin;
		private final ModelRenderer RightFin_r1;
		private final ModelRenderer TailFin2;
		private final ModelRenderer TailFin;

		public Modelgoldfish() {
			textureWidth = 64;
			textureHeight = 64;
			Head = new ModelRenderer(this);
			Head.setRotationPoint(0.0F, 21.0F, -1.0F);
			Body = new ModelRenderer(this);
			Body.setRotationPoint(0.0F, 1.0F, 4.0F);
			Head.addChild(Body);
			Body.setTextureOffset(24, 19).addBox(-1.0F, -2.0F, -6.0F, 2.0F, 4.0F, 6.0F, 0.0F, false);
			Body.setTextureOffset(0, 0).addBox(0.0F, -5.0F, -9.0F, 0.0F, 10.0F, 9.0F, 0.0F, false);
			LeftFin = new ModelRenderer(this);
			LeftFin.setRotationPoint(1.0F, 0.0F, -3.0F);
			Body.addChild(LeftFin);
			LeftFin_r1 = new ModelRenderer(this);
			LeftFin_r1.setRotationPoint(0.0F, 0.0F, 0.0F);
			LeftFin.addChild(LeftFin_r1);
			setRotationAngle(LeftFin_r1, 0.0F, 0.0F, 0.5236F);
			LeftFin_r1.setTextureOffset(0, 19).addBox(0.0F, 0.0F, -3.0F, 6.0F, 0.0F, 6.0F, 0.0F, false);
			RightFin = new ModelRenderer(this);
			RightFin.setRotationPoint(-1.0F, 0.0F, -3.0F);
			Body.addChild(RightFin);
			RightFin_r1 = new ModelRenderer(this);
			RightFin_r1.setRotationPoint(0.0F, 0.0F, 0.0F);
			RightFin.addChild(RightFin_r1);
			setRotationAngle(RightFin_r1, 0.0F, 0.0F, -0.5236F);
			RightFin_r1.setTextureOffset(0, 19).addBox(-6.0F, 0.0F, -3.0F, 6.0F, 0.0F, 6.0F, 0.0F, true);
			TailFin2 = new ModelRenderer(this);
			TailFin2.setRotationPoint(0.0F, 0.0F, 0.0F);
			Body.addChild(TailFin2);
			TailFin = new ModelRenderer(this);
			TailFin.setRotationPoint(0.0F, 0.0F, 0.0F);
			TailFin2.addChild(TailFin);
			TailFin.setTextureOffset(18, 0).addBox(0.0F, -5.0F, 0.0F, 0.0F, 10.0F, 9.0F, 0.0F, false);
		}

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

}
