package hmggirlfront.render.npc;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import gvclib.entity.living.EntityGVCLivingBase;
import gvclib.event.gun.Layermat;
import gvclib.item.ItemGunBase;
import gvclib.render.ModelBase_Non;
import hmggirlfront.entity.npc.EntityNPC_Doll;
import hmggirlfront.items.ItemDollAttachment;
import hmggirlfront.items.ItemDollGunBase;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
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.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import objmodel.AdvancedModelLoader;
import objmodel.IModelCustom;

@SideOnly(Side.CLIENT)
public class RenderNPC_Doll extends RenderLiving<EntityNPC_Doll> //extends RenderLiving<EntityNPC_Doll>
{
    private static final ResourceLocation m1911t = new ResourceLocation("hmggirlfront:textures/model/doll/doll_m1911.png");
    private static final IModelCustom m1911 = AdvancedModelLoader.loadModel(new ResourceLocation("hmggirlfront:textures/model/doll/doll_m1911.mqo"));
    
    /** instance of ModelBoat for rendering */
    
    private static final ResourceLocation t0 = new ResourceLocation("hmggirlfront:textures/model/marker/marker_npc.png");
    private static final IModelCustom marker = AdvancedModelLoader.loadModel(new ResourceLocation("hmggirlfront:textures/model/marker/marker.obj"));
    
    
    public RenderNPC_Doll(RenderManager renderManagerIn)
    {
    	super(renderManagerIn, new ModelBase_Non(),0.5F);
        this.shadowSize = 0.5F;
    }

