package hmggirlfront.entity.drone;

import java.util.List;

import javax.annotation.Nullable;

import gvclib.entity.EntityB_Shell;
import gvclib.entity.living.EntityGVCLivingBase;
import gvclib.entity.living.ISoldier;
import gvclib.event.GVCSoundEvent;
import hmggirlfront.mod_GirlFront;
import hmggirlfront.entity.EntityDoll;
import hmggirlfront.entity.mob.EntityIBC01;
import hmggirlfront.entity.npc.EntityTraining_Drone;
import hmggirlfront.items.ItemDollCN;
import hmggirlfront.items.ItemSpawn_Drone;
import hmggirlfront.network.GFClientMessageKeyPressed;
import hmggirlfront.network.GFMessageKeyPressed;
import hmggirlfront.network.GFPacketHandler;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;

public class Drone_State {

	public static void load(EntityPlayer player,  EntityDrone drone) {
		ItemStack stack = drone.getHeldItemMainhand();
		if(!stack.isEmpty()) {
			if(stack.getItem() instanceof ItemSpawn_Drone){
				ItemSpawn_Drone drone_spawn = (ItemSpawn_Drone) stack.getItem();
				drone.w1name = drone_spawn.w1name;
				drone.reload_time1 = drone_spawn.reload_time1;
				//drone.reloadsoundset1 = 40;
				//drone.reloadsound1 = GVCSoundEvent.reload_shell;
			}
			if(stack.getItem() == mod_GirlFront.drone_command) {
				//command_load(player, drone);
			}
		}
		
		
		{
			NBTTagCompound nbt = player.getEntityData();
			NBTTagCompound nbtcn = drone.getEntityData();
			if(nbtcn != null) {
				int squadid = nbtcn.getInteger("squadid");
				int co = nbt.getInteger("dollcount");
				int co_cool = nbt.getInteger("dollcount_cool");
				int coun = 0;
				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)
							{
								boolean flag = false;
								if(rayTraceBlocks(player.world, new Vec3d(player.posX, player.posY, player.posZ), 
	                					new Vec3d(entity1.posX, entity1.posY + (double)entity1.getEyeHeight(), entity1.posZ), false, true, false) == null) 
	                			{
	                				flag = true;
	                			}
								if(!flag){
									doll.drone_inv = true;
									doll.drone_inv_count = 0;
								}
							}
						}
					}
				}
			}
		}
		
		command_load(player, drone);
	}
	
	public static void skill(EntityPlayer player,  EntityDrone drone) {
		ItemStack stack = drone.getHeldItemMainhand();
		if(!stack.isEmpty()) {
			if(drone.cooltime >= drone.ammo1  && drone.getRemain_L() > 0){
				
				if(stack.getItem() == mod_GirlFront.drone_command) {
					command_skill(player, drone);
				}
				if(stack.getItem() == mod_GirlFront.drone_mortar) {
					mortar_skill(player, drone);
				}
				if(stack.getItem() == mod_GirlFront.drone_airborne) {
					airborne_skill(player, drone);
				}
				if(stack.getItem() == mod_GirlFront.drone_bomber) {
					bomber_skill(player, drone);
				}
				if(stack.getItem() == mod_GirlFront.drone_decoy) {
					decoy_skill(player, drone);
				}
				drone.cooltime = 0;
				drone.setRemain_L(0);
			}
			
		}
	}
	
	public static void order(EntityPlayer player,  EntityDrone drone) {
		NBTTagCompound nbt = player.getEntityData();
		NBTTagCompound nbtcn = drone.getEntityData();
		if(nbtcn == null)return;
		int squadid = nbtcn.getInteger("squadid");
		int co = nbt.getInteger("dollcount");
		int co_cool = nbt.getInteger("dollcount_cool");
		
		
		
		
		if(co != 0){
			int cou = squadid;
			EntityDoll 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 EntityDoll && entity1 != null) {
						EntityDoll doll = (EntityDoll) entity1;
						if(doll.isOwner(player)  && doll.getSquadID() == squadid) 
						{
							if(co == cou) {
								dollbase = doll;
								break;
							}else {
								++cou;
							}
						}
					}
				}
			}
			if(dollbase != null) {
				if (co_cool >= 5) {
					GFPacketHandler.INSTANCE.sendToServer(new GFMessageKeyPressed(21, dollbase.getEntityId()));
					{
						if(dollbase.getMoveT() == 0) {
							if(player.world.isRemote)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.stay.name", new Object[0]));
						}
						else if(dollbase.getMoveT() == 1) {
							if(player.world.isRemote)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.follow.name", new Object[0]));
						}
						else if(dollbase.getMoveT() == 3) {
							if(player.world.isRemote)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.free.name", new Object[0]));
						}
						else if(dollbase.getMoveT() == 2) {
							if(player.world.isRemote)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.follow.name", new Object[0]));
						}
					}
					nbt.setInteger("dollcount_cool", 0);
				}
			}
		}else {
			int coun = 0;
			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) {
							if (co_cool >= 5) {
								GFPacketHandler.INSTANCE.sendToServer(new GFMessageKeyPressed(21, doll.getEntityId()));
								{
									if(doll.getMoveT() == 0) {
										if(player.world.isRemote && coun == 0)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.stay.name", new Object[0]));
									}
									else if(doll.getMoveT() == 1) {
										if(player.world.isRemote && coun == 0)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.follow.name", new Object[0]));
									}
									else if(doll.getMoveT() == 3) {
										if(player.world.isRemote && coun == 0)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.free.name", new Object[0]));
									}
									else if(doll.getMoveT() == 2) {
										if(player.world.isRemote && coun == 0)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.follow.name", new Object[0]));
									}
    							}
								nbt.setInteger("dollcount_cool", 0);
								++coun;
							}
						}
					}
				}
			}
		}
		
		
		
	}
	
	public static void squad(EntityPlayer player,  EntityDrone drone) {
		World worldIn = player.world;
		NBTTagCompound nbtcn = drone.getEntityData();
    	if(nbtcn != null){
    		{
        		{
        			int squadid = nbtcn.getInteger("squadid");
        			{
        				if(squadid < 4) {
            				++squadid;
            			}else {
            				squadid = 1;
            			}
        				nbtcn.setInteger("squadid", squadid);
            			
            			String id = "First";
            			if(squadid == 2)id = "Second";
            			if(squadid == 3)id = "Third";
            			if(squadid == 4)id = "Fourth";
            			if(worldIn.isRemote)
            				player.sendMessage(new TextComponentTranslation(id + "Squad!", new Object[0]));
        			}
        		}
    		}
    	}
	}
	
	public static void command_load(EntityPlayer player,  EntityDrone drone) {
		NBTTagCompound nbt = player.getEntityData();
		int count = 1;
		NBTTagCompound nbtcn = drone.getEntityData();
		if(nbtcn == null)return;
		int squadid = nbtcn.getInteger("squadid");
		if(squadid == 0){
			nbtcn.setInteger("squadid", 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) {
							++count;
						}
					}
				}
			}
		}
		int co = nbt.getInteger("dollcount");
		int co_cool = nbt.getInteger("dollcount_cool");
		if(player.world.isRemote) {
			if(co_cool <= 30){
				++co_cool;
				nbt.setInteger("dollcount_cool", co_cool);
			}
		}
		
		if (mod_GirlFront.proxy.left() && co > 0 && co_cool >= 5) {
			if(player.world.isRemote) {
				//nbt.setInteger("dollcount", co - 1);
			}else {
				//GFPacketHandler.INSTANCE.sendToServer(new GFMessageKeyPressed(20, co - 1, false));
			}
			nbt.setInteger("dollcount", co - 1);
			nbt.setInteger("dollcount_cool", 0);
		}
		if (mod_GirlFront.proxy.right() && co < count-1 && co_cool >= 5) {
			nbt.setInteger("dollcount", co + 1);
			nbt.setInteger("dollcount_cool", 0);
		}
	}
	
	public static void point_move(EntityPlayer player,  EntityDrone drone) {
		NBTTagCompound nbt = player.getEntityData();
		NBTTagCompound nbtcn = drone.getEntityData();
		if(nbtcn == null)return;
		int squadid = nbtcn.getInteger("squadid");
		int co = nbt.getInteger("dollcount");
		int co_cool = nbt.getInteger("dollcount_cool");
		
		
		
		
		if(co != 0){
			int cou = squadid;
			EntityDoll 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 EntityDoll && entity1 != null) {
						EntityDoll doll = (EntityDoll) entity1;
						if(doll.isOwner(player)  && doll.getSquadID() == squadid) 
						{
							if(co == cou) {
								dollbase = doll;
								break;
							}else {
								++cou;
							}
						}
					}
				}
			}
			if(dollbase != null) {
				/*if (mod_GirlFront.proxy.up() && co_cool >= 5) {
					GFPacketHandler.INSTANCE.sendToServer(new GFMessageKeyPressed(21, dollbase.getEntityId()));
					nbt.setInteger("dollcount_cool", 0);
				}*/
				//if (mod_GirlFront.proxy.down() && co_cool >= 5) 
				{
					GFPacketHandler.INSTANCE.sendToServer(new GFMessageKeyPressed(22, dollbase.getEntityId()));
					if(player.world.isRemote)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.pointattack.name", new Object[0]));
					nbt.setInteger("dollcount_cool", 0);
				}
			}
		}else {
			int coun = 0;
			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) {
							/*if (mod_GirlFront.proxy.up() && co_cool >= 5) {
								GFPacketHandler.INSTANCE.sendToServer(new GFMessageKeyPressed(21, doll.getEntityId()));
								nbt.setInteger("dollcount_cool", 0);
							}*/
							//if (mod_GirlFront.proxy.down() && co_cool >= 5) 
							{
								GFPacketHandler.INSTANCE.sendToServer(new GFMessageKeyPressed(22, doll.getEntityId()));
								if(player.world.isRemote && coun == 0)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.pointattack.name", new Object[0]));
								nbt.setInteger("dollcount_cool", 0);
								++coun;
							}
						}
					}
				}
			}
		}
	}
	
	
	public static void command_skill(EntityPlayer player,  EntityDrone drone) {
		{
			Vec3d lock = Vec3d.fromPitchYaw(player.rotationPitch, player.rotationYaw);
			int ix = 0;
			int iy = 0;
			int iz = 0;
			for(int x = 0; x < 120; ++x) {
				if (player.world
						.getBlockState(new BlockPos(player.posX + lock.x * x,
								player.posY + 1.5 + lock.y * x,
								player.posZ + lock.z * x))
						.getBlock() != Blocks.AIR) {
					ix = (int) (player.posX + lock.x * x);
					iy = (int) (player.posY + 1.5 + lock.y * x);
					iz = (int) (player.posZ + lock.z * x);
					player.world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, 
							player.posX +lock.x * x,  player.posY + 1.5 +lock.y * x, player.posZ +lock.z * x, 0, 0, 0);
					break;
				}
			}
			if(ix != 0 && iz != 0 && iy != 0) {
				EntityLivingBase target = null;
				{
					int han = 1;
	            	AxisAlignedBB axisalignedbb2 = (new AxisAlignedBB((double)(ix-han), (double)(iy-han), (double)(iz-han), 
	            			(double)(ix + han), (double)(iy + han), (double)(iz+ han)))
	                		.grow(3);
	                List llist2 = player.world.getEntitiesWithinAABBExcludingEntity(player, axisalignedbb2);
	                if(llist2!=null){
	                    for (int lj = 0; lj < llist2.size(); lj++) {
	                    	
	                    	Entity entity1 = (Entity)llist2.get(lj);
	                    	if (entity1.canBeCollidedWith())
	                        {
	                    		if (entity1 instanceof IMob && entity1 != null)
	                            {
	                    			EntityLivingBase mob = (EntityLivingBase) entity1;
	                    			mob.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 400, 200));
	                    			target = mob;
	                            }
	                        }
	                    }
	                }
				}
                if(target != null){
                	int han = 80;
                	double x = player.posX;
                	double y = player.posY;
                	double z = player.posZ;
                	AxisAlignedBB axisalignedbb2 = (new AxisAlignedBB((double)(x-han), (double)(y-han), (double)(z-han), 
	            			(double)(x + han), (double)(y + han), (double)(z+ han)))
	                		.grow(1);
	                List llist2 = player.world.getEntitiesWithinAABBExcludingEntity(player, axisalignedbb2);
	                if(llist2!=null){
	                    for (int lj = 0; lj < llist2.size(); lj++) {
	                    	
	                    	Entity entity1 = (Entity)llist2.get(lj);
	                    	if (entity1.canBeCollidedWith())
	                        {
	                    		if (entity1 instanceof ISoldier && entity1 != null)
	                            {
	                    			EntityGVCLivingBase mob = (EntityGVCLivingBase) entity1;
	                    			mob.targetentity = target;
	                    			mob.setMobMode(1);
	                    			mob.sneak = true;
	                    			mob.setattacktask(true);
	                    			{
	                    				mob.world.spawnParticle(EnumParticleTypes.NOTE, 
	                    						mob.posX,  mob.posY + mob.height + 1, mob.posZ, 0, 0, 0);
	                    			}
	                            }
	                        }
	                    }
	                }
                }
                
			}
    		
		}
	}
	
	public static void mortar_skill(EntityPlayer player,  EntityDrone drone) {
		{
			Vec3d lock = Vec3d.fromPitchYaw(player.rotationPitch, player.rotationYaw);
			int ix = 0;
			int iy = 0;
			int iz = 0;
			for(int x = 0; x < 120; ++x) {
				if (player.world
						.getBlockState(new BlockPos(drone.posX + lock.x * x,
								drone.posY + 1.5 + lock.y * x,
								drone.posZ + lock.z * x))
						.getBlock() != Blocks.AIR) {
					ix = (int) (drone.posX + lock.x * x);
					iy = (int) (drone.posY + 0 + lock.y * x);
					iz = (int) (drone.posZ + lock.z * x);
					player.world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, 
							drone.posX +lock.x * x,  drone.posY + 0 +lock.y * x, drone.posZ +lock.z * x, 0, 0, 0);
					break;
				}
			}
			if(ix != 0 && iz != 0 && iy != 0) {
				EntityB_Shell var8 = new EntityB_Shell(player.world, (EntityLivingBase) player);
		    	{
		    		var8.Bdamege = 100;
		    		var8.exlevel = 6.0F;
		    		var8.setModel("gvclib:textures/entity/model/bullet_cannon_small.mqo");
					var8.setTex("gvclib:textures/entity/model/bullet_cannon_small.png");
		    	}
				
		    	var8.spg_fly_sound = true;
				var8.gra = 0;
				var8.muteki = true;
				var8.friend = player;
				
				var8.bulletDameID = 0;
				var8.ex = false;
				
				float bbure = 1;
				var8.timemax = 8000;
				var8.setLocationAndAngles(ix, iy + 240, iz, 0,0);
				var8.setHeadingFromThrower(player, 90, player.rotationYaw, 0.0F, 2, 0);
				if (!player.world.isRemote) {
					player.world.spawnEntity(var8);
					for(int xx = 0; xx < 60; ++xx) {
						if(player.world.getBlockState(new BlockPos(ix, iy + 1 + xx, iz)).getBlock() == Blocks.AIR){
							player.world.setBlockState(new BlockPos(ix, iy + 1 + xx, iz), mod_GirlFront.bdoll_point.getDefaultState(), 2);
							
							break;
						}
					}
				}
				//if(player.world.isRemote)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.pointattack.name", new Object[0]));
			}
    		
		}
	}
	
	public static void airborne_skill(EntityPlayer player,  EntityDrone drone) {
		{
			Vec3d lock = Vec3d.fromPitchYaw(player.rotationPitch, player.rotationYaw);
			int ix = 0;
			int iy = 0;
			int iz = 0;
			for(int x = 0; x < 120; ++x) {
				if (player.world
						.getBlockState(new BlockPos(player.posX + lock.x * x,
								player.posY + 1.5 + lock.y * x,
								player.posZ + lock.z * x))
						.getBlock() != Blocks.AIR) {
					ix = (int) (player.posX + lock.x * x);
					iy = (int) (player.posY + 1.5 + lock.y * x);
					iz = (int) (player.posZ + lock.z * x);
					player.world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, 
							player.posX +lock.x * x,  player.posY + 1.5 +lock.y * x, player.posZ +lock.z * x, 0, 0, 0);
					break;
				}
			}
			if(ix != 0 && iz != 0 && iy != 0) {
				NBTTagCompound nbt = player.getEntityData();
				NBTTagCompound nbtcn = drone.getEntityData();
				if(nbtcn == null)return;
				int squadid = nbtcn.getInteger("squadid");
				{
					int coun = 0;
					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) {
									{
										//GFPacketHandler.INSTANCE.sendToServer(new GFMessageKeyPressed(22, doll.getEntityId()));
										int ranx = doll.world.rand.nextInt(6) - 3;
										int ranz = doll.world.rand.nextInt(6) - 3;
										doll.setPositionAndUpdate(ix + ranx, iy + 40, iz + ranz);
										doll.addPotionEffect(
												new PotionEffect(MobEffects.LEVITATION, 10, 10, false, false));
										if(FMLCommonHandler.instance().getMinecraftServerInstance() != null) {
											for (EntityPlayerMP player2 : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayers())
								            {
												GFPacketHandler.INSTANCE2.sendTo(new GFClientMessageKeyPressed(30, doll.getEntityId()), player2);
								            }
										}
										doll.setParachute(1);
										if (!player.world.isRemote) {
											for(int xx = 0; xx < 60; ++xx) {
												if(player.world.getBlockState(new BlockPos(ix, iy + 1 + xx, iz)).getBlock() == Blocks.AIR){
													player.world.setBlockState(new BlockPos(ix, iy + 1 + xx, iz), mod_GirlFront.bdoll_point.getDefaultState(), 2);
													
													break;
												}
											}
										}
										if(player.world.isRemote && coun == 0)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.pointattack.name", new Object[0]));
										++coun;
									}
								}
							}
						}
					}
				}
			}
    		
		}
	}
	
	
	public static void bomber_skill(EntityPlayer player,  EntityDrone drone) {
		for(int ii = 0; ii < 20; ++ii){
			Vec3d lock = Vec3d.fromPitchYaw(player.rotationPitch, player.rotationYaw);
			int ix = 0;
			int iy = 0;
			int iz = 0;
			for(int x = 0; x < 120; ++x) {
				if (player.world
						.getBlockState(new BlockPos(player.posX + lock.x * x,
								player.posY + 1.5 + lock.y * x,
								player.posZ + lock.z * x))
						.getBlock() != Blocks.AIR) {
					ix = (int) (player.posX + lock.x * x);
					iy = (int) (player.posY + 1.5 + lock.y * x);
					iz = (int) (player.posZ + lock.z * x);
					player.world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, 
							player.posX +lock.x * x,  player.posY + 1.5 +lock.y * x, player.posZ +lock.z * x, 0, 0, 0);
					break;
				}
			}
			if(ix != 0 && iz != 0 && iy != 0) {
				EntityB_Shell var8 = new EntityB_Shell(player.world, (EntityLivingBase) player);
		    	{
		    		var8.Bdamege = 5;
		    		var8.exlevel = 3.0F;
		    		var8.setModel("gvclib:textures/entity/model/bullet_cannon_small.mqo");
					var8.setTex("gvclib:textures/entity/model/bullet_cannon_small.png");
		    	}
				
		    	var8.spg_fly_sound = false;
				var8.gra = 0;
				var8.muteki = true;
				var8.friend = player;
				
				var8.bulletDameID = 0;
				var8.ex = false;
				
				float bbure = 1;
				var8.timemax = 8000;
				int rax = drone.world.rand.nextInt(30) - 15;
				int raz = drone.world.rand.nextInt(30) - 15;
				int ray = drone.world.rand.nextInt(30);
				var8.setLocationAndAngles(ix + rax, iy + 100 +(ii * 2), iz + raz, 0,0);
				var8.setHeadingFromThrower(player, 90, player.rotationYaw, 0.0F, 2, 0);
				if (!player.world.isRemote) {
					player.world.spawnEntity(var8);
					for(int xx = 0; xx < 60; ++xx) {
						if(player.world.getBlockState(new BlockPos(ix, iy + 1 + xx, iz)).getBlock() == Blocks.AIR){
							player.world.setBlockState(new BlockPos(ix, iy + 1 + xx, iz), mod_GirlFront.bdoll_point.getDefaultState(), 2);
							
							break;
						}
					}
				}
				//if(player.world.isRemote)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.pointattack.name", new Object[0]));
			}
    		
		}
	}
	
	public static void decoy_skill(EntityPlayer player,  EntityDrone drone) {
		{
			Vec3d lock = Vec3d.fromPitchYaw(player.rotationPitch, player.rotationYaw);
			int ix = 0;
			int iy = 0;
			int iz = 0;
			for(int x = 0; x < 120; ++x) {
				if (player.world
						.getBlockState(new BlockPos(player.posX + lock.x * x,
								player.posY + 1.5 + lock.y * x,
								player.posZ + lock.z * x))
						.getBlock() != Blocks.AIR) {
					ix = (int) (player.posX + lock.x * x);
					iy = (int) (player.posY + 1.5 + lock.y * x);
					iz = (int) (player.posZ + lock.z * x);
					player.world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, 
							player.posX +lock.x * x,  player.posY + 1.5 +lock.y * x, player.posZ +lock.z * x, 0, 0, 0);
					break;
				}
			}
			if(ix != 0 && iz != 0 && iy != 0) {
				EntityTraining_Drone ent = new EntityTraining_Drone(player.world);
				ent.setLocationAndAngles(ix + 0.5, iy + 1, iz + 0.5, 0, 0.0F);
				ent.setcanDespawn(1);
				if (!player.world.isRemote)player.world.spawnEntity(ent);
				//if(player.world.isRemote)player.sendMessage(new TextComponentTranslation("hmggirlfront.order.pointattack.name", new Object[0]));
			}
    		
		}
	}
	
	/**
     * Performs a raycast against all blocks in the world. Args : Vec1, Vec2, stopOnLiquid,
     * ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock
     */
    @Nullable
    public static RayTraceResult rayTraceBlocks(World world, Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock)
    {
        if (!Double.isNaN(vec31.x) && !Double.isNaN(vec31.y) && !Double.isNaN(vec31.z))
        {
            if (!Double.isNaN(vec32.x) && !Double.isNaN(vec32.y) && !Double.isNaN(vec32.z))
            {
                int i = MathHelper.floor(vec32.x);
                int j = MathHelper.floor(vec32.y);
                int k = MathHelper.floor(vec32.z);
                int l = MathHelper.floor(vec31.x);
                int i1 = MathHelper.floor(vec31.y);
                int j1 = MathHelper.floor(vec31.z);
                BlockPos blockpos = new BlockPos(l, i1, j1);
                IBlockState iblockstate = world.getBlockState(blockpos);
                Block block = iblockstate.getBlock();

                //if ((!ignoreBlockWithoutBoundingBox || iblockstate.getCollisionBoundingBox(this.world, blockpos) != Block.NULL_AABB) && block.canCollideCheck(iblockstate, stopOnLiquid))
                 if ((!ignoreBlockWithoutBoundingBox && block.canCollideCheck(iblockstate, stopOnLiquid)))
                {
                    RayTraceResult raytraceresult = iblockstate.collisionRayTrace(world, blockpos, vec31, vec32);

                    if (raytraceresult != null)
                    {
                        return raytraceresult;
                    }
                }

                RayTraceResult raytraceresult2 = null;
                int k1 = 200;

                while (k1-- >= 0)
                {
                    if (Double.isNaN(vec31.x) || Double.isNaN(vec31.y) || Double.isNaN(vec31.z))
                    {
                        return null;
                    }

                    if (l == i && i1 == j && j1 == k)
                    {
                        return returnLastUncollidableBlock ? raytraceresult2 : null;
                    }

                    boolean flag2 = true;
                    boolean flag = true;
                    boolean flag1 = true;
                    double d0 = 999.0D;
                    double d1 = 999.0D;
                    double d2 = 999.0D;

                    if (i > l)
                    {
                        d0 = (double)l + 1.0D;
                    }
                    else if (i < l)
                    {
                        d0 = (double)l + 0.0D;
                    }
                    else
                    {
                        flag2 = false;
                    }

                    if (j > i1)
                    {
                        d1 = (double)i1 + 1.0D;
                    }
                    else if (j < i1)
                    {
                        d1 = (double)i1 + 0.0D;
                    }
                    else
                    {
                        flag = false;
                    }

                    if (k > j1)
                    {
                        d2 = (double)j1 + 1.0D;
                    }
                    else if (k < j1)
                    {
                        d2 = (double)j1 + 0.0D;
                    }
                    else
                    {
                        flag1 = false;
                    }

                    double d3 = 999.0D;
                    double d4 = 999.0D;
                    double d5 = 999.0D;
                    double d6 = vec32.x - vec31.x;
                    double d7 = vec32.y - vec31.y;
                    double d8 = vec32.z - vec31.z;

                    if (flag2)
                    {
                        d3 = (d0 - vec31.x) / d6;
                    }

                    if (flag)
                    {
                        d4 = (d1 - vec31.y) / d7;
                    }

                    if (flag1)
                    {
                        d5 = (d2 - vec31.z) / d8;
                    }

                    if (d3 == -0.0D)
                    {
                        d3 = -1.0E-4D;
                    }

                    if (d4 == -0.0D)
                    {
                        d4 = -1.0E-4D;
                    }

                    if (d5 == -0.0D)
                    {
                        d5 = -1.0E-4D;
                    }

                    EnumFacing enumfacing;

                    if (d3 < d4 && d3 < d5)
                    {
                        enumfacing = i > l ? EnumFacing.WEST : EnumFacing.EAST;
                        vec31 = new Vec3d(d0, vec31.y + d7 * d3, vec31.z + d8 * d3);
                    }
                    else if (d4 < d5)
                    {
                        enumfacing = j > i1 ? EnumFacing.DOWN : EnumFacing.UP;
                        vec31 = new Vec3d(vec31.x + d6 * d4, d1, vec31.z + d8 * d4);
                    }
                    else
                    {
                        enumfacing = k > j1 ? EnumFacing.NORTH : EnumFacing.SOUTH;
                        vec31 = new Vec3d(vec31.x + d6 * d5, vec31.y + d7 * d5, d2);
                    }

                    l = MathHelper.floor(vec31.x) - (enumfacing == EnumFacing.EAST ? 1 : 0);
                    i1 = MathHelper.floor(vec31.y) - (enumfacing == EnumFacing.UP ? 1 : 0);
                    j1 = MathHelper.floor(vec31.z) - (enumfacing == EnumFacing.SOUTH ? 1 : 0);
                    blockpos = new BlockPos(l, i1, j1);
                    IBlockState iblockstate1 = world.getBlockState(blockpos);
                    Block block1 = iblockstate1.getBlock();

                    if (!ignoreBlockWithoutBoundingBox || iblockstate1.getMaterial() == Material.PORTAL || iblockstate1.getCollisionBoundingBox(world, blockpos) != Block.NULL_AABB)
                  //  if (!ignoreBlockWithoutBoundingBox || iblockstate1.getMaterial() == Material.PORTAL)
                    {
                        if (block1.canCollideCheck(iblockstate1, stopOnLiquid))
                        {
                            RayTraceResult raytraceresult1 = iblockstate1.collisionRayTrace(world, blockpos, vec31, vec32);

                            if (raytraceresult1 != null)
                            {
                                return raytraceresult1;
                            }
                        }
                        else
                        {
                            raytraceresult2 = new RayTraceResult(RayTraceResult.Type.MISS, vec31, enumfacing, blockpos);
                        }
                    }
                }

                return returnLastUncollidableBlock ? raytraceresult2 : null;
            }
            else
            {
                return null;
            }
        }
        else
        {
            return null;
        }
    }
}
