
package studio.halbear.hem.gui.overlay;

import studio.halbear.hem.procedures.GooedOverlayDisplayOverlayIngameProcedure;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraft.world.World;
import net.minecraft.util.ResourceLocation;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.client.Minecraft;

import java.util.stream.Stream;
import java.util.Map;
import java.util.HashMap;
import java.util.AbstractMap;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.platform.GlStateManager;

@Mod.EventBusSubscriber
public class GooedOverlayOverlay {
	@OnlyIn(Dist.CLIENT)
	@SubscribeEvent(priority = EventPriority.HIGHEST)
	public static void eventHandler(RenderGameOverlayEvent.Post event) {
		if (event.getType() == RenderGameOverlayEvent.ElementType.HELMET) {
			int w = event.getWindow().getScaledWidth();
			int h = event.getWindow().getScaledHeight();
			int posX = w / 2;
			int posY = h / 2;
			World _world = null;
			double _x = 0;
			double _y = 0;
			double _z = 0;
			PlayerEntity entity = Minecraft.getInstance().player;
			if (entity != null) {
				_world = entity.world;
				_x = entity.getPosX();
				_y = entity.getPosY();
				_z = entity.getPosZ();
			}
			World world = _world;
			double x = _x;
			double y = _y;
			double z = _z;
			RenderSystem.disableDepthTest();
			RenderSystem.depthMask(false);
			RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
					GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
			RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
			RenderSystem.disableAlphaTest();
			if (GooedOverlayDisplayOverlayIngameProcedure.executeProcedure(Stream.of(new AbstractMap.SimpleEntry<>("entity", entity))
					.collect(HashMap::new, (_m, _e) -> _m.put(_e.getKey(), _e.getValue()), Map::putAll))) {
				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/transparentgreen.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), 0, 0, 0, 0, w, h, w, h);
				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -110, posY + 20, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 106, posY + -79, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -151, posY + -59, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 118, posY + 65, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -162, posY + 61, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -35, posY + -61, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -189, posY + -92, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 32, posY + 74, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -200, posY + 9, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 124, posY + -34, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -80, posY + -81, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -29, posY + 77, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 181, posY + -57, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -177, posY + -34, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 15, posY + -102, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 75, posY + 27, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -128, posY + 93, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -126, posY + -106, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 157, posY + -89, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 75, posY + -27, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 65, posY + 80, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -227, posY + -135, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 76, posY + -141, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 211, posY + 78, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -259, posY + 85, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -100, posY + 112, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -115, posY + -137, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -22, posY + -131, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -254, posY + -65, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 219, posY + 67, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -152, posY + 13, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 31, posY + -46, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 11, posY + 23, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -35, posY + 25, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -48, posY + -6, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -72, posY + 21, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -9, posY + 44, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -70, posY + 60, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -92, posY + 60, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 61, posY + -86, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 35, posY + 1, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -82, posY + -27, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -33, posY + -35, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 5, posY + 3, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -82, posY + 3, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 158, posY + 21, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 191, posY + 46, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -121, posY + -26, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed3.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + -217, posY + 85, 0, 0, 32, 32, 32, 32);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 182, posY + 96, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed2.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 189, posY + -116, 0, 0, 16, 16, 16, 16);

				Minecraft.getInstance().getTextureManager().bindTexture(new ResourceLocation("hem:textures/screens/gooed1.png"));
				Minecraft.getInstance().ingameGUI.blit(event.getMatrixStack(), posX + 89, posY + -119, 0, 0, 16, 16, 16, 16);

			}
			RenderSystem.depthMask(true);
			RenderSystem.enableDepthTest();
			RenderSystem.enableAlphaTest();
			RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
		}
	}
}
