package hmggirlfront.event;

import org.lwjgl.opengl.GL11;

import gvclib.mod_GVCLib;
import gvclib.event.vehicle.client.RenderHUDEvent;
import gvclib.item.ItemArmor_Base;
import gvclib.item.ItemArmor_NewObj;
import gvclib.item.ItemGunBase;
import hmggirlfront.items.ItemSOFLAM;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiIngame;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class GFEventSOFLAM {
	@SideOnly(Side.CLIENT)
    @SubscribeEvent
	  public void renderfovGun(FOVUpdateEvent event)
	  {
		Minecraft minecraft = FMLClientHandler.instance().getClient();
		EntityPlayer entityplayer = event.getEntity();
		if(entityplayer.isSneaking()) {
			ItemStack itemstack = entityplayer.getHeldItemMainhand();
			ItemStack itemstackl = entityplayer.getHeldItemOffhand();
			if (!itemstack.isEmpty() && itemstack.getItem() instanceof ItemSOFLAM) {
				event.setNewfov(event.getFov() / 4);
			}
			if (!itemstackl.isEmpty() && itemstackl.getItem() instanceof ItemSOFLAM) {
				event.setNewfov(event.getFov() / 4);
			}
		}
	  }
	
	@SideOnly(Side.CLIENT)
	  @SubscribeEvent
	  public void onEvent(RenderGameOverlayEvent.Text event)
	  {
		  Minecraft minecraft = FMLClientHandler.instance().getClient();
		  World world = FMLClientHandler.instance().getWorldClient();
		  ScaledResolution scaledresolution = new ScaledResolution(minecraft);
	        int i = scaledresolution.getScaledWidth();
	        int j = scaledresolution.getScaledHeight();
			EntityPlayer entityplayer = minecraft.player;
			FontRenderer fontrenderer = minecraft.fontRenderer;
	        minecraft.entityRenderer.setupOverlayRendering();
	        if(entityplayer.isSneaking()) {
				ItemStack itemstack = entityplayer.getHeldItemMainhand();
				ItemStack itemstackl = entityplayer.getHeldItemOffhand();
				if (!itemstack.isEmpty() && itemstack.getItem() instanceof ItemSOFLAM) {
					this.renderPumpkinBlur(minecraft,scaledresolution, "hmggirlfront:textures/misc/over.png", 0.4F);
					this.renderPumpkinBlur(minecraft,scaledresolution, "hmggirlfront:textures/misc/soflam.png", 1.0F);
				}
				if (!itemstackl.isEmpty() && itemstackl.getItem() instanceof ItemSOFLAM) {
					this.renderPumpkinBlur(minecraft,scaledresolution, "hmggirlfront:textures/misc/over.png", 0.4F);
					this.renderPumpkinBlur(minecraft,scaledresolution, "hmggirlfront:textures/misc/soflam.png", 1.0F);
				}
			}
	        
      	
      
	  }
	
	@SideOnly(Side.CLIENT)
	protected void renderPumpkinBlur(Minecraft minecraft, ScaledResolution scaledRes, String adss, float tou) {
		//GL11.glPushMatrix();// 12
		GL11.glEnable(GL11.GL_BLEND);
		GlStateManager.disableDepth();
		GlStateManager.depthMask(false);
		GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
				GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
				GlStateManager.DestFactor.ZERO);
		//GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
		GL11.glColor4f(1.0F, 1.0F, 1.0F, tou);
		GlStateManager.disableAlpha();
		minecraft.getTextureManager().bindTexture(new ResourceLocation(adss));
		Tessellator tessellator = Tessellator.getInstance();
		BufferBuilder bufferbuilder = tessellator.getBuffer();
      bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
      bufferbuilder.pos(0.0D, (double)scaledRes.getScaledHeight(), -90.0D).tex(0.0D, 1.0D).endVertex();
      bufferbuilder.pos((double)scaledRes.getScaledWidth(), (double)scaledRes.getScaledHeight(), -90.0D).tex(1.0D, 1.0D).endVertex();
      bufferbuilder.pos((double)scaledRes.getScaledWidth(), 0.0D, -90.0D).tex(1.0D, 0.0D).endVertex();
      bufferbuilder.pos(0.0D, 0.0D, -90.0D).tex(0.0D, 0.0D).endVertex();
		tessellator.draw();
		GlStateManager.depthMask(true);
		GlStateManager.enableDepth();
		GlStateManager.enableAlpha();
		GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
		GL11.glDisable(GL11.GL_BLEND);
		//GL11.glPopMatrix();// 12
	}
}