    public void rendermodel(EntityNPC_Doll entity, String model) {
    	IModelCustom mo = null;
		ItemStack item = entity.getHeldItemMainhand();
		boolean flag = !item.isEmpty();
		if(flag && entity != null) {
			if(item.getItem() instanceof ItemDollGunBase) {
				ItemDollGunBase dollgun = (ItemDollGunBase) item.getItem();
				mo = dollgun.doll_model;
			}
		}
    	if(mo != null) {
    		mo.renderPart(model);
    	}
    }
    
    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntityNPC_Doll entity)
    {
    	ResourceLocation dolltex = m1911t;
		ItemStack item = entity.getHeldItemMainhand();
		boolean flag = !item.isEmpty();
		ResourceLocation id = null;
		if(flag && entity != null) {
			if(item.getItem() instanceof ItemDollGunBase) {
				ItemDollGunBase dollgun = (ItemDollGunBase) item.getItem();
				id = new ResourceLocation(dollgun.doll_tex);
			}
		}
    	if(id != null) {
    		dolltex = id;
    	}
		return dolltex;
    }
    
    
    
    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity>) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doe
     */
    float iii;
    public void doRender(EntityNPC_Doll entity, double x, double y, double z, float entityYaw, float partialTicks)
    {
    	{
			//doRenderShadowAndFire(entity, x, y, z, entityYaw, partialTicks);
		}
    	float limbSwing = this.F6(entity, partialTicks);
		float limbSwingAmount = this.F5(entity, partialTicks);
    	this.bindEntityTexture(entity);
    	GL11.glPushMatrix();
		GL11.glTranslatef((float) x, (float) y, (float) z);
		GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
		GL11.glEnable(GL12.GL_RESCALE_NORMAL);
		
		
		
		if(entity.deathTicks > 0){
			GL11.glColor4f(0.6F, 0.6F, 0.6F, 1F);
		}else {
			if(entity.hurtTime > 0) {
				GL11.glColor4f(0.7F, 0.2F, 0.2F, 1F);
			}else {
				GL11.glColor4f(1F, 1F, 1F, 1F);
			}
		}
		GL11.glScalef(entity.doll_size, entity.doll_size, entity.doll_size);
		GL11.glRotatef(180.0F - entity.renderYawOffset, 0.0F, 1.0F, 0.0F);
		{
			GL11.glPushMatrix();//glstart
			this.renderlegs(entity, limbSwing, limbSwingAmount, partialTicks);
			GL11.glPopMatrix();//glend
		}
		if(entity.isRiding()) {
			GL11.glTranslatef(0F, -0.5F, 0.0F);
		}
		{
			GL11.glPushMatrix();//glstart
			this.renderbody(entity, limbSwing, limbSwingAmount, partialTicks);
			GL11.glPopMatrix();//glend
		}
		this.bindEntityTexture(entity);
		if(entity.deathTicks > 0){
			//GL11.glTranslatef(0F, -0.1F, 0.25F);
			GL11.glTranslatef(0F, 1.5F, 0.0F);
			GL11.glRotatef(10, 1.0F, 0.0F, 0.0F);
			GL11.glTranslatef(0F, -1.5F, 0.0F);
		}
		GL11.glRotatef(-(180.0F - entity.renderYawOffset), 0.0F, 1.0F, 0.0F);
		GL11.glTranslatef(0F, 1.5F, 0.0F);
		GL11.glRotatef(180.0F - entity.rotationYawHead, 0.0F, 1.0F, 0.0F);
		GL11.glRotatef(entity.rotationPitch, 1.0F, 0.0F, 0.0F);
		GL11.glTranslatef(0F, -1.5F, 0.0F);
		int ra = entity.world.rand.nextInt(10);
		if((entity.ontick == ra) || entity.deathTicks > 0) {
			this.rendermodel(entity, "head2");
		}else {
			this.rendermodel(entity, "head");
		}
		this.rendermodel(entity, "head1");
		
		GL11.glRotatef(-(180.0F - entity.rotationYawHead), 0.0F, 1.0F, 0.0F);
		EntityPlayer player = Minecraft.getMinecraft().player;
		if(entity.isOwner(player)) 
		{
			GL11.glPushMatrix();//glstart
			GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
			GL11.glEnable(GL12.GL_RESCALE_NORMAL);
			GL11.glTranslatef(0, entity.height + 0.5F, 0);
			Minecraft.getMinecraft().renderEngine.bindTexture(t0);
			GlStateManager.disableLighting();
			marker.renderPart("mat1");;
			GlStateManager.enableLighting();
			GL11.glColor4f(1F, 1F, 1F, 1F);
			GL11.glDisable(GL12.GL_RESCALE_NORMAL);
			GL11.glPopMatrix();//glend
		}
		
		GL11.glColor4f(1F, 1F, 1F, 1F);
		GL11.glDisable(GL12.GL_RESCALE_NORMAL);
		GL11.glPopMatrix();
		
		//doRenderShadowAndFire(entity, x, y, z, entityYaw, partialTicks);
		//renderEntityOnFire(entity, x, y, z, partialTicks);
		
		super.doRender(entity, x, y, z, entityYaw, partialTicks);
    }
    
    private void renderlegs(EntityNPC_Doll entity, float limbSwing, float limbSwingAmount, float partialTicks){
    	GL11.glPushMatrix();//glstart
    	{
			float Ax = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * limbSwingAmount;
			GL11.glTranslatef(0.15F, 0.625F, 0.0F);//GL11.glTranslatef(0.15F, 0.75F, 0.0F);
			if(entity.isRiding()) {
				GL11.glTranslatef(0F, -0.5F, 0.0F);
				GL11.glRotatef(-90, 1.0F, 0.0F, 0.0F);
				GL11.glRotatef(20, 0.0F, 0.0F, 1.0F);
			}else {
				GL11.glRotatef(Ax * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
			}
			GL11.glTranslatef(-0.15F, -0.625F, 0.0F);
			this.rendermodel(entity, "leg_l");
		}
		GL11.glPopMatrix();//glend
		
		GL11.glPushMatrix();//glstart
		{
			float Ax =MathHelper.cos(limbSwing * 0.6662F) * limbSwingAmount;
			GL11.glTranslatef(-0.15F, 0.625F, 0.0F);
			if(entity.isRiding()) {
				GL11.glTranslatef(0F, -0.5F, 0.0F);
				GL11.glRotatef(-90, 1.0F, 0.0F, 0.0F);
				GL11.glRotatef(-20, 0.0F, 0.0F, 1.0F);
			}else {
				GL11.glRotatef(Ax * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
			}
			GL11.glTranslatef(0.15F, -0.625F, 0.0F);
			this.rendermodel(entity, "leg_r");
		}
		GL11.glPopMatrix();//glend
	}
    
    private void renderbody(EntityNPC_Doll entity, float limbSwing, float limbSwingAmount, float partialTicks){
    	if(entity.deathTime > 0){
    		GL11.glTranslatef(0F, 0.75F, 0.0F);
    		GL11.glRotatef(20, 1.0F, 0.0F, 0.0F);
    		GL11.glTranslatef(0F, -0.75F, 0.0F);
    	}
    	GL11.glPushMatrix();//glstart
    	this.rendermodel(entity, "body");
		this.rendermodel(entity, "body1");
		this.rendermodel(entity, "mantle");
		GL11.glPopMatrix();//glend
		
		boolean tageflag = true;
		if(entity.getRidingEntity() != null && entity.getRidingEntity() instanceof EntityGVCLivingBase) {
			EntityGVCLivingBase vehicle = (EntityGVCLivingBase) entity.getRidingEntity();
			int i = vehicle.getPassengers().indexOf(entity);
			if(vehicle.vehicle_ridding_nofire[i]) {
				tageflag = false;
			}
		}
		ItemStack main = entity.getHeldItemMainhand();
		ItemStack off = entity.getHeldItemOffhand();
		 float arm_l_rotex = 0;
	     float arm_l_rotez = 0;
	     float arm_l_rotey = 0;
	     float arm_r_rotex = 0;
	     float arm_r_rotez = 0;
	     float arm_r_rotey = 0;
    	GL11.glPushMatrix();//glstart
    	{
    		
			float Ax = MathHelper.cos(limbSwing * 0.6662F) * limbSwingAmount;
			GL11.glTranslatef(0.35F, 1.375F, 0.0F);
			//arm_l_rotex = (MathHelper.sin(partialTicks * 0.067F) * 0.05F) * (180F / (float)Math.PI);
			if(entity.getattacktask() && !(entity.deathTime > 0)) {
				arm_l_rotex = -90 + entity.rotationPitch;
				if(!off.isEmpty() && off.getItem() instanceof ItemGunBase) {
					if(entity.gun_count1 < 2){
		    			GL11.glRotatef(-entity.gun_count1, 1.0F, 0.0F, 0.0F);
		    		}
				}else {
					arm_l_rotez = -30;
				}
				
			}else if(entity.isRiding()) {
				arm_l_rotex = -30;
			}
			else if(entity.deathTime > 0){
				arm_l_rotex = -30;
				arm_l_rotez = -40;
			}else {
				if(!off.isEmpty() && off.getItem() instanceof ItemGunBase) {
					arm_l_rotex = Ax * (180F / (float)Math.PI) - 20;
				}else {
					arm_l_rotex = Ax * (180F / (float)Math.PI);
				}
			}
			//arm_l_rotez = (MathHelper.cos(partialTicks * 0.09F) * 0.05F + 0.05F) * (180F / (float)Math.PI);
			//GL11.glRotatef(Ax * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
			//GL11.glRotatef(-(MathHelper.cos(partialTicks * 0.09F) * 0.05F + 0.05F) * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
			//GL11.glRotatef(-(MathHelper.sin(partialTicks * 0.067F) * 0.05F) * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
			GL11.glRotatef(arm_l_rotex, 1.0F, 0.0F, 0.0F);
			GL11.glRotatef(arm_l_rotey, 0.0F, 1.0F, 0.0F);
			GL11.glRotatef(arm_l_rotez, 0.0F, 0.0F, 1.0F);
			
			//GL11.glRotatef(MathHelper.sin(partialTicks / 100) * 30F, 1.0F, 0.0F, 0.0F);
			//GL11.glRotatef(MathHelper.cos(partialTicks / 100) * 30F, 0.0F, 0.0F, 1.0F);
			GL11.glTranslatef(-0.35F, -1.375F, 0.0F);
			this.rendermodel(entity, "arm_l");
			if (!off.isEmpty() && off.getItem() instanceof ItemGunBase  && tageflag){
				ItemGunBase gun = (ItemGunBase) off.getItem();
				String tex = gun.obj_tex;
				IModelCustom model = gun.obj_model;
				GL11.glPushMatrix();//glstart
				GL11.glScalef(0.1875F, 0.1875F, 0.1875F);
				GL11.glRotatef(90F, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(0.375F * 5.33F, 0 , -0.85F * 5.33F + 0.2F);//x,z,y
				
				Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(tex));
				gun.obj_model.renderPart("mat1");
				gun.obj_model.renderPart("mat100");
				gun.obj_model.renderPart("mat2");
				gun.obj_model.renderPart("mat3");
				Layermat.rendersight( entity,  off,  gun);
				Layermat.renderattachment( entity,  off,  gun);
				gun.obj_model.renderPart("mat25");
				gun.obj_model.renderPart("mat31");
				gun.obj_model.renderPart("mat32");/**/
				{
					ItemStack head = entity.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
					if(!head.isEmpty() &&  head.getItem() instanceof ItemDollAttachment) {
						ItemDollAttachment am = (ItemDollAttachment) head.getItem();
						GL11.glPushMatrix();//glstart
						String amtex = am.obj_tex;
						IModelCustom ammodel = am.obj_model;
						GL11.glTranslatef(gun.am_sight_x, gun.am_sight_y, gun.am_sight_z);
						Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(amtex));
						ammodel.renderPart("sight");
						GL11.glTranslatef( - gun.am_sight_x,  - gun.am_sight_y,  - gun.am_sight_z);
						Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(tex));
						gun.obj_model.renderPart("mat41");
						GL11.glPopMatrix();//glend
					}
				}
				GL11.glPopMatrix();//glend
				this.bindEntityTexture(entity);
			}
		}
		GL11.glPopMatrix();//glend
		this.bindEntityTexture(entity);
		
		
		GL11.glPushMatrix();//glstart
		{
			float Ax = MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * limbSwingAmount;
			GL11.glTranslatef(-0.35F, 1.375F, 0.0F);
			//arm_r_rotex = (MathHelper.sin(partialTicks * 0.067F) * 0.05F) * (180F / (float)Math.PI);
			if(entity.getattacktask() && !(entity.deathTime > 0)) {
				if(entity.gun_count1 < 2){
	    			GL11.glRotatef(-entity.gun_count1, 1.0F, 0.0F, 0.0F);
	    		}
				arm_r_rotex = -90 + entity.rotationPitch;
			}else if(entity.isRiding()) {
				arm_r_rotex = -30;
			}
			else if(entity.deathTime > 0){
				arm_r_rotex = -20;
			}
			else {
				arm_r_rotex = Ax * (180F / (float)Math.PI) - 20;
			}
			
			//arm_r_rotez = (MathHelper.cos(partialTicks * 0.09F) * 0.05F + 0.05F) * (180F / (float)Math.PI);
			//GL11.glRotatef(Ax * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
			//GL11.glRotatef((MathHelper.cos(partialTicks * 0.09F) * 0.05F + 0.05F) * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
			//GL11.glRotatef((MathHelper.sin(partialTicks * 0.067F) * 0.05F) * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
			GL11.glRotatef(arm_r_rotex, 1.0F, 0.0F, 0.0F);
			GL11.glRotatef(arm_r_rotey, 0.0F, 1.0F, 0.0F);
			GL11.glRotatef(arm_r_rotez, 0.0F, 0.0F, 1.0F);
			
			//GL11.glRotatef(MathHelper.sin(partialTicks / 100) * 50F, 1.0F, 0.0F, 0.0F);
			//GL11.glRotatef(MathHelper.cos(partialTicks / 100) * 50F, 0.0F, 0.0F, 1.0F);
			GL11.glTranslatef(0.35F, -1.375F, 0.0F);
			this.rendermodel(entity, "arm_r");
			
			if (!main.isEmpty() && main.getItem() instanceof ItemGunBase  && tageflag){
				ItemGunBase gun = (ItemGunBase) main.getItem();
				String tex = gun.obj_tex;
				IModelCustom model = gun.obj_model;
				GL11.glPushMatrix();//glstart
				GL11.glScalef(0.1875F, 0.1875F, 0.1875F);
				GL11.glRotatef(90F, 1.0F, 0.0F, 0.0F);
				GL11.glTranslatef(-0.375F * 5.33F, 0 , -0.85F * 5.33F + 0.2F);//x,z,y
				
				Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(tex));
				gun.obj_model.renderPart("mat1");
				gun.obj_model.renderPart("mat100");
				gun.obj_model.renderPart("mat2");
				gun.obj_model.renderPart("mat3");
				Layermat.rendersight( entity,  main,  gun);
				Layermat.renderattachment( entity,  main,  gun);
				gun.obj_model.renderPart("mat25");
				gun.obj_model.renderPart("mat31");
				gun.obj_model.renderPart("mat32");
				{
					ItemStack head = entity.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
					if(!head.isEmpty() &&  head.getItem() instanceof ItemDollAttachment) {
						ItemDollAttachment am = (ItemDollAttachment) head.getItem();
						GL11.glPushMatrix();//glstart
						String amtex = am.obj_tex;
						IModelCustom ammodel = am.obj_model;
						GL11.glTranslatef(gun.am_sight_x, gun.am_sight_y, gun.am_sight_z);
						Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(amtex));
						ammodel.renderPart("sight");
						GL11.glTranslatef( - gun.am_sight_x,  - gun.am_sight_y,  - gun.am_sight_z);
						Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation(tex));
						gun.obj_model.renderPart("mat41");
						GL11.glPopMatrix();//glend
					}
				}
				GL11.glPopMatrix();//glend
				this.bindEntityTexture(entity);
			}
		}
		GL11.glPopMatrix();//glend
		this.bindEntityTexture(entity);
	}
    
    
    
    public float F6(EntityLivingBase entity, float partialTicks){
 		float f6 = 0;
 		if (!entity.isRiding())
        {
            f6 = entity.limbSwing - entity.limbSwingAmount * (1.0F - partialTicks);
            if (entity.isChild())
            {
                f6 *= 3.0F;
            }
        }
 		return f6;
 	}
 	public float F5(EntityLivingBase entity, float partialTicks){
 		float f5 = 0;
 		if (!entity.isRiding())
        {
            f5 = entity.prevLimbSwingAmount + (entity.limbSwingAmount - entity.prevLimbSwingAmount) * partialTicks;
            if (f5 > 1.0F)
            {
                f5 = 1.0F;
            }
        }
 		return f5;
 	}
 	
 	/**
     * Returns a rotation angle that is inbetween two other rotation angles. par1 and par2 are the angles between which
     * to interpolate, par3 is probably a float between 0.0 and 1.0 that tells us where "between" the two angles we are.
     * Example: par1 = 30, par2 = 50, par3 = 0.5, then return = 40
     */
    protected float interpolateRotation(float prevYawOffset, float yawOffset, float partialTicks)
    {
        float f;

        for (f = yawOffset - prevYawOffset; f < -180.0F; f += 360.0F)
        {
            ;
        }

        while (f >= 180.0F)
        {
            f -= 360.0F;
        }

        return prevYawOffset + partialTicks * f;
    }
    
    protected void renderLivingAt(EntityNPC_Doll entityLivingBaseIn, double x, double y, double z)
    {
        GlStateManager.translate((float)x, (float)y, (float)z);
    }
    protected float handleRotationFloat(EntityNPC_Doll livingBase, float partialTicks)
    {
        return (float)livingBase.ticksExisted + partialTicks;
    }
    
    private void renderEntityOnFire(Entity entity, double x, double y, double z, float partialTicks)
    {
        GlStateManager.disableLighting();
        TextureMap texturemap = Minecraft.getMinecraft().getTextureMapBlocks();
        TextureAtlasSprite textureatlassprite = texturemap.getAtlasSprite("minecraft:blocks/fire_layer_0");
        TextureAtlasSprite textureatlassprite1 = texturemap.getAtlasSprite("minecraft:blocks/fire_layer_1");
        GlStateManager.pushMatrix();
        GlStateManager.translate((float)x, (float)y, (float)z);
        float f = entity.width * 1.4F;
        GlStateManager.scale(f, f, f);
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferbuilder = tessellator.getBuffer();
        float f1 = 0.5F;
        float f2 = 0.0F;
        float f3 = entity.height / f;
        float f4 = (float)(entity.posY - entity.getEntityBoundingBox().minY);
        GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
        GlStateManager.translate(0.0F, 0.0F, -0.3F + (float)((int)f3) * 0.02F);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        float f5 = 0.0F;
        int i = 0;
        bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);

        while (f3 > 0.0F)
        {
            TextureAtlasSprite textureatlassprite2 = i % 2 == 0 ? textureatlassprite : textureatlassprite1;
            this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
            float f6 = textureatlassprite2.getMinU();
            float f7 = textureatlassprite2.getMinV();
            float f8 = textureatlassprite2.getMaxU();
            float f9 = textureatlassprite2.getMaxV();

            if (i / 2 % 2 == 0)
            {
                float f10 = f8;
                f8 = f6;
                f6 = f10;
            }

            bufferbuilder.pos((double)(f1 - 0.0F), (double)(0.0F - f4), (double)f5).tex((double)f8, (double)f9).endVertex();
            bufferbuilder.pos((double)(-f1 - 0.0F), (double)(0.0F - f4), (double)f5).tex((double)f6, (double)f9).endVertex();
            bufferbuilder.pos((double)(-f1 - 0.0F), (double)(1.4F - f4), (double)f5).tex((double)f6, (double)f7).endVertex();
            bufferbuilder.pos((double)(f1 - 0.0F), (double)(1.4F - f4), (double)f5).tex((double)f8, (double)f7).endVertex();
            f3 -= 0.45F;
            f4 -= 0.45F;
            f1 *= 0.9F;
            f5 += 0.03F;
            ++i;
        }

        tessellator.draw();
        GlStateManager.popMatrix();
        GlStateManager.enableLighting();
    }
}