package hmggirlfront.entity.mob;

import java.util.List;

import javax.annotation.Nullable;

import gvclib.entity.living.AI_Damage;
import gvclib.entity.living.AI_EntityWeapon;
import gvclib.entity.living.AI_EntityWeapon_new;
import gvclib.event.GVCSoundEvent;
import gvclib.world.GVCExplosionBase;
import hmggirlfront.GFSoundEvent;
import hmggirlfront.mod_GirlFront;
import hmggirlfront.entity.mob.ai.IBCAI_EntityMoveS;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIFleeSun;
import net.minecraft.entity.ai.EntityAIRestrictSun;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;

public class EntityIBCGENE extends EntityIBCBase {

	public EntityIBCGENE(World worldIn) {
		super(worldIn);
		this.setSize(2.5F, 2.0F);
		this.rotationp_max = -90;
		this.rotationp_min = 0;
	}

	protected void initEntityAI() {
	}

	protected void applyEntityAttributes() {
		super.applyEntityAttributes();
		this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(20D);
		this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(20D);
		this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.25D);
		this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(100.0D);
	}

	public boolean getCanSpawnHere() {
		return this.getLevel() >= 0 && super.getCanSpawnHere();
	}
	
	protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) {
		super.setEquipmentBasedOnDifficulty(difficulty);
		
	}
	@Nullable
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata)
    {
        livingdata = super.onInitialSpawn(difficulty, livingdata);
        return livingdata;
    }
	/**
     * Drop the equipment for this entity.
     */
    protected void dropEquipment(boolean wasRecentlyHit, int lootingModifier)
    {
    	DamageSource source = this.getLastDamageSource();
    	int dame = 0;
    	if(source == null || source.getTrueSource() == null) {
    		dame = 1;
    	}else {
    		dame = 0;
    	}
    	if(dame == 1)return;
    	
    }
    
    @Override
    public boolean isEntityInsideOpaqueBlock()
    {
    	return false;
    }
    
    public SoundEvent  DamegeSound = SoundEvents.BLOCK_ANVIL_LAND;
	/*public boolean attackEntityFrom(DamageSource source, float par2)
    {
    	Entity entity;
    	entity = source.getImmediateSource();
    	Entity entity2 = source.getTrueSource();
    	
		if(entity != null && entity2 != null){
			if(entity2 instanceof IMob){
	    		return false;
	        }
			else
	        {
				double d5 = entity2.posX - this.posX;
				double d7 = entity2.posZ - this.posZ;
				double ddx = Math.abs(d5);
				double ddz = Math.abs(d7);
				if ((ddx > 60 || ddz > 60)) {
					par2 = par2 * 0.25F;
				}else if ((ddx > 40 || ddz > 40)) {
					par2 = par2 * 0.5F;
				}
				par2 = par2 * AI_Damage.newAntiBullet(this, entity, par2, 1.0F, 1.0F, 1.0F, 1.0F);
				if(par2 <= 1.0) {
					par2 = 0;
					this.playSound(DamegeSound, 1F, 1F);
					return false;
				}else {
					return super.attackEntityFrom(source, par2);
				}
			}
		}else{
			return super.attackEntityFrom(source, par2);
		}
    }*/
    
	public boolean processInteract(EntityPlayer player, EnumHand hand)
    {
		this.attackEntityFrom(DamageSource.causeMobDamage(player), 200);
		return true;
    }
	
    
    protected void onDeathUpdate() {
    	super.onDeathUpdate();
		if (this.deathTime == 1 && !this.world.isRemote) {
			GVCExplosionBase.ExplosionKai(this, this, this.posX + 0, this.posY + 0, this.posZ + 0, 1, false,  false);
		}
	}
    
	/**
	 * Called frequently so the entity can update its state every tick as
	 * required. For example, zombies and skeletons use this to react to
	 * sunlight and start to burn.
	 */
    int self_ex = 0;
	public void onLivingUpdate() {
		super.onLivingUpdate();
		this.biped = false;
		
		this.rotationYaw = 0;
		this.renderYawOffset = 0;
		
		if(this.getMoveT() == 0) {
			this.setMoveT(1);
			this.setMoveX((int)this.posX);
			this.setMoveY((int)this.posY);
			this.setMoveZ((int)this.posZ);
		}
		if(this.getMoveT() == 1)this.setPosition(this.getMoveX(), this.getMoveY(), this.getMoveZ());
		
		if(getJUPITER(this) != null){
			double x1 = 0;
			double z1 = 0;
			float ff = this.rotationYawHead * 0.01745329252F;
			
			x1 -= MathHelper.sin(ff -0) * 1;
			z1 += MathHelper.cos(ff -0) * 1;
			this.world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, this.posX + 0 + x1, this.posY + 2.3, this.posZ + 0 + z1, 0.0D, 0.0D, 0.0D, new int[0]);
		}
		
		getJUPITER(this);
	}
	
	public static Entity getJUPITER(EntityIBCGENE entity) {
		Entity flag = null;
		int kazu = 0;
		double k = entity.posX;
		double l = entity.posY;
		double i = entity.posZ;
		int han = 15;
		int bit = 0;
		AxisAlignedBB axisalignedbb = (new AxisAlignedBB((double) (k - han), (double) (l - han),
				(double) (i - han), (double) (k + han), (double) (l + han), (double) (i + han)))
						.grow(1);
		List<Entity> llist = entity.world.getEntitiesWithinAABBExcludingEntity(entity, axisalignedbb);
		if (llist != null) {
			for (int lj = 0; lj < llist.size(); lj++) {
				Entity entity1 = (Entity) llist.get(lj);
				if (entity1.canBeCollidedWith()) {
					if (entity1 instanceof EntityIBCJUPITER && entity1 != null) {
						flag = entity1;
						break;
					}
				}
			}
		}
		return flag;
	}
}