package hmggirlfront.entity.vehicle;

import java.util.List;

import gvclib.mod_GVCLib;
import gvclib.entity.living.AI_AirCraftSet;
import gvclib.entity.living.EntityGVCLivingBase;
import gvclib.entity.living.EntityMobVehicleBase;
import gvclib.entity.living.ISoldier;
import gvclib.entity.living.PL_AirCraftMove;
import gvclib.event.GVCSoundEvent;
import gvclib.network.GVCLMessageKeyPressed;
import gvclib.network.GVCLPacketHandler;
import hmggirlfront.mod_GirlFront;
import hmggirlfront.entity.EntityDoll;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class EntityVe_Heli extends EntityMobVehicleBase
{

    public EntityVe_Heli(World worldIn)
    {
        super(worldIn);
        this.setSize(6F, 4.0F);
        this.setVehicleLock(true);
        this.setcanDespawn(1);
        this.ridding_sneakdismount = false;
        this.riddng_freehand = false;
        this.hud_icon = "hmggirlfront:textures/hud/heli.png";
        this.render_hud_icon_hori = true;
        this.hud_icon_hori = "hmggirlfront:textures/hud/heli_hori.png";
        this.render_hud_information_1 = "Z-KEY:Get off";
        this.render_hud_information_2 = "W/S-KEY:Throttle-UP/DWON";
        this.render_hud_information_3 = "SPEAC/SHIFT-KEY:UP/DWON";
        this.render_hud_information_4 = "Mouse-UP/DOWN:PICTH-UP/DOWN";
        this.render_hud_information_5 = "V-KEY:ALLY-Boarding";
        this.render_hud_information_6 = "B-KEY:ALLY-Get off";
        vehicletype = 2;
        ridding_roteplayer = false;
        roodbreak = mod_GirlFront.cfg_vehicle_breakblock;
        this.spawn_item = mod_GirlFront.ve_heli;
        
        vehicle_ridding_nofire[2] = true;
        vehicle_ridding_nofire[3] = true;
        
        this.sp = 0.03F;
        this.turnspeed = 2F;
        this.rotationp_max = -20F;
        this.rotationp_min = 30F;
		this.ridding_invisible = false;
		this.riddng_opentop = true;
		this.renderhud = true;
        this.thmax = 20F;
		this.thmin = -2F;
		this.thmaxa = 0.2F;
		this.thmina = -0.15F;
		this.stepHeight = 1.5F;
		this.riddng_maximum = 6;
		riddingx[0]=0.6D;
		riddingy[0]=0.85D;
		riddingz[0]=2.0D;
		{
			riddingx[1]=-0.6D;
			riddingy[1]=1.05D;
			riddingz[1]=2.0D;
			
			riddingx[2]=0.72D;
			riddingy[2]=1.12D;
			riddingz[2]=-1.2D;
			
			riddingx[3]=-0.72D;
			riddingy[3]=1.12D;
			riddingz[3]=-1.2D;
			
			riddingx[4]=0.4D;
			riddingy[4]=1.12D;
			riddingz[4]=-0.36D;
			riddingx[5]=-0.4D;
			riddingy[5]=1.12D;
			riddingz[5]=-0.36D;
			
		}
		
		
		ridding_view_x=0F;
		ridding_view_y=-2F;
		ridding_view_z=-10F;
		ridding_view_gunner_x=0F;
		ridding_view_gunner_y=2F;
		ridding_view_gunner_z=1F;
		
		antibullet_0 = 0.2F;
		antibullet_1 = 1.0F;
		antibullet_2 = 2.0F;
		antibullet_3 = 1.2F;
		this.ridding_damege = 0.5F;
		
		{
			cloud = 2;
			cloud_x[0] = 1.0D;
			cloud_y[0] = 2.75D;
			cloud_z[0] = -2.7D;
			
			cloud_x[1] = -1.0D;
			cloud_y[1] = 2.75D;
			cloud_z[1] = -2.7D;
		}
		{
			pera = 2;
			pera_x[0] = 0F;
			pera_y[0] = 4F;
			pera_z[0] = 0F;
			perarote_x[0] = 0F;
			perarote_y[0] = 1F;
			perarote_z[0] = 0F;
			pera_x[1] = 0F;
			pera_y[1] = 3.24F;
			pera_z[1] = -6.56F;
			perarote_x[1] = 1F;
			perarote_y[1] = 0F;
			perarote_z[1] = 0F;
		}
		
		mob_min_range = 10;
		mob_max_range = 90;
		
		{
			this.weapon2true = true;
			this.weapon2key = 0;
			this.ammo2 = 1;
			this.magazine2 = 30;
			reload_time2 = 100;
			this.w2name = "MachineGun";
			this.w2cycle = 1;
			this.w2barst = 1;
			this.weapon2 = 1;
			{
				this.bullet_type2[0] = 0;
				this.bullet_model2[0] = "gvclib:textures/entity/BulletNormal.obj";
				this.bullet_tex2[0] = "gvclib:textures/entity/BulletNormal.png";
				this.fire_model2[0] = "gvclib:textures/entity/mflash.mqo";
				this.fire_tex2[0] = "gvclib:textures/entity/mflash.png";
				this.fire_time2[0] = 2;
				this.sound_fire2[0] = "gvclib.fire_rifle";
				this.fire_pointx2[0] = 1.5F;
				this.fire_pointy2[0] = 1.4F;
				this.fire_pointz2[0] = -0.75F;
				this.basis_pointx2[0] = 1.5F;
        		this.basis_pointy2[0] = 1.4F;
        		this.basis_pointz2[0] = -0.75F;
				this.fire_yoffset2[0] = 0;
				this.rotationfollowing2[0] = true;
				this.rotationfirepoint2[0] = true;
				this.rotation_mob_head2[0] = true;
				this.bullet_damage2[0] = 4;
				this.bullet_speed2[0] = 4F;
				this.bullet_bure2[0] = 5.0F;
				this.bullet_expower2[0] = 0F;
				this.bullet_ex2[0] = false;
				this.bullet_kazu2[0] = 1;
				this.bullet_gravity2[0] = 0.029D;
				this.bullet_livingtime2[0] = 80;

			}
			this.mob_min_range = 15;
			this.mob_max_range = 30;
			this.mob_w2range = 40;
			this.mob_w2range_max_y = 30;
			this.mob_w2range_min_y = 30;
		}
		{
			this.weapon3true = true;
			this.weapon3key = 0;
			this.ammo3 = 1;
			this.magazine3 = 30;
			reload_time3 = 100;
			this.w3name = "MachineGun";
			this.w3cycle = 1;
			this.w3barst = 1;
			this.weapon3 = 1;
			{
				this.bullet_type3[0] = 0;
				this.bullet_model3[0] = "gvclib:textures/entity/BulletNormal.obj";
				this.bullet_tex3[0] = "gvclib:textures/entity/BulletNormal.png";
				this.fire_model3[0] = "gvclib:textures/entity/mflash.mqo";
				this.fire_tex3[0] = "gvclib:textures/entity/mflash.png";
				this.fire_time3[0] = 2;
				this.sound_fire3[0] = "gvclib.fire_rifle";
				this.fire_pointx3[0] = -1.5F;
				this.fire_pointy3[0] = 1.4F;
				this.fire_pointz3[0] = -0.75F;
				this.basis_pointx3[0] = -1.5F;
        		this.basis_pointy3[0] = 1.4F;
        		this.basis_pointz3[0] = -0.75F;
				this.fire_yoffset3[0] = 0;
				this.rotationfollowing3[0] = true;
				this.rotationfirepoint3[0] = true;
				this.rotation_mob_head3[0] = true;
				this.bullet_damage3[0] = 4;
				this.bullet_speed3[0] = 4F;
				this.bullet_bure3[0] = 5.0F;
				this.bullet_expower3[0] = 0F;
				this.bullet_ex3[0] = false;
				this.bullet_kazu3[0] = 1;
				this.bullet_gravity3[0] = 0.029D;
				this.bullet_livingtime3[0] = 80;

			}
			this.mob_min_range = 15;
			this.mob_max_range = 30;
			this.mob_w3range = 40;
			this.mob_w3range_max_y = 30;
			this.mob_w3range_min_y = 30;
		}
		
		this.weapon4type = 1;
		{
			this.weapon4true = true;
    		this.weapon4key = 0;
    		this.w4name = "Flare";
    		this.ammo4 = 30;
    		this.magazine4 = 1;
    		this.reload_time4 = 30;
    		this.reloadsoundset4 = 0;
    		this.reloadsound4 = GVCSoundEvent.reload_cannon;
    		this.w4cycle = 1;
    		this.w4barst = 1;
    		this.weapon4 = 1;
    		this.w4crossfire = false;
    			this.bullet_type4[0] = 21;
        		this.sound_fire4[0] = "gvclib.fire_roket";
        		this.fire_pointx4[0] = 6.4F;
        		this.fire_pointy4[0] = 2.5F;
        		this.fire_pointz4[0] = 0.5F;
        		this.basis_pointx4[0] = 3.5F;
        		this.basis_pointy4[0] = (float) (riddingy[0] + 1.25F);
        		this.basis_pointz4[0] = 0F;
        		this.fire_yoffset4[0] = 0;
        		this.bullet_speed4[0] = 1F;
        		this.bullet_kazu4[0] = 1;
        		
		}
    }

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(200D);
        this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(20D);
    }

    
    public boolean processInteract(EntityPlayer player, EnumHand hand)
    {
    	ItemStack itemstack = player.getHeldItem(hand);
        boolean flag = !itemstack.isEmpty();
        if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.idoll_parts)
        {
        	if(this.getHealth() < this.getMaxHealth()) {
				this.setHealth(this.getHealth() + 10);
    			itemstack.shrink(1);
    			this.playSound(SoundEvents.BLOCK_ANVIL_LAND, 5F, 2F);
			}
        	return true;
        }
        else  if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.ve_weaponchange)
        {
        	this.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1.0F, 1.0F);
        	if(this.getArmID_L() == 0) {
        		this.setArmID_L(1);
        		this.setRemain_L(30);
        	}else if(this.getArmID_L() == 1) {
        		this.setArmID_L(2);
        		this.setRemain_L(4);
        	}
        	else {
        		this.setArmID_L(0);
        		this.setRemain_L(0);
        	}
        	return true;
        }
        /*else if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.dollgun_galil)
        {
        	itemstack.shrink(1);
        	this.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1.0F, 1.0F);
        	this.setArmID_L(1);
        	this.setRemain_L(30);
        	return true;
        }
        else if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.dollgun_fn49)
        {
        	itemstack.shrink(1);
        	this.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1.0F, 1.0F);
        	this.setArmID_L(2);
        	this.setRemain_L(4);
        	return true;
        }
        else if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.dollgun_m1911)
        {
        	itemstack.shrink(1);
        	this.playSound(SoundEvents.BLOCK_ANVIL_HIT, 1.0F, 1.0F);
        	this.setArmID_L(0);
        	this.setRemain_L(0);
        	return true;
        }*/
        else{
        	super.processInteract(player, hand);
        	return true;
        }
        
    }
    
    public boolean spawn = false;
    public void onUpdate() {
		super.onUpdate();
		this.setcanDespawn(1);
		this.riddng_freehand = false;
		float f1 = this.rotationYawHead * (2 * (float) Math.PI / 360);
		this.roadattack();
		this.setcanDespawn(1);
		//this.typeHeli(GVCSoundEvent.sound_heli);
		this.setVehicleLock(true);
		
		this.ContMobRidding();
		
		if(this.getArmID_L() == 2){
			this.weapon1true = true;
    		this.weapon1key = 0;
    		this.w1name = "76mmRocket";
    		this.ammo1 = 10;
    		this.magazine = 4;
    		this.reload_time1 = 80;
    		this.reloadsoundset1 = 20;
    		this.reloadsound1 = GVCSoundEvent.reload_shell;
    		this.w1cycle = 1;
    		this.w1barst = 1;
    		this.weapon1 = 1;
    		this.w1crossfire = true;
    		{
    			this.bullet_type1[0] = 3;
        		this.bullet_model1[0] = "gvclib:textures/entity/BulletRocket.obj";
        		this.bullet_tex1[0] = "gvclib:textures/entity/BulletRocket.png";
        		this.fire_model1[0]= "gvclib:textures/entity/mflash.mqo";
        		this.fire_tex1[0] = "gvclib:textures/entity/mflash.png";
        		this.fire_time1[0] = 2;
        		this.sound_fire1[0] = "gvclib.fire_roket";
        		this.fire_pointx1[0] = 1.1F;
        		this.fire_pointy1[0] = 0.7F;
        		this.fire_pointz1[0] = 2.0F;
        		this.basis_pointx1[0] = 1.1F;
        		this.basis_pointy1[0] = 0.7F;
        		this.basis_pointz1[0] = 2.0F;
        		this.fire_yoffset1[0] = 0;
        		this.rotationfollowing1[0] = false;
        		this.rotation_player1[0] = false;
        		this.rotationfirepoint1[0] = false;
        		this.bullet_damage1[0] = 25;
        		this.bullet_speed1[0] = 3.0F;
        		this.bullet_bure1[0] = 1F;
        		this.bullet_expower1[0] = 2.0F;
        		this.bullet_ex1[0] = false;
        		this.bullet_kazu1[0] = 1;
        		this.bullet_gravity1[0] = 0.029D;
        		this.bullet_livingtime1[0] = 80;
    		}
			this.mob_min_range = 15;
			this.mob_max_range = 50;
			this.mob_w1range = 50;
			this.mob_w1range_max_y = 5;
			this.mob_w1range_min_y = 30;
		}else if(this.getArmID_L() == 1){
			this.weapon1true = true;
			this.weapon1key = 0;
			this.ammo1 = 1;
			this.magazine = 30;
			reload_time1 = 100;
			this.w1name = "MachineGun";
			this.w1cycle = 1;
			this.w1barst = 1;
			this.weapon1 = 2;
			{
				this.bullet_type1[0] = 0;
				this.bullet_model1[0] = "gvclib:textures/entity/BulletNormal.obj";
				this.bullet_tex1[0] = "gvclib:textures/entity/BulletNormal.png";
				this.fire_model1[0] = "gvclib:textures/entity/mflash.mqo";
				this.fire_tex1[0] = "gvclib:textures/entity/mflash.png";
				this.fire_time1[0] = 2;
				this.sound_fire1[0] = "gvclib.fire_rifle";
				this.fire_pointx1[0] = 1.1F;
        		this.fire_pointy1[0] = 0.7F;
        		this.fire_pointz1[0] = 2.2F;
        		this.basis_pointx1[0] = 1.1F;
        		this.basis_pointy1[0] = 0.7F;
        		this.basis_pointz1[0] = 1.0F;
				this.fire_yoffset1[0] = 0;
				this.rotationfollowing1[0] = false;
        		this.rotation_player1[0] = false;
        		this.rotationfirepoint1[0] = false;
				this.bullet_damage1[0] = 4;
				this.bullet_speed1[0] = 4F;
				this.bullet_bure1[0] = 2.0F;
				this.bullet_expower1[0] = 0F;
				this.bullet_ex1[0] = false;
				this.bullet_kazu1[0] = 1;
				this.bullet_gravity1[0] = 0.029D;
				this.bullet_livingtime1[0] = 80;
			}
			{
				this.bullet_type1[1] = 0;
				this.bullet_model1[1] = "gvclib:textures/entity/BulletNormal.obj";
				this.bullet_tex1[1] = "gvclib:textures/entity/BulletNormal.png";
				this.fire_model1[1] = "gvclib:textures/entity/mflash.mqo";
				this.fire_tex1[1] = "gvclib:textures/entity/mflash.png";
				this.fire_time1[1] = 2;
				this.sound_fire1[1] = "gvclib.fire_rifle";
				this.fire_pointx1[1] = -1.1F;
        		this.fire_pointy1[1] = 0.7F;
        		this.fire_pointz1[1] = 2.2F;
        		this.basis_pointx1[1] = -1.1F;
        		this.basis_pointy1[1] = 0.7F;
        		this.basis_pointz1[1] = 1.0F;
				this.fire_yoffset1[1] = 0;
				this.rotationfollowing1[1] = false;
        		this.rotation_player1[1] = false;
        		this.rotationfirepoint1[1] = false;
				this.bullet_damage1[1] = 4;
				this.bullet_speed1[1] = 4F;
				this.bullet_bure1[1] = 2.0F;
				this.bullet_expower1[1] = 0F;
				this.bullet_ex1[1] = false;
				this.bullet_kazu1[1] = 1;
				this.bullet_gravity1[1] = 0.029D;
				this.bullet_livingtime1[1] = 80;
			}
			this.mob_min_range = 15;
			this.mob_max_range = 30;
			this.mob_w1range = 30;
			this.mob_w1range_max_y = 5;
			this.mob_w1range_min_y = 30;
		}else{
			this.weapon1true = false;
		}
		
		if (this.canBeSteered() && this.getControllingPassenger() != null && this.getHealth() > 0.0F)
		{
			if(this.getControllingPassenger() instanceof EntityPlayer)
			{
				boolean kf = mod_GVCLib.proxy.keyf();
				if (kf) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(19, this.getEntityId()));
				}
				EntityPlayer entitylivingbase = (EntityPlayer) this.getControllingPassenger();
				Vec3d looked = entitylivingbase.getLookVec();
				if (this.serverf) {
					{
						if(this.cooltime4 >= this.ammo4){
							this.counter4 = true;
							this.cooltime4 = 0;
	    				}
	    				if(this.weapon4true) {
	    					this.weapon4active(looked, entitylivingbase);
	        		    }
					}
					this.serverf = false;
			}
			
			
		}
		}
		
		if (this.canBeSteered() && this.getControllingPassenger() != null && this.getHealth() > 0.0F)
		{
			if(this.getControllingPassenger() instanceof EntityPlayer)
			{
				EntityPlayer entitylivingbase = (EntityPlayer) this.getControllingPassenger();
				this.setcanDespawn(1);
				this.rotation = entitylivingbase.rotationYawHead;
				this.rotationp = entitylivingbase.rotationPitch;
				//this.rotationPitch = entitylivingbase.rotationPitch;
				Vec3d looked = this.getLookVec();
				if (this.getFTMode() != 1) {
					//PL_AirCraftMove.moveheli(entitylivingbase, this, sp, turnspeed);
					PL_AirCraftMove.moveheli_NEW(entitylivingbase, this, sp, turnspeed);
				} else {
					PL_AirCraftMove.moveheligunner(entitylivingbase, this, sp, turnspeed);
				}

				boolean left = mod_GVCLib.proxy.leftclick();
				boolean right = mod_GVCLib.proxy.rightclick();
				boolean jump = mod_GVCLib.proxy.jumped();
				boolean kx = mod_GVCLib.proxy.keyx();
				boolean kg = mod_GVCLib.proxy.keyg();
				boolean kc = mod_GVCLib.proxy.keyc();
				if (left) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(11, this.getEntityId()));
					this.server1 = true;
				}
				if (right) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(12, this.getEntityId()));
				}
				if (jump) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(13, this.getEntityId()));
				}
				if (kx) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(14, this.getEntityId()));
				}
				if (kg) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(15, this.getEntityId()));
				}
				if (kc) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(16, this.getEntityId()));
				}

				

				if (serverx) {
					this.serverx = false;
				}
				if (this.server1) {
					{
	    				if(cooltime >= ammo1){
	    					this.counter1 = true;
	    		            cooltime = 0;
	    				}
	    				if(this.weapon1true) {
	    					{
	    						this.weapon1active(looked, entitylivingbase);
	    					}
	        		    }
	    			}
					this.server1 = false;
				}
			}//player
			else if(this.getControllingPassenger() instanceof EntityGVCLivingBase) {
				
			}
		}
		if(this.getPassengers().size() > 2)
        {
        	 if(this.getPassengers().get(2) != null){
     			if (this.getPassengers().get(2) instanceof EntityPlayer) {
     				EntityPlayer entitylivingbase = (EntityPlayer)this.getPassengers().get(2);
     				this.setcanDespawn(1);
     				this.rotation_2  = entitylivingbase.rotationYawHead;
     				this.rotationp_2 = entitylivingbase.rotationPitch;
     				Vec3d looked = entitylivingbase.getLookVec();
     				boolean left = mod_GVCLib.proxy.leftclick();
     				if (left) {
     					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(11, this.getEntityId()));
     					this.server1 = true;
     				}

     				if (this.server1) {
     					{
     	    				if(cooltime2 >= ammo2){
     	    					this.counter2 = true;
     	    		            cooltime2 = 0;
     	    				}
     	    				if(this.weapon2true) {
     	    					{
     	    						this.weapon2active(looked, entitylivingbase);
     	    					}
     	        		    }
     	    			}
     					this.server1 = false;
     				}
     			}else
     			if (this.getPassengers().get(2) instanceof EntityDoll) {
     				EntityDoll entitylivingbase = (EntityDoll)this.getPassengers().get(2);
     				if(entitylivingbase.getattacktask()) {
     					
     				}else {
     					entitylivingbase.rotationYawHead = this.rotationYaw;
     				}
     				this.rotation_2  = entitylivingbase.rotationYawHead;
     				this.rotationp_2 = entitylivingbase.rotationPitch;
     				Vec3d looked = entitylivingbase.getLookVec();
     				//AI_EntityWeapon.getTargetEntity(entitylivingbase, this.mob_w2range, this.mob_w2range_max_y, this.mob_w2range_min_y);
     				DollAI_GetTarget.load(entitylivingbase, this.mob_w2range, this.mob_w2range_max_y, this.mob_w2range_min_y, this.rotationYaw, 0, 180);
     				if(DollAI_GetTarget.getRange(entitylivingbase, this.mob_w2range, this.mob_w2range_max_y, this.mob_w2range_min_y, this.rotationYaw, 0, 180)){
     					if(cooltime2 >= ammo2 && this.getRemain_R() > 0){
     						this.counter2 = true;
     			            cooltime2 = 0;
     					}
     					if(this.weapon2true) {
     	    		    	this.weapon2activeMob(looked, entitylivingbase, 0);
     	    		    }
     				}
     			}
     		}else {
     			this.rotation_2  = this.rotationYawHead;
 				this.rotationp_2 = this.rotationPitch;
     		}
        }
		if(this.getPassengers().size() > 3)
        {
        	 if(this.getPassengers().get(3) != null){
      			if (this.getPassengers().get(3) instanceof EntityPlayer) {
      				EntityPlayer entitylivingbase = (EntityPlayer)this.getPassengers().get(3);
      				this.setcanDespawn(1);
      				this.rotation_3  = entitylivingbase.rotationYawHead;
     				this.rotationp_3 = entitylivingbase.rotationPitch;
      				Vec3d looked = entitylivingbase.getLookVec();
      				boolean left = mod_GVCLib.proxy.leftclick();
      				if (left) {
      					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(11, this.getEntityId()));
      					this.server1 = true;
      				}

      				if (this.server1) {
      					{
      	    				if(cooltime3 >= ammo3){
      	    					this.counter3 = true;
      	    		            cooltime3 = 0;
      	    				}
      	    				if(this.weapon3true) {
      	    					{
      	    						this.weapon3active(looked, entitylivingbase);
      	    					}
      	        		    }
      	    			}
      					this.server1 = false;
      				}
      			}else
      			if (this.getPassengers().get(3) instanceof EntityDoll) {
      				EntityDoll entitylivingbase = (EntityDoll)this.getPassengers().get(3);
      				if(entitylivingbase.getattacktask()) {
      					
      				}else {
      					entitylivingbase.rotationYawHead = this.rotationYaw;
      				}
      				this.rotation_3  = entitylivingbase.rotationYawHead;
      				this.rotationp_3 = entitylivingbase.rotationPitch;
      				Vec3d looked = entitylivingbase.getLookVec();
      				//AI_EntityWeapon.getTargetEntity(entitylivingbase, this.mob_w4range, this.mob_w4range_max_y, this.mob_w4range_min_y);
      				DollAI_GetTarget.load(entitylivingbase, this.mob_w4range, this.mob_w3range_max_y, this.mob_w3range_min_y, this.rotationYaw, 180, 0);
      				if(DollAI_GetTarget.getRange(entitylivingbase, this.mob_w4range, this.mob_w3range_max_y, this.mob_w3range_min_y, this.rotationYaw, 180, 0)){
      					if(cooltime3 >= ammo3 && this.getRemain_S() > 0){
      						this.counter3 = true;
      			            cooltime3 = 0;
      					}
      					if(this.weapon3true) {
      	    		    	this.weapon3activeMob(looked, entitylivingbase, 0);
      	    		    }
      				}
      			}
      		}else {
     			this.rotation_3  = this.rotationYawHead;
 				this.rotationp_3 = this.rotationPitch;
     		}
        }
    	if(this.getFTMode() != 1){
    		AI_AirCraftSet.setheli_NEW(this, GVCSoundEvent.sound_heli, f1, sp, 0.1F);
		}else {
			AI_AirCraftSet.setheligunner(this, GVCSoundEvent.sound_heli, f1, sp, 0.1F);
		}
		
    }

    /*public void updatePassenger(Entity passenger)
    {
        if (this.isPassenger(passenger))
        {
        	 int i = this.getPassengers().indexOf(passenger);
        	// if (i == 0)
        	 
             {
				double ix = 0;
				double iy = 0;
				double iz = 0;
				float rote = this.rotationYawHead;
				if (ridding_roteplayer) {
					rote = passenger.rotationYaw;
				}
				float f1 = rote * (2 * (float) Math.PI / 360);
				ix -= MathHelper.sin(f1) * riddingz[i];
				iz += MathHelper.cos(f1) * riddingz[i];
				ix -= MathHelper.sin(f1 - 1.57F) * riddingx[i];
				iz += MathHelper.cos(f1 - 1.57F) * riddingx[i];
				double ix2 = 0;
				double iz2 = 0;
				float f12 = passenger.rotationYaw * (2 * (float) Math.PI / 360);
				
				double b = 0;
				double b2 = 0;
				double a = 0;
				double ax = 0;
				double az = 0;
				//if(i != 0) 
				{
					b =  riddingz[i] * MathHelper.sin(this.rotationPitch  * (1 * (float) Math.PI / 180)) *  1.0D;
					//b2 =  Math.abs(riddingx[i]) * Math.tan(this.throte  * (2 * (float) Math.PI / 360)) *  1.0D;
					a =  riddingz[i] * Math.abs(Math.cos(this.rotationPitch  * (1 * (float) Math.PI / 180))) *  1.0D;
					//a =  riddingz[i] *  1.0D;
					ax -= MathHelper.sin(this.rotationYaw * (2 * (float) Math.PI / 360)) * a;
					az += MathHelper.cos(this.rotationYaw * (2 * (float) Math.PI / 360)) * a;
					ax -= MathHelper.sin(this.rotationYaw * (2 * (float) Math.PI / 360) - 1.57F) * riddingx[i];
					az += MathHelper.cos(this.rotationYaw * (2 * (float) Math.PI / 360) - 1.57F) * riddingx[i];
				}
				//System.out.println(String.format("%1$.2f", b));
				passenger.setPosition(
						this.posX + ax,
						this.posY + riddingy[i] + passenger.getYOffset() - b, 
						this.posZ + az);
             }
        }
    }*/
    
    protected void onDeathUpdate() {
		++this.deathTicks;
		int x = this.world.rand.nextInt(4);
		int y = this.world.rand.nextInt(5);
		int z = this.world.rand.nextInt(4);
		this.motionY *= 0.8D;
		//this.motionY -= 0.5D;
		float turnspeed = 10F;
        //if(!this.worldObj.isRemote)
        {
    	this.rotationYawHead = this.rotationYawHead + turnspeed;
	    this.rotationYaw = this.rotationYaw + turnspeed;
	    this.prevRotationYaw = this.prevRotationYaw + turnspeed;
	    this.prevRotationYawHead = this.prevRotationYawHead + turnspeed;
        }
		if (this.deathTicks == 1 && !this.world.isRemote) {
			this.world.createExplosion(this, this.posX, this.posY+2, this.posZ, 3.0F, false);
		}
		if ((this.deathTicks == 200 || this.onGround || this.collidedHorizontally) && !this.world.isRemote) {
			this.world.createExplosion(this, this.posX, this.posY+2, this.posZ, 3.0F, false);
			this.setDead();
		}
	}
}