package common.entity.projectile;

import common.entity.DamageSource;
import common.entity.types.EntityLiving;
import common.init.Blocks;
import common.init.Config;
import common.util.BlockPos;
import common.util.HitPosition;
import common.world.World;

public class EntityFireCharge extends EntityProjectile
{
    public EntityFireCharge(World worldIn)
    {
        super(worldIn);
        this.setSize(0.3125F, 0.3125F);
    }

    public EntityFireCharge(World worldIn, EntityLiving shooter, double accelX, double accelY, double accelZ)
    {
        super(worldIn, shooter, accelX, accelY, accelZ, 0.35f, 1.0f);
        this.setSize(0.3125F, 0.3125F);
    }

    public EntityFireCharge(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
        this.setSize(0.3125F, 0.3125F);
    }

    public EntityFireCharge(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
    {
        this(worldIn, x, y, z);
        this.setAcceleration(accelX, accelY, accelZ);
    }

    /**
     * Called when this EntityFireball hits a block or entity.
     */
    protected void onImpact(HitPosition movingObject)
    {
        if (!this.worldObj.client)
        {
            if (movingObject.entity != null)
            {
                boolean flag = Config.damageFireball && 
                		movingObject.entity.attackEntityFrom(DamageSource.causeFireballDamage(this, this.shootingEntity), 6);

                if (flag)
                {
                    this.applyEnchantments(this.shootingEntity, movingObject.entity);

//                    if (!movingObject.entityHit.isImmuneToFire())
//                    {
                        movingObject.entity.setOnFireFromObject(5);
//                    }
                }
            }
            else
            {
                boolean flag1 = true;

                if (this.shootingEntity != null && this.shootingEntity instanceof EntityLiving) //  && !(this.shootingEntity.isPlayer()))
                {
                    flag1 = Config.mobGrief;
                }

                if (flag1)
                {
                    BlockPos blockpos = movingObject.block.offset(movingObject.side);

                    if (this.worldObj.isAirBlock(blockpos))
                    {
                        this.worldObj.setState(blockpos, Blocks.fire.getState());
                    }
                }
            }

            this.setDead();
        }
    }

    /**
     * Returns true if other Entities should be prevented from moving through this Entity.
     */
    public boolean canBeCollidedWith()
    {
        return false;
    }

    /**
     * Called when the entity is attacked.
     */
    public boolean attackEntityFrom(DamageSource source, int amount)
    {
        return false;
    }
}
