package hmggirlfront.render;

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.mod_GirlFront;
import hmggirlfront.entity.EntityDoll_Dummy;
import hmggirlfront.entity.GFEntityID;
import hmggirlfront.entity.GFEntityID_Dummy;
import hmggirlfront.items.ItemDollAttachment;
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.init.MobEffects;
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 RenderDoll_Dummy extends RenderLiving<EntityDoll_Dummy> //extends RenderLiving<EntityDoll_Dummy>
{
    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"));
    
    
    private static final ResourceLocation para = new ResourceLocation("hmggirlfront:textures/model/doll/parachute.png");
    private static final IModelCustom param = AdvancedModelLoader.loadModel(new ResourceLocation("hmggirlfront:textures/model/doll/parachute.mqo"));
    
    
    /** instance of ModelBoat for rendering */
    
    private static final ResourceLocation t0 = new ResourceLocation("hmggirlfront:textures/model/marker/marker0.png");
	private static final ResourceLocation t1 = new ResourceLocation("hmggirlfront:textures/model/marker/marker1.png");
	private static final ResourceLocation t2 = new ResourceLocation("hmggirlfront:textures/model/marker/marker2.png");
	private static final ResourceLocation t3 = new ResourceLocation("hmggirlfront:textures/model/marker/marker3.png");
	private static final ResourceLocation t5 = new ResourceLocation("hmggirlfront:textures/model/marker/marker5.png");
    private static final IModelCustom marker = AdvancedModelLoader.loadModel(new ResourceLocation("hmggirlfront:textures/model/marker/marker.obj"));
    
    private static final ResourceLocation class_assalt = new ResourceLocation("hmggirlfront:textures/model/marker/class_assalt.png");
    private static final ResourceLocation class_medic = new ResourceLocation("hmggirlfront:textures/model/marker/class_medic.png");
    private static final ResourceLocation class_support = new ResourceLocation("hmggirlfront:textures/model/marker/class_support.png");
    private static final ResourceLocation class_scout = new ResourceLocation("hmggirlfront:textures/model/marker/class_scout.png");
    private static final ResourceLocation class_torcher = new ResourceLocation("hmggirlfront:textures/model/marker/class_torcher.png");
    private static final IModelCustom doll_class = AdvancedModelLoader.loadModel(new ResourceLocation("hmggirlfront:textures/model/marker/class.mqo"));

    private static final ResourceLocation class_grenade_n = new ResourceLocation("hmggirlfront:textures/items/gun/idoll_grenade_n.png");
    private static final ResourceLocation class_grenade_f = new ResourceLocation("hmggirlfront:textures/items/gun/idoll_grenade_f.png");
    private static final ResourceLocation class_grenade_s = new ResourceLocation("hmggirlfront:textures/items/gun/idoll_grenade_s.png");
    private static final ResourceLocation class_grenade_fb = new ResourceLocation("hmggirlfront:textures/items/gun/idoll_grenade_fb.png");
    private static final ResourceLocation class_grenade_gb = new ResourceLocation("hmggirlfront:textures/items/item/idoll_bullet_40.png");
    
    public RenderDoll_Dummy(RenderManager renderManagerIn)
    {
        super(renderManagerIn, new ModelBase_Non(),0.5F);
  //  	super(renderManagerIn);
        this.shadowSize = 0.5F;
    }

    public void rendermodel(EntityDoll_Dummy entity, String model) {
    	GFEntityID_Dummy gfid = new GFEntityID_Dummy(entity);
    	IModelCustom mo = gfid.getModel();
    	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(EntityDoll_Dummy entity)
    {
    	ResourceLocation dolltex = m1911t;
    	GFEntityID_Dummy gfid = new GFEntityID_Dummy(entity);
    	ResourceLocation te = gfid.getModelTex();
    	if(te != null) {
    		dolltex = te;
    	}
		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(EntityDoll_Dummy 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.getMoveT() == 3 && entity.getFTMode() == 1) || 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);
		}
		if(entity.getSneak()){
			GL11.glTranslatef(0F, 0.75F, 0.0F);
    		GL11.glRotatef(20, 1.0F, 0.0F, 0.0F);
    		GL11.glTranslatef(0F, -0.75F, 0.0F);
    		
    		GL11.glTranslatef(0F, 1.5F, 0.0F);
			GL11.glRotatef(-20, 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");
		
		
		if(!entity.getBoost()) {
		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);
			if(entity.getMoveT() == 0) {
				Minecraft.getMinecraft().renderEngine.bindTexture(t0);
			}
			else if(entity.getMoveT() == 1) {
				Minecraft.getMinecraft().renderEngine.bindTexture(t1);
			}
			else if(entity.getMoveT() == 2) {
				Minecraft.getMinecraft().renderEngine.bindTexture(t2);
			}
			else if(entity.getMoveT() == 3) {
				Minecraft.getMinecraft().renderEngine.bindTexture(t3);
			}
			else if(entity.getMoveT() == 5) {
				Minecraft.getMinecraft().renderEngine.bindTexture(t5);
			}else 
			{
				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
		}
		ItemStack feet = entity.getItemStackFromSlot(EntityEquipmentSlot.FEET);
		if(!feet.isEmpty() &&  feet.getItem() instanceof ItemDollAttachment) {
			ItemDollAttachment am = (ItemDollAttachment) feet.getItem();
			{
				GL11.glPushMatrix();//glstart
				Minecraft mc = Minecraft.getMinecraft();
				RenderManager manager = mc.getRenderManager();
				GlStateManager.rotate(-manager.playerViewY, 0.0F, 1.0F, 0.0F);
		        //GlStateManager.rotate((float)(manager.options.thirdPersonView == 2 ? -1 : 1) * manager.playerViewX, 1.0F, 0.0F, 0.0F);
				//GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
				GL11.glEnable(GL12.GL_RESCALE_NORMAL);
				GL11.glTranslatef(0.5F, entity.height + 1.0F, 0);
				if(feet.getItem() == mod_GirlFront.dollam_class_assalt) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_assalt);
				}
				if(feet.getItem() == mod_GirlFront.dollam_class_medic) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_medic);
				}
				if (feet.getItem() == mod_GirlFront.dollam_class_support) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_support);
				}
				if (feet.getItem() == mod_GirlFront.dollam_class_scout) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_scout);
				}
				if (feet.getItem() == mod_GirlFront.dollam_class_torcher) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_torcher);
				}
		            GlStateManager.disableLighting();
		            doll_class.renderPart("mat1");
					GlStateManager.enableLighting();
		        GL11.glPopMatrix();//glend
			}
		}
		if(entity.doll_skill != 0) {
			if(entity.doll_skill_can){
				GL11.glPushMatrix();//glstart
				Minecraft mc = Minecraft.getMinecraft();
				RenderManager manager = mc.getRenderManager();
				GlStateManager.rotate(-manager.playerViewY, 0.0F, 1.0F, 0.0F);
				GL11.glEnable(GL12.GL_RESCALE_NORMAL);
				GL11.glTranslatef(-0.5F, entity.height + 1.0F, 0);
				if(entity.doll_skill == 1) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_grenade_n);
				}
				if(entity.doll_skill == 2) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_grenade_f);
				}
				if (entity.doll_skill == 3) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_grenade_s);
				}
				if (entity.doll_skill == 4) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_grenade_fb);
				}
				if (entity.doll_skill == 10) {
					Minecraft.getMinecraft().renderEngine.bindTexture(class_grenade_gb);
				}
		            GlStateManager.disableLighting();
		            doll_class.renderPart("mat1");
					GlStateManager.enableLighting();
		        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);
		
		/*{
		GL11.glPushMatrix();//glstart
		Minecraft mc = Minecraft.getMinecraft();
		RenderManager manager = mc.getRenderManager();
		double d0 = entity.getDistanceSq(manager.renderViewEntity);

        if (d0 <= (double)(64 * 64))
        {
            boolean flag = entity.isSneaking();
            float f = manager.playerViewY;
            float f1 = manager.playerViewX;
            boolean flag1 = manager.options.thirdPersonView == 2;
            float f2 = entity.height + 0.5F - (flag ? 0.25F : 0.0F);
            int i = "deadmau5".equals("0000") ? -10 : 0;
            EntityRenderer.drawNameplate(manager.getFontRenderer(), "0000", (float)x, (float)y + f2, (float)z, i, f, f1, flag1, flag);
        }
        GL11.glPopMatrix();//glend
	}*/
    }
    
    private void renderlegs(EntityDoll_Dummy 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.getMoveT() == 3 && entity.getFTMode() == 1) || 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.getMoveT() == 3 && entity.getFTMode() == 1) || 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(EntityDoll_Dummy entity, float limbSwing, float limbSwingAmount, float partialTicks){
    	if(entity.deathTime > 0 || entity.getSneak()){
    		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");
//		if (entity.isPotionActive(MobEffects.LUCK))
		
		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.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
		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(main.isEmpty() && off.isEmpty()) {
				arm_l_rotex = Ax * (180F / (float)Math.PI);
			}
			else 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.getMoveT() == 3 && entity.getFTMode() == 1) || 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 {
					if(entity.getFTMode() == 1) {
						arm_l_rotex = Ax * (180F / (float)Math.PI);
					}else {
						ItemGunBase gun = null;
						if (!main.isEmpty() && main.getItem() instanceof ItemGunBase  && tageflag && (entity.getFTMode() != 1 || entity.getattacktask())){
							gun = (ItemGunBase) main.getItem();
						}
						if(gun != null) {
							
							double xmove = Math.abs(entity.motionX);
							double zmove = Math.abs(entity.motionZ);
							if(gun.arm_l_posz > -1.0F) {
								if(xmove > 0 || zmove > 0) {
									arm_l_rotex = -20;
									arm_l_rotez = -20;
								}else {
									arm_l_rotex = -20;
									arm_l_rotez = -10;
								}
							}else {
								if(xmove > 0 || zmove > 0) {
									arm_l_rotex = -20;
									arm_l_rotez = -30;
								}else {
									arm_l_rotex = -10;
									arm_l_rotez = -00;
								}
							}
						}else {
							arm_l_rotex = -20;
							arm_l_rotez = -10;
						}
						
					}
				}
			}
			if(entity.getSneak()){
				arm_l_rotex = arm_l_rotex -20;
			}
			//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 && (entity.getFTMode() != 1 || entity.getattacktask())){
				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
				
				GL11.glScalef(1/entity.doll_size, 1/entity.doll_size, 1/entity.doll_size);
				
				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(main.isEmpty() && off.isEmpty()) {
				arm_r_rotex = Ax * (180F / (float)Math.PI);
			}
			else if(entity.getattacktask() && !(entity.deathTime > 0)) {
				if(entity.gun_count1 < 2 && entity.firetrue){
	    			GL11.glRotatef(-entity.gun_count1, 1.0F, 0.0F, 0.0F);
	    		}
				arm_r_rotex = -90 + entity.rotationPitch;
			}else if((entity.getMoveT() == 3 && entity.getFTMode() == 1) || entity.isRiding()) {
				arm_r_rotex = -30;
			}
			else if(entity.deathTime > 0){
				arm_r_rotex = -20;
			}
			else {
				ItemGunBase gun = null;
				if (!main.isEmpty() && main.getItem() instanceof ItemGunBase  && tageflag && (entity.getFTMode() != 1 || entity.getattacktask())){
					gun = (ItemGunBase) main.getItem();
				}
				if(entity.getFTMode() == 1 || (!off.isEmpty() && off.getItem() instanceof ItemGunBase)) {
					arm_r_rotex = Ax * (180F / (float)Math.PI) - 20;
				}else {
					double xmove = Math.abs(entity.motionX);
					double zmove = Math.abs(entity.motionZ);
					if(gun != null && gun.arm_l_posz > -1.0F) {
						arm_r_rotex =  - 30;
						arm_r_rotez =   10;
					}else {
						if(xmove > 0 || zmove > 0) {
							arm_r_rotex =  - 15;
						}else {
							arm_r_rotex =  - 5;
						}
					}
				}
			}
			
			if(entity.getSneak()){
				arm_r_rotex = arm_r_rotex -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 && (entity.getFTMode() != 1 || entity.getattacktask())){
				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
				
				GL11.glScalef(1/entity.doll_size, 1/entity.doll_size, 1/entity.doll_size);
				
				if(!entity.getattacktask() && !(entity.deathTime > 0)) {
					if((entity.getMoveT() == 3 && entity.getFTMode() == 1) || entity.isRiding()) {
						if(gun.arm_l_posz > -1.0F) {
							GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
						}
					}else {
						double xx = Math.abs(entity.posX - entity.prevPosX);
						double zz = Math.abs(entity.posZ - entity.prevPosZ);
						double xmove = Math.abs(entity.motionX);
						double zmove = Math.abs(entity.motionZ);
						if(entity.getFTMode() != 1 && gun.arm_l_posz > -1.0F) {
							//GL11.glRotatef(mod_GirlFront.test_x, 1.0F, 0.0F, 0.0F);
							//GL11.glRotatef(mod_GirlFront.test_y, 0.0F, 1.0F, 0.0F);
							//GL11.glRotatef(mod_GirlFront.test_z, 0.0F, 0.0F, 1.0F);
							if(xmove > 0 || zmove > 0) {
								/*GL11.glRotatef(mod_GirlFront.test_x, 1.0F, 0.0F, 0.0F);
								GL11.glRotatef(mod_GirlFront.test_y, 0.0F, 1.0F, 0.0F);
								GL11.glRotatef(mod_GirlFront.test_z, 0.0F, 0.0F, 1.0F);*/
								GL11.glRotatef(-25, 1.0F, 0.0F, 0.0F);
								GL11.glRotatef(20, 0.0F, 1.0F, 0.0F);
								GL11.glRotatef(-10, 0.0F, 0.0F, 1.0F);
							}else {
								GL11.glRotatef(-10, 1.0F, 0.0F, 0.0F);
								GL11.glRotatef(50, 0.0F, 1.0F, 0.0F);
								GL11.glRotatef(-60, 0.0F, 0.0F, 1.0F);
							}
							
						}
						if(gun.arm_l_posz > -1.0F && (xx < 0.00002 && zz < 0.00002)) {
							//GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
						}
					}
				}
				
				Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(tex));
				gun.obj_model.renderPart("mat1");
				gun.obj_model.renderPart("mat100");
				gun.obj_model.renderPart("mat20");
				gun.obj_model.renderPart("mat22");
				gun.obj_model.renderPart("mat21");
				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(EntityDoll_Dummy entityLivingBaseIn, double x, double y, double z)
    {
        GlStateManager.translate((float)x, (float)y, (float)z);
    }
    protected float handleRotationFloat(EntityDoll_Dummy 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();
    }
}