package hmggirlfront.block.tile;
 
import java.util.List;

import javax.annotation.Nullable;

import hmggirlfront.mod_GirlFront;
import hmggirlfront.entity.EntityKalina;
import hmggirlfront.entity.mob.EntityIBC01;
import hmggirlfront.entity.mob.EntityIBC01Turret;
import hmggirlfront.entity.mob.EntityIBC02;
import hmggirlfront.entity.mob.EntityIBC03;
import hmggirlfront.entity.mob.EntityIBC04;
import hmggirlfront.entity.mob.EntityIBC05;
import hmggirlfront.entity.mob.EntityIBC06;
import hmggirlfront.entity.mob.EntityIBC07;
import hmggirlfront.entity.mob.EntityIBC08;
import hmggirlfront.entity.mob.EntityIBC09;
import hmggirlfront.entity.mob.EntityIBC10Turret;
import hmggirlfront.entity.mob.EntityIBC10u;
import hmggirlfront.entity.mob.EntityIBC11;
import hmggirlfront.entity.mob.EntityIBC12;
import hmggirlfront.entity.mob.EntityIBC13;
import hmggirlfront.entity.mob.EntityIBC14;
import hmggirlfront.entity.mob.EntityIBCGENE;
import hmggirlfront.entity.mob.EntityIBCJUPITER;
import hmggirlfront.entity.mob.EntityIBCML;
import hmggirlfront.entity.mob.EntitySCM_AEGIS;
import hmggirlfront.entity.mob.EntitySCM_CERYNITIS;
import hmggirlfront.entity.mob.EntitySCM_CYCLOPS;
import hmggirlfront.entity.mob.EntitySCM_HYDRA;
import hmggirlfront.entity.npc.EntityNPC_Doll;
import hmggirlfront.items.ItemDollGunBase;
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.SharedMonsterAttributes;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
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.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
 
public class TileEntity_Spawn_ONE extends TileEntity implements ITickable
{
	public boolean spawn = false;
    
	@SideOnly(Side.CLIENT)
    public double getMaxRenderDistanceSquared()
    {
        return 65536.0D;
    }
	
