package hmggirlfront.entity.bullet;

import java.util.List;

import gvclib.entity.EntityBBase;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.MoverType;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

public class EntityBullet_Blade extends EntityBBase {
	public EntityBullet_Blade(World worldIn) {
		super(worldIn);
	}

	public EntityBullet_Blade(World worldIn, EntityLivingBase throwerIn) {
		super(worldIn, throwerIn);
	}

	public EntityBullet_Blade(World worldIn, double x, double y, double z) {
		super(worldIn, x, y, z);
	}

	public static void func_189662_a(DataFixer p_189662_0_) {
		EntityBBase.func_189661_a(p_189662_0_, "Snowball");
	}

	public void onUpdate()
    {
		if (!this.world.isRemote)
        {
            this.setFlag(6, this.isGlowing());
        }

        this.onEntityUpdate();
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
        
        if (!this.hasNoGravity())
        {
            this.motionY -= 0.03999999910593033D - this.gra;
        }

        this.move(MoverType.SELF,this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.9800000190734863D;
        //this.motionY *= 0.9800000190734863D;
        this.motionZ *= 0.9800000190734863D;

        if (this.onGround)
        {
            //this.motionX *= 0.699999988079071D;
            //this.motionZ *= 0.699999988079071D;
            this.motionY *= -0.5D;
        }

        ++time;
        {
        	if(time > timemax){
        		if(!this.world.isRemote){
        			this.setDead();
                }
        	}else
        		if(!this.world.isRemote){
                	this.explode();
                }
        }
        {
            {
                this.handleWaterMovement();
                this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }
    }
	
	public void setDead(){
		this.world.spawnParticle(EnumParticleTypes.SNOWBALL, this.posX, this.posY + 0D, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
		super.setDead();
	}
	
	private void explode()
    {
        //this.world.createExplosion(this, this.posX, this.posY + (double)(this.height / 16.0F), this.posZ, exlevel, ex);
		if (this.getThrower() != null) {
			{
				//GVCExplosionBase.ExplosionKai(this.getThrower(), this, this.posX + 0, this.posY + 0, this.posZ + 0,this.exlevel, this.exfire, this.ex);
				{
					List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this,
							this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ)
									.grow(exlevel));
					for (int i = 0; i < list.size(); ++i) {
						Entity entity1 = (Entity) list.get(i);
						if (entity1.canBeCollidedWith()) {
							if (entity1 instanceof EntityLivingBase && entity1 != this.getThrower()) {
								EntityLivingBase en = (EntityLivingBase) entity1;
								en.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)this.Bdamege);
							}
						}
					}
				}
			}
		}
    }
	
	/**
	 * Called when this EntityThrowable hits a block or entity.
	 */
	protected void onImpact(RayTraceResult result) {
	}
	
	protected void onBreak(RayTraceResult result) {
	}

	@Override
	public void shoot(double x, double y, double z, float velocity, float inaccuracy) {
		// TODO 自動生成されたメソッド・スタブ
		
	}
}