package hmggirlfront.event;

import java.awt.Color;
import java.util.List;

import org.lwjgl.opengl.GL11;

import gvclib.mod_GVCLib;
import hmggirlfront.mod_GirlFront;
import hmggirlfront.block.Block_BaseBase;
import hmggirlfront.block.tile.TileEntity_BaseBase;
import hmggirlfront.entity.EntityDoll;
import hmggirlfront.entity.drone.EntityDrone;
import hmggirlfront.entity.mob.EntityIBC10u;
import hmggirlfront.entity.mob.EntityIBCBoss01M;
import hmggirlfront.entity.npc.EntityNPC_Doll;
import hmggirlfront.items.ItemDollCN;
import hmggirlfront.items.ItemDollGunBase;
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.GlStateManager;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
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.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
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 GFEventHUD {
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onUPEvent(LivingUpdateEvent event) {
		EntityLivingBase target = event.getEntityLiving();
		/*if (mod_GVCLib.proxy.left()) {
			mod_GirlFront.test_x = mod_GirlFront.test_x + 0.1F;
			String dd = String.format("%1$.2f", mod_GirlFront.test_x);
			System.out.println("x : " + String.format(dd));
		}
		if (mod_GVCLib.proxy.right()) {
			mod_GirlFront.test_x = mod_GirlFront.test_x - 0.1F;
			String dd = String.format("%1$.2f", mod_GirlFront.test_x);
			System.out.println("x : " + String.format(dd));
		}
		if (mod_GVCLib.proxy.up()) {
			mod_GirlFront.test_y = mod_GirlFront.test_y + 0.1F;
			String dd = String.format("%1$.2f", mod_GirlFront.test_y);
			System.out.println("y : " + String.format(dd));
		}
		if (mod_GVCLib.proxy.down()) {
			mod_GirlFront.test_y = mod_GirlFront.test_y - 0.1F;
			String dd = String.format("%1$.2f", mod_GirlFront.test_y);
			System.out.println("y : " + String.format(dd));
		}*/
		/*if (target instanceof EntityPlayer) {
			Minecraft minecraft = Minecraft.getMinecraft();
			EntityPlayer entityplayer = (EntityPlayer) target;
			if (mod_GVCLib.proxy.left()) {
				mod_GirlFront.test_x = mod_GirlFront.test_x + 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_x);
				System.out.println("x : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.right()) {
				mod_GirlFront.test_x = mod_GirlFront.test_x - 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_x);
				System.out.println("x : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.up()) {
				mod_GirlFront.test_y = mod_GirlFront.test_y + 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_y);
				System.out.println("y : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.down()) {
				mod_GirlFront.test_y = mod_GirlFront.test_y - 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_y);
				System.out.println("y : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.LBRACKET()) {
				mod_GirlFront.test_z = mod_GirlFront.test_z + 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_z);
				System.out.println("z : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.RBRACKET()) {
				mod_GirlFront.test_z = mod_GirlFront.test_z - 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_z);
				System.out.println("z : " + String.format(dd));
			}
			
			if (mod_GVCLib.proxy.numpad_4()) {
				mod_GirlFront.test_2_x = mod_GirlFront.test_2_x + 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_2_x);
				System.out.println("x2 : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.numpad_6()) {
				mod_GirlFront.test_2_x = mod_GirlFront.test_2_x - 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_2_x);
				System.out.println("x2 : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.numpad_8()) {
				mod_GirlFront.test_2_y = mod_GirlFront.test_2_y + 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_2_y);
				System.out.println("y2 : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.numpad_2()) {
				mod_GirlFront.test_2_y = mod_GirlFront.test_2_y - 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_2_y);
				System.out.println("y2 : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.numpad_1()) {
				mod_GirlFront.test_2_z = mod_GirlFront.test_2_z + 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_2_z);
				System.out.println("z2 : " + String.format(dd));
			}
			if (mod_GVCLib.proxy.numpad_3()) {
				mod_GirlFront.test_2_z = mod_GirlFront.test_2_z - 2;
				String dd = String.format("%1$.2f", mod_GirlFront.test_2_z);
				System.out.println("z2 : " + String.format(dd));
			}
		}*/
	}
	
	
	@SideOnly(Side.CLIENT)
    @SubscribeEvent
	  public void rendergun(RenderHandEvent event)
	  {
		Minecraft minecraft = FMLClientHandler.instance().getClient();
		EntityPlayer entityplayer = minecraft.player;
		ItemStack itemstack = ((EntityPlayer) (entityplayer)).getHeldItemMainhand();
		ItemStack itemstackl = ((EntityPlayer) (entityplayer)).getHeldItemOffhand();
		if(itemstack.isEmpty()) {
			{
				List llist = entityplayer.world.getEntitiesWithinAABBExcludingEntity(entityplayer, entityplayer.getEntityBoundingBox()
		        		.expand(entityplayer.motionX, entityplayer.motionY, entityplayer.motionZ).grow(1.0D));
				if (llist != null) {
					for (int lj = 0; lj < llist.size(); lj++) {
						Entity entity1 = (Entity) llist.get(lj);
						if (entity1 != null) {
							if (entity1 instanceof EntityDoll) {
								EntityDoll doll = (EntityDoll) entity1;
								 //if (doll.processInteract(entityplayer, EnumHand.MAIN_HAND)) 
								//if(entityplayer.interactOn(doll, EnumHand.MAIN_HAND) == EnumActionResult.SUCCESS)
								//if(CPacketUseEntity.Action.INTERACT != null)
								if(doll.usehand)
								 {
									 float ticks = (float)Math.sin(doll.ontick100sec * 0.2) * 0.2F;
									 GL11.glTranslatef(ticks, 0, 0);
									 GL11.glTranslatef(0, 0, -1.2F);
									 break;
								 }
							}
						}
					}
				}
			}
		}
	  }
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onEvent(RenderGameOverlayEvent.Text event) {
		if(!mod_GirlFront.cfg_hud) {
			return;
		}
		
		Minecraft mc = FMLClientHandler.instance().getClient();
		World world = FMLClientHandler.instance().getWorldClient();
		ScaledResolution scaledresolution = new ScaledResolution(mc);
		int i = scaledresolution.getScaledWidth();
		int j = scaledresolution.getScaledHeight();
		EntityPlayer player = mc.player;
		ItemStack itemstack = ((EntityPlayer) (player)).getHeldItemMainhand();
		ItemStack itemstackl = ((EntityPlayer) (player)).getHeldItemOffhand();
		FontRenderer fontrenderer = mc.fontRenderer;
		mc.entityRenderer.setupOverlayRendering();
		// OpenGlHelper.
		
		if (player.getRidingEntity() instanceof EntityDrone && player.getRidingEntity() != null) {// 1
			EntityDrone vehicle = (EntityDrone) player.getRidingEntity();
			{
				NBTTagCompound nbtcn = vehicle.getEntityData();
				if(nbtcn != null)this.renderhud(player, mc, fontrenderer, nbtcn);
			}
		}
		else if(player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).getItem() == mod_GirlFront.armor_gk_uniform_head) {
			NBTTagCompound nbtcn = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).getTagCompound();
			if(!player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty() && nbtcn != null)this.renderhud(player, mc, fontrenderer, nbtcn);
		}
		else if(itemstack.getItem() instanceof ItemDollCN) {
			NBTTagCompound nbtcn = itemstack.getTagCompound();
			if(!itemstack.isEmpty() && nbtcn != null)this.renderhud(player, mc, fontrenderer, nbtcn);
		}
		else if(itemstackl.getItem() instanceof ItemDollCN) {
			NBTTagCompound nbtcn = itemstackl.getTagCompound();
			if(!itemstackl.isEmpty() && nbtcn != null)this.renderhud(player, mc, fontrenderer, nbtcn);
		}
		
		
		renderInv(player, mc, fontrenderer);
		renderNPC_Doll(player, mc, fontrenderer);
		
	}
	
	
	public void renderhud(EntityPlayer player, Minecraft mc, FontRenderer fontrenderer, NBTTagCompound nbtcn) {
		// GL11.glEnable(GL11.GL_BLEND);
				if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
	//				if(itemstack.isEmpty())return;
	//				if(itemstack.isEmpty() && !(itemstack.getItem() instanceof ItemDollCN))return;
	//				ItemDollCN cn = (ItemDollCN) itemstack.getItem();
	//				NBTTagCompound nbtcn = itemstack.getTagCompound();
					if(nbtcn == null)return;
					int squadid = nbtcn.getInteger("squadid");
					String id = "First";
					if(squadid == 2)id = "Second";
					if(squadid == 3)id = "Third";
					if(squadid == 4)id = "Fourth";
					NBTTagCompound nbt = player.getEntityData();
					boolean nb = false;
					if(nbt != null) {
						int co = nbt.getInteger("dollcount");
						nb = true;
					}
					{
						GL11.glPushMatrix();
						GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
						GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
								GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
								GlStateManager.DestFactor.ZERO);
						mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
						int x = 8;
						GL11.glScalef(1, 1, 1);
						if(nb) {
							int co = nbt.getInteger("dollcount");
							if(co == 0) {
								GL11.glTranslatef(x, 0, 0);
								GL11.glScalef(1.2F, 1.2F, 1.2F);
								GL11.glTranslatef(-x, 0, 0);
							}
						}
						fontrenderer.drawString(id, x-4, 20, 0xFFFFFF);
						fontrenderer.drawString("Squad", x-4, 30, 0xFFFFFF);
						GuiIngame g  = mc.ingameGUI;
						mc.renderEngine.bindTexture(new ResourceLocation("hmggirlfront:textures/items/rogo.png"));
						GL11.glScalef(0.0625f, 0.0625f, 1);
						g.drawTexturedModalRect((5)*16,
								(0)*16, 0,0, 256, 256);
						
						GL11.glPopMatrix();
					}
					
					
					int count = 1;
					List<Entity> llist = player.world.getEntitiesWithinAABBExcludingEntity(player,
							player.getEntityBoundingBox().expand(player.motionX, player.motionY, player.motionZ).grow(100.0D));
					if (llist != null) {
						for (int lj = 0; lj < llist.size(); lj++) {
							Entity entity1 = (Entity) llist.get(lj);
							if (entity1.canBeCollidedWith() && entity1 instanceof EntityDoll && entity1 != null) {
								EntityDoll doll = (EntityDoll) entity1;
								if(doll.isOwner(player) && doll.getSquadID() == squadid) {
									GL11.glPushMatrix();
									GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
									GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
											GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
											GlStateManager.DestFactor.ZERO);
									mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
									ItemStack main = doll.getHeldItemMainhand();
									int x = 0 + 30 * count;
									GL11.glScalef(1, 1, 1);
									if(nb) {
										int co = nbt.getInteger("dollcount");
										if(co == count) {
											GL11.glTranslatef(x, 0, 0);
											GL11.glScalef(1.2F, 1.2F, 1.2F);
											GL11.glTranslatef(-x, 0, 0);
										}
									}
									if(!main.isEmpty()) {
										if(main.getItem() != null)
										{
											GL11.glPushMatrix();
											RenderItem renderitem = mc.getRenderItem();
											renderitem.renderItemIntoGUI(new ItemStack(main.getItem()), x, 0);
											GL11.glPopMatrix();
										}
									}
									int color = 0;
									int color_bu = 0xFFFFFF;
									int color_fo = 0xFFFFFF;
									if(doll.getHealth() > 0) {
										color = 0xFFFFFF;
									}else {
										color = Color.RED.getRGB();
										color_bu = Color.RED.getRGB();
										color_fo = Color.RED.getRGB();
									}
									if(!(doll.getRemain_S() > 0)) {
										color_bu = Color.YELLOW.getRGB();
									}
									if(!(doll.getRemain_A() > 0)) {
										color_fo = Color.YELLOW.getRGB();
									}
									String hp = String.format("%1$3d", (int)doll.getHealth());
									String lv = String.format("%1$3d", (int)doll.getArmID_L());
									String bullet = String.format("%1$3d", (int)doll.getRemain_S());
									String food = String.format("%1$3d", (int)doll.getRemain_A());
									fontrenderer.drawString("HP"+hp, x, 20, color);
									fontrenderer.drawString("Lv"+lv, x, 30, color);
									fontrenderer.drawString("  "+bullet, x, 40, color_bu);//Bu
									if(!main.isEmpty() && main.getItem() instanceof ItemDollGunBase) {
											ItemDollGunBase gun = (ItemDollGunBase) main.getItem();
											GL11.glPushMatrix();
											GL11.glTranslatef(x, 0, 40);
											GL11.glScalef(0.5F, 0.5F, 0.5F);
											GL11.glTranslatef(-x, 0, -40);
											RenderItem renderitem = mc.getRenderItem();
											renderitem.renderItemIntoGUI(new ItemStack(gun.magazine), x, 80);
											GL11.glPopMatrix();
									}
									fontrenderer.drawString("  "+food, x, 50, color_fo);//Fo
									{
										GL11.glPushMatrix();
										GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
										GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
												GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
												GlStateManager.DestFactor.ZERO);
										mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
										GuiIngame g  = mc.ingameGUI;
										mc.renderEngine.bindTexture(new ResourceLocation("hmggirlfront:textures/items/item/idoll_food.png"));
										GL11.glScalef(0.03125F, 0.03125F, 1);
										g.drawTexturedModalRect((x)*32,
												(50)*32, 0,0, 256, 256);
										
										GL11.glPopMatrix();
									}
									double d5 = entity1.posX - player.posX;
									double d7 = entity1.posZ - player.posZ;
									double d6 = entity1.posY - player.posY;
									double ddx = Math.abs(d5);
									double ddz = Math.abs(d7);
									double dxz = MathHelper.sqrt(d5 * d5 + d7 * d7);
									double dxzy = MathHelper.sqrt(dxz * dxz + d6 * d6);
									String m = String.format("%1$3d", (int)dxzy);
									fontrenderer.drawString("m"+m, x, 60, color);
									String mode = "follow";
									int color_mode = Color.GREEN.getRGB();
									if(doll.getMoveT() == 1) {
										mode = "free";
										color_mode = Color.RED.getRGB();
									}
									if(doll.getMoveT() == 2) {
										mode = "attack";
										color_mode = Color.YELLOW.getRGB();
									}
									if(doll.getMoveT() == 3) {
										mode = "wait";
										color_mode = Color.BLUE.getRGB();
									}
									if(doll.getMoveT() == 5) {
										mode = "point attack";
										color_mode = Color.ORANGE.getRGB();
									}
									fontrenderer.drawString(mode, x, 70, color_mode);
									
									String skill = "Skill ON";
									if(doll.getBoosttime() == 1)skill = "Skill OFF";
									if(doll.getPledge() != 0)fontrenderer.drawString(skill, x, 80, 0xFFFFFF);
									
									GL11.glPopMatrix();
									++count;
								}
							}
						}
					}
				}
	}
	
	public void renderNPC_Doll(EntityPlayer player, Minecraft mc, FontRenderer fontrenderer) {
		if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
			
			
			int count = 0;
			EntityNPC_Doll dollbase = null;
			List<Entity> llist = player.world.getEntitiesWithinAABBExcludingEntity(player,
					player.getEntityBoundingBox().expand(player.motionX, player.motionY, player.motionZ).grow(100.0D));
			if (llist != null) {
				for (int lj = 0; lj < llist.size(); lj++) {
					Entity entity1 = (Entity) llist.get(lj);
					if (entity1.canBeCollidedWith() && entity1 instanceof EntityNPC_Doll && entity1 != null) {
						EntityNPC_Doll doll = (EntityNPC_Doll) entity1;
						if(doll.getFTMode() == 1)dollbase = doll;
						if(doll.isOwner(player)) {
							GL11.glPushMatrix();
							GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
							GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
									GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
									GlStateManager.DestFactor.ZERO);
							mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
							ItemStack main = doll.getHeldItemMainhand();
							int x =30 * count;
							GL11.glScalef(1, 1, 1);
							if(!main.isEmpty()) {
								if(main.getItem() != null)
								{
									GL11.glPushMatrix();
									RenderItem renderitem = mc.getRenderItem();
									renderitem.renderItemIntoGUI(new ItemStack(main.getItem()), x, 80);
									GL11.glPopMatrix();
								}
							}
							int color = 0;
							if(doll.getHealth() > doll.getHealth()/2) {
								color = 0xFFFFFF;
							}else if(doll.getHealth() > 0) {
								color = Color.YELLOW.getRGB();
							}
							else {
								color = Color.RED.getRGB();
							}
							String hp = String.format("%1$3d", (int)doll.getHealth());
							fontrenderer.drawString("HP"+hp, x, 100, color);
							GL11.glPopMatrix();
							++count;
						}
					}
				}
			}
			if(dollbase != null && dollbase.getMissonID() == 1) {
				GL11.glPushMatrix();
				GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
				GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
						GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
						GlStateManager.DestFactor.ZERO);
				mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
				double d5 = dollbase.getMoveX() - dollbase.posX;
				double d7 = dollbase.getMoveZ() - dollbase.posZ;
				double ddx = Math.abs(d5);
				double ddz = Math.abs(d7);
				double dxz = MathHelper.sqrt(d5 * d5 + d7 * d7);
				String m = String.format("%1$3d", (int)(240 - dxz));
				TextComponentTranslation text = new TextComponentTranslation("hmggirlfront.mission1.kyori.name", new Object[0]);
				fontrenderer.drawString(text.getFormattedText() + m, 20, 70, Color.GREEN.getRGB());
				GL11.glPopMatrix();
			}
			
			if(dollbase != null && dollbase.getMissonID() == 2) {
				EntityIBC10u u = null;
				EntityIBCBoss01M boss = null;
				List<Entity> llist2 = player.world.getEntitiesWithinAABBExcludingEntity(player,
						player.getEntityBoundingBox().expand(player.motionX, player.motionY, player.motionZ).grow(120.0D));
				if (llist2 != null) {
					for (int lj = 0; lj < llist2.size(); lj++) {
						Entity entity1 = (Entity) llist2.get(lj);
						if (entity1.canBeCollidedWith()  && entity1 != null) {
							if(entity1 instanceof EntityIBC10u) {
								EntityIBC10u s = (EntityIBC10u) entity1;
								u = s;
							}
							if(entity1 instanceof EntityIBCBoss01M) {
								EntityIBCBoss01M s = (EntityIBCBoss01M) entity1;
								boss = s;
							}
						}
					}
				}
				if(u != null) {
					GL11.glPushMatrix();
					GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
					GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
							GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
							GlStateManager.DestFactor.ZERO);
					mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
					double d5 = u.getMoveX() - u.posX;
					double d7 = u.getMoveZ() - u.posZ;
					double ddx = Math.abs(d5);
					double ddz = Math.abs(d7);
					double dxz = MathHelper.sqrt(d5 * d5 + d7 * d7);
					String m = String.format("%1$3d", (int)(180 - dxz));
					TextComponentTranslation text = new TextComponentTranslation("hmggirlfront.mission2.kyori.name", new Object[0]);
					fontrenderer.drawString(text.getFormattedText() + m, 20, 70, Color.GREEN.getRGB());
					GL11.glPopMatrix();
				}
				if(boss != null) {
					GL11.glPushMatrix();
					GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
					GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
							GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
							GlStateManager.DestFactor.ZERO);
					mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
					TextComponentTranslation text = new TextComponentTranslation("hmggirlfront.mission2.boss.name", new Object[0]);
					fontrenderer.drawString(text.getFormattedText(), 20, 70, Color.GREEN.getRGB());
					GL11.glPopMatrix();
				}
			}
			
		}
	}
	
	public void renderInv(EntityPlayer player, Minecraft mc, FontRenderer fontrenderer) {
		GL11.glPushMatrix();{
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
		ScaledResolution scaledresolution = new ScaledResolution(mc);
        int ix = scaledresolution.getScaledWidth();
        int jy = scaledresolution.getScaledHeight();
		for(int x = 0; x < 40; ++x) {
			for(int y = 0; y < 40; ++y) {
				for(int z = 0; z < 40; ++z) {
					BlockPos pos = new BlockPos(player.posX - 20 + x, player.posY - 20 + y, player.posZ - 20 + z);
					if(player.world.getBlockState(pos)
							.getBlock() instanceof Block_BaseBase) {
						TileEntity_BaseBase tile =  (TileEntity_BaseBase)player.world.getTileEntity(pos);
						{
							double count = tile.getClientInvCount(tile);
							double invmaxcount = tile.getClientInvMaxCount(tile);
							{
								
							}
							/*GL11.glPushMatrix();{
								GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
										GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
										GlStateManager.DestFactor.ZERO);
							GuiIngame g  = mc.ingameGUI;
							mc.renderEngine.bindTexture(new ResourceLocation("hmggirlfront:textures/misc/" + tile.inv_tex));
							GL11.glScalef(0.125f, 0.125f, 1);
							g.drawTexturedModalRect((ix / 2 - 16)*8,(jy / 2 - 100)*8, 0,0, 256, 256);
							}GL11.glPopMatrix();
							*/
							//invasion
							{
								GL11.glPushMatrix();
								{
									GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
											GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
											GlStateManager.SourceFactor.ONE,
											GlStateManager.DestFactor.ZERO);
									GuiIngame g = mc.ingameGUI;
									mc.renderEngine
											.bindTexture(
													new ResourceLocation("hmggirlfront:textures/misc/inv_m.png"));
									GL11.glScalef(0.125f, 0.125f, 1);
									g.drawTexturedModalRect((ix / 2 - 16) * 8, (jy / 2 - 100) * 8, 0, 0, 256, 256);
								}
								GL11.glPopMatrix();
								GL11.glPushMatrix();
								{
									GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
											GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
											GlStateManager.SourceFactor.ONE,
											GlStateManager.DestFactor.ZERO);
									GuiIngame g = mc.ingameGUI;
									mc.renderEngine
											.bindTexture(new ResourceLocation(
													"hmggirlfront:textures/misc/inv_m_em.png"));
									GL11.glScalef(0.125f, 0.125f, 1);
									double co = (count / invmaxcount) * 256;
									//GL11.glScalef(1 * 0.5f, 1, 1);
									int co2 = (int) co;
									if(tile.enemyblock) {
										g.drawTexturedModalRect((ix / 2 - 16) * 8, (jy / 2 - 100) * 8, 0, 0, 256 - co2,
												256);
									}else {
										g.drawTexturedModalRect((ix / 2 - 16) * 8, (jy / 2 - 100) * 8, 0, 0, co2,
												256);
									}
								}
								GL11.glPopMatrix();
								GL11.glPushMatrix();
								{
									GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
											GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
											GlStateManager.SourceFactor.ONE,
											GlStateManager.DestFactor.ZERO);
									TextComponentTranslation text = new TextComponentTranslation(tile.inv_name, new Object[0]);
									fontrenderer.drawString(text.getFormattedText(), (ix / 2) - 26, (jy / 2 - 60), 0xFFFFFF);
								}
								GL11.glPopMatrix();
						}
					
							//player vs mob
							{
								double player_count = tile.getClientPlayerCount(tile);
								double mob_count = tile.getClientMobCount(tile);
								
									GL11.glPushMatrix();
									{
										GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
												GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
												GlStateManager.SourceFactor.ONE,
												GlStateManager.DestFactor.ZERO);
										GuiIngame g = mc.ingameGUI;
										mc.renderEngine
												.bindTexture(
														new ResourceLocation("hmggirlfront:textures/misc/invhp.png"));
										GL11.glScalef(0.125f, 0.125f, 1);
										g.drawTexturedModalRect((ix / 2 - 16) * 8, (jy / 2 - 84) * 8, 0, 0, 256, 256);
									}
									GL11.glPopMatrix();
									GL11.glPushMatrix();
									{
										GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
												GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
												GlStateManager.SourceFactor.ONE,
												GlStateManager.DestFactor.ZERO);
										GuiIngame g = mc.ingameGUI;
										mc.renderEngine
												.bindTexture(new ResourceLocation(
														"hmggirlfront:textures/misc/invhp_em.png"));
										GL11.glScalef(0.125f, 0.125f, 1);
										double max = player_count + mob_count;
										double range = 256 / max;
										double player_range = player_count * range;
										double mob_range = mob_count * range;
										//double co = (count / invmaxcount) * 256;
										//int co2 = (int) co;
										{
											g.drawTexturedModalRect((ix / 2 - 16) * 8, (jy / 2 - 84) * 8, 0, 0, (int)mob_range,
													256);
										}
									}
									GL11.glPopMatrix();
									GL11.glPushMatrix();
									{
										GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
												GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
												GlStateManager.SourceFactor.ONE,
												GlStateManager.DestFactor.ZERO);
										TextComponentTranslation text = new TextComponentTranslation(tile.inv_name, new Object[0]);
										fontrenderer.drawString(text.getFormattedText(), (ix / 2) - 26, (jy / 2 - 60), 0xFFFFFF);
									}
									GL11.glPopMatrix();
							}
						}
						break;
					}
				}
			}
		}
		
		
		}GL11.glPopMatrix();
	}
	
}