    @Override
	public void update() {
    	Block block = this.world.getBlockState(this.pos).getBlock();
        
        int x = this.pos.getX();
        int y= this.pos.getY();
        int z = this.pos.getZ();
        
        if(this.world.getBlockState(new BlockPos(x, y + 1, z)).getBlock() == Blocks.IRON_BLOCK) {
        	this.canspawn(x, y, z, 80, false);
        }
        if(this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.b_npc_isomer) {
        	this.canspawn(x, y, z, 80, false);
        }
        else  if(this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.bdoll_ibc_boss01) {
        	this.canspawn(x, y, z, 5, true);
        }
        else  if(this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.bdoll_ibc_boss02) {
        	this.canspawn(x, y, z, 5, true);
        }
        else  if(this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.bdoll_ibc_boss05) {
        	this.canspawn(x, y, z, 5, true);
        }
        else  if(this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.bdoll_ibc01turret
        		|| this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.bdoll_ibc10turret
        		|| this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.bdoll_ibcml
        		|| this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.bdoll_ibc_jupiter
        		|| this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.bdoll_ibc_generator) {
        	this.canspawn(x, y, z, 80, false);
        }
        else  if(this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.story_mission_1_npc
        		|| this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == mod_GirlFront.story_mission_2_npc) {
        	this.canspawn(x, y, z, 50, true);
        }
        else 
        {
        	this.canspawn(x, y, z, 60, true);
        }
        
        
        if(spawn && !this.world.isRemote){
        	if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc01) {
        		//for(int ii = 0; ii < 40; ++ii) 
        		{
        			EntityIBC01 entityskeleton = new EntityIBC01(this.world);
    	        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
    	        	entityskeleton.setcanDespawn(1);
    		        this.world.spawnEntity(entityskeleton);
        		}
				
	        }
        	if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc02) {
				EntityIBC02 entityskeleton = new EntityIBC02(this.world);
	        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
	        	entityskeleton.setcanDespawn(1);
		        this.world.spawnEntity(entityskeleton);
	        }
        	if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc03) {
				EntityIBC03 entityskeleton = new EntityIBC03(this.world);
	        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
	        	entityskeleton.setcanDespawn(1);
		        this.world.spawnEntity(entityskeleton);
	        }
        	if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc04) {
				EntityIBC04 entityskeleton = new EntityIBC04(this.world);
				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_ibc04smg));
				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(mod_GirlFront.dollgun_ibc04smg));
	        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
	        	entityskeleton.setcanDespawn(1);
		        this.world.spawnEntity(entityskeleton);
	        }
        	if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc05) {
				EntityIBC05 entityskeleton = new EntityIBC05(this.world);
				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_ibc05ar));
	        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
	        	entityskeleton.setcanDespawn(1);
		        this.world.spawnEntity(entityskeleton);
	        }
        	if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc06) {
				EntityIBC06 entityskeleton = new EntityIBC06(this.world);
				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_ibc06rf));
	        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
	        	entityskeleton.setcanDespawn(1);
		        this.world.spawnEntity(entityskeleton);
	        }
        	if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc07) {
				EntityIBC07 entityskeleton = new EntityIBC07(this.world);
				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_ibc07hg));
				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(mod_GirlFront.dollgun_ibc07sd));
	        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
	        	entityskeleton.setcanDespawn(1);
		        this.world.spawnEntity(entityskeleton);
	        }
        	
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc08) {
					EntityIBC08 entityskeleton = new EntityIBC08(this.world);
					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_ibc08sw));
					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(mod_GirlFront.dollgun_ibc08sd));
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc09) {
        			EntityIBC09 entityskeleton = new EntityIBC09(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc01turret) {
        			EntityIBC01Turret entityskeleton = new EntityIBC01Turret(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc10turret) {
        			EntityIBC10Turret entityskeleton = new EntityIBC10Turret(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc11) {
					EntityIBC11 entityskeleton = new EntityIBC11(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc12) {
					EntityIBC12 entityskeleton = new EntityIBC12(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc13) {
					EntityIBC13 entityskeleton = new EntityIBC13(this.world);
					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_ibc13glg));
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc14) {
					EntityIBC14 entityskeleton = new EntityIBC14(this.world);
					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_ibc14sw));
					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(mod_GirlFront.dollgun_ibc14sw));
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibcml) {
        			EntityIBCML entityskeleton = new EntityIBCML(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+0, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc_jupiter) {
        			EntityIBCJUPITER entityskeleton = new EntityIBCJUPITER(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+0, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc_generator) {
        			EntityIBCGENE entityskeleton = new EntityIBCGENE(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+0, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bsocom_cyclops) {
        			EntitySCM_CYCLOPS entityskeleton = new EntitySCM_CYCLOPS(this.world);
        			entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.subarm_ak12prt));
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bsocom_aegis) {
        			EntitySCM_AEGIS entityskeleton = new EntitySCM_AEGIS(this.world);
        			entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_ibc08sw));
					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(mod_GirlFront.dollgun_ibc08sd));
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bsocom_cerynitis) {
        			EntitySCM_CERYNITIS entityskeleton = new EntitySCM_CERYNITIS(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bsocom_hydra) {
        			EntitySCM_HYDRA entityskeleton = new EntitySCM_HYDRA(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		
        		
        		
        		
        		
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.b_npc_isomer) {
        			EntityKalina entityskeleton = new EntityKalina(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+0, z + 0.5, 0, 0.0F);
		        	entityskeleton.setcanDespawn(1);
		        	entityskeleton.setArmID_A(3);
			        this.world.spawnEntity(entityskeleton);
		        }
        		/*if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc_boss01) {
        			EntityIBCBoss01 entityskeleton = new EntityIBCBoss01(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setMoveT(1);
					entityskeleton.setMoveX(x);
					entityskeleton.setMoveY(y);
					entityskeleton.setMoveZ(z);
					entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc_boss02) {
        			EntityIBCBoss02 entityskeleton = new EntityIBCBoss02(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_ibcboss02sw));
		        	entityskeleton.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(mod_GirlFront.dollgun_ibcboss02hg));
		        	entityskeleton.setMoveT(1);
					entityskeleton.setMoveX(x);
					entityskeleton.setMoveY(y);
					entityskeleton.setMoveZ(z);
					entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.bdoll_ibc_boss05) {
        			EntityIBCBoss05 entityskeleton = new EntityIBCBoss05(this.world);
		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
		        	entityskeleton.setMoveT(1);
					entityskeleton.setMoveX(x);
					entityskeleton.setMoveY(y);
					entityskeleton.setMoveZ(z);
					entityskeleton.setcanDespawn(1);
			        this.world.spawnEntity(entityskeleton);
		        }*/
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.story_mission_1_npc) {
        			{
        				EntityNPC_Doll entityskeleton = new EntityNPC_Doll(this.world);
            			BlockPos bp = this.world.getHeight(new BlockPos(x, y, z));
        				y = bp.getY(); 
        				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_m1014));
    		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
    		        	entityskeleton.setcanDespawn(1);
    		        	entityskeleton.setMoveX(x);
    					entityskeleton.setMoveY(y);
    					entityskeleton.setMoveZ(z);
    					entityskeleton.setFTMode(1);
    					entityskeleton.setSquadID(1);
    					entityskeleton.setArmID_L(3);
    					entityskeleton.setMissonID(1);
    					ItemDollGunBase gun = (ItemDollGunBase) mod_GirlFront.dollgun_m1014;
    					entityskeleton.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20D + 1 + gun.doll_hp);
    					entityskeleton.setHealth((float) (20D + 3 + gun.doll_hp));
    			        this.world.spawnEntity(entityskeleton);
        			}
        			{
        				EntityNPC_Doll entityskeleton = new EntityNPC_Doll(this.world);
            			BlockPos bp = this.world.getHeight(new BlockPos(x, y, z));
        				y = bp.getY(); 
    					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_m10));
    		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
    		        	entityskeleton.setcanDespawn(1);
    		        	entityskeleton.setMoveX(x);
    					entityskeleton.setMoveY(y);
    					entityskeleton.setMoveZ(z);
    					entityskeleton.setFTMode(0);
    					entityskeleton.setSquadID(1);
    					entityskeleton.setArmID_L(3);
    					entityskeleton.setMissonID(1);
    					ItemDollGunBase gun = (ItemDollGunBase) mod_GirlFront.dollgun_m10;
    					entityskeleton.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20D + 1 + gun.doll_hp);
    					entityskeleton.setHealth((float) (20D + 3 + gun.doll_hp));
    			        this.world.spawnEntity(entityskeleton);
        			}
        			{
        				EntityNPC_Doll entityskeleton = new EntityNPC_Doll(this.world);
            			BlockPos bp = this.world.getHeight(new BlockPos(x, y, z));
        				y = bp.getY(); 
        				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_m1911));
    					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(mod_GirlFront.dollgun_m1911));
    		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
    		        	entityskeleton.setcanDespawn(1);
    		        	entityskeleton.setMoveX(x);
    					entityskeleton.setMoveY(y);
    					entityskeleton.setMoveZ(z);
    					entityskeleton.setFTMode(0);
    					entityskeleton.setSquadID(1);
    					entityskeleton.setArmID_L(3);
    					entityskeleton.setMissonID(1);
    					ItemDollGunBase gun = (ItemDollGunBase) mod_GirlFront.dollgun_m1911;
    					entityskeleton.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20D + 1 + gun.doll_hp);
    					entityskeleton.setHealth((float) (20D + 3 + gun.doll_hp));
    			        this.world.spawnEntity(entityskeleton);
        			}
        			
		        }
        		
        		if(this.world.getBlockState(this.pos).getBlock() == mod_GirlFront.story_mission_2_npc) {
        			{
        				EntityIBC10u entityskeleton = new EntityIBC10u(this.world);
            			BlockPos bp = this.world.getHeight(new BlockPos(x, y, z));
        				y = bp.getY(); 
    		        	entityskeleton.setLocationAndAngles(x + 0.5 + 60, y+1, z + 0.5 + 60, 0, 0.0F);
    		        	entityskeleton.setcanDespawn(1);
    		        	entityskeleton.setMoveX(x + 60);
    					entityskeleton.setMoveY(y);
    					entityskeleton.setMoveZ(z + 60);
    					entityskeleton.setArmID_A(1);
    			        this.world.spawnEntity(entityskeleton);
        			}
        			/*{
        				EntityIBC10u entityskeleton = new EntityIBC10u(this.world);
            			BlockPos bp = this.world.getHeight(new BlockPos(x, y, z));
        				y = bp.getY(); 
        				entityskeleton.setLocationAndAngles(x + 0.5 + 70, y+1, z + 0.5 + 60, 0, 0.0F);
    		        	entityskeleton.setcanDespawn(1);
    		        	entityskeleton.setMoveX(x);
    					entityskeleton.setMoveY(y);
    					entityskeleton.setMoveZ(z);
    					entityskeleton.setArmID_A(0);
    			        this.world.spawnEntity(entityskeleton);
        			}
        			{
        				EntityIBC10u entityskeleton = new EntityIBC10u(this.world);
            			BlockPos bp = this.world.getHeight(new BlockPos(x, y, z));
        				y = bp.getY(); 
        				entityskeleton.setLocationAndAngles(x + 0.5 + 70, y+1, z + 0.5 + 60, 0, 0.0F);
    		        	entityskeleton.setcanDespawn(1);
    		        	entityskeleton.setMoveX(x);
    					entityskeleton.setMoveY(y);
    					entityskeleton.setMoveZ(z);
    					entityskeleton.setArmID_A(0);
    			        this.world.spawnEntity(entityskeleton);
        			}*/
        			
        			{
        				EntityNPC_Doll entityskeleton = new EntityNPC_Doll(this.world);
            			BlockPos bp = this.world.getHeight(new BlockPos(x, y, z));
        				y = bp.getY(); 
        				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_m1014));
    		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
    		        	entityskeleton.setcanDespawn(1);
    		        	entityskeleton.setMoveX(x);
    					entityskeleton.setMoveY(y);
    					entityskeleton.setMoveZ(z);
    					entityskeleton.setFTMode(1);
    					entityskeleton.setSquadID(1);
    					entityskeleton.setArmID_L(3);
    					entityskeleton.setMissonID(2);
    					ItemDollGunBase gun = (ItemDollGunBase) mod_GirlFront.dollgun_m1014;
    					entityskeleton.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20D + 1 + gun.doll_hp);
    					entityskeleton.setHealth((float) (20D + 3 + gun.doll_hp));
    			        this.world.spawnEntity(entityskeleton);
        			}
        			{
        				EntityNPC_Doll entityskeleton = new EntityNPC_Doll(this.world);
            			BlockPos bp = this.world.getHeight(new BlockPos(x, y, z));
        				y = bp.getY(); 
    					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_m10));
    		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
    		        	entityskeleton.setcanDespawn(1);
    		        	entityskeleton.setMoveX(x);
    					entityskeleton.setMoveY(y);
    					entityskeleton.setMoveZ(z);
    					entityskeleton.setFTMode(0);
    					entityskeleton.setSquadID(1);
    					entityskeleton.setArmID_L(3);
    					entityskeleton.setMissonID(2);
    					ItemDollGunBase gun = (ItemDollGunBase) mod_GirlFront.dollgun_m10;
    					entityskeleton.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20D + 1 + gun.doll_hp);
    					entityskeleton.setHealth((float) (20D + 3 + gun.doll_hp));
    			        this.world.spawnEntity(entityskeleton);
        			}
        			{
        				EntityNPC_Doll entityskeleton = new EntityNPC_Doll(this.world);
            			BlockPos bp = this.world.getHeight(new BlockPos(x, y, z));
        				y = bp.getY(); 
        				entityskeleton.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(mod_GirlFront.dollgun_m1911));
    					entityskeleton.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(mod_GirlFront.dollgun_m1911));
    		        	entityskeleton.setLocationAndAngles(x + 0.5, y+1, z + 0.5, 0, 0.0F);
    		        	entityskeleton.setcanDespawn(1);
    		        	entityskeleton.setMoveX(x);
    					entityskeleton.setMoveY(y);
    					entityskeleton.setMoveZ(z);
    					entityskeleton.setFTMode(0);
    					entityskeleton.setSquadID(1);
    					entityskeleton.setArmID_L(3);
    					entityskeleton.setMissonID(2);
    					ItemDollGunBase gun = (ItemDollGunBase) mod_GirlFront.dollgun_m1911;
    					entityskeleton.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20D + 1 + gun.doll_hp);
    					entityskeleton.setHealth((float) (20D + 3 + gun.doll_hp));
    			        this.world.spawnEntity(entityskeleton);
        			}
        			
		        }
            if(!this.world.isRemote){
            	this.world.setBlockToAir(this.pos);
            }
        }
	}
	
	public void canspawn(double x, double y, double z, int han, boolean cansee) {
		Entity entity = null;
		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 = this.world.getEntitiesWithinAABBExcludingEntity(entity, axisalignedbb2);
		if (llist2 != null) {
			for (int lj = 0; lj < llist2.size(); lj++) {

				Entity entity1 = (Entity) llist2.get(lj);
				if (entity1.canBeCollidedWith()) {
					if (entity1 instanceof EntityPlayer && entity1 != null) {
						EntityPlayer ss = (EntityPlayer) entity1;
						ItemStack itemstack = ss.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
						if (!itemstack.isEmpty() && itemstack.getItem() == Items.GOLDEN_HELMET) {
						} else {
							double d5 = entity1.posX - this.pos.getX();
							double d6 = entity1.posY - this.pos.getY();
							double d7 = entity1.posZ - this.pos.getZ();
							double ddx = Math.abs(d5);
							double ddy = Math.abs(d6);
							double ddz = Math.abs(d7);
							if(!cansee) {
								spawn = true;
								break;
							}
							else if ((ddx < 10 && ddz < 10)) {
								if(ddy < 4) {
									spawn = true;
									break;
								}
							}
							/*if (rayTraceBlocks(
									new Vec3d(this.pos.getX() + 0.1, this.pos.getY() + 0.85, this.pos.getZ() + 0.1),
									new Vec3d(entity1.posX, entity1.posY + (double) entity1.getEyeHeight(),
											entity1.posZ),
									false, true, false) == null) {
								spawn = true;
								break;
							}*/
							if(rayTraceBlocks(new Vec3d(this.pos.getX() + 0.1, this.pos.getY() + 0.85, this.pos.getZ() + 0.1), 
                					new Vec3d(entity1.posX, entity1.posY + (double)entity1.getEyeHeight(), entity1.posZ), false, true, false) == null) 
                			{
                				spawn = true;
                			}
                			if(rayTraceBlocks(new Vec3d(this.pos.getX() + 0.1, this.pos.getY() + 1.85, this.pos.getZ() + 0.1), 
                					new Vec3d(entity1.posX, entity1.posY + (double)entity1.getEyeHeight(), entity1.posZ), false, true, false) == null) 
                			{
                				spawn = true;
                			}
						}
					}
				}
			}
		}
    }
    
    
    /**
     * Performs a raycast against all blocks in the world. Args : Vec1, Vec2, stopOnLiquid,
     * ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock
     */
    @Nullable
    public RayTraceResult rayTraceBlocks(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 = this.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(this.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 = this.world.getBlockState(blockpos);
                    Block block1 = iblockstate1.getBlock();

                    if (!ignoreBlockWithoutBoundingBox || iblockstate1.getMaterial() == Material.PORTAL || iblockstate1.getCollisionBoundingBox(this.world, blockpos) != Block.NULL_AABB)
                  //  if (!ignoreBlockWithoutBoundingBox || iblockstate1.getMaterial() == Material.PORTAL)
                    {
                        if (block1.canCollideCheck(iblockstate1, stopOnLiquid))
                        {
                            RayTraceResult raytraceresult1 = iblockstate1.collisionRayTrace(this.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;
        }
    }
}