package common.entity.projectile;

import common.entity.DamageSource;
import common.entity.types.EntityLiving;
import common.init.Config;
import common.nbt.NBTTagCompound;
import common.util.HitPosition;
import common.world.World;

public class EntityFireball extends EntityProjectile
{
    public int explosionPower = 1;

    public EntityFireball(World worldIn)
    {
        super(worldIn);
        this.setSize(0.45F, 0.45F);
    }

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

    public EntityFireball(World worldIn, EntityLiving shooter, double accelX, double accelY, double accelZ, double velocity)
    {
        super(worldIn, shooter, accelX, accelY, accelZ, 0.1, velocity);
        this.setSize(0.45F, 0.45F);
    }

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

            boolean flag = Config.mobGrief;
            this.worldObj.newExplosion(this.shootingEntity, this.posX, this.posY, this.posZ, (float)this.explosionPower, flag, false, true);
            this.setDead();
        }
    }

    public boolean attackEntityFrom(DamageSource source, int amount)
    {
        return false;
    }

    /**
     * (abstract) Protected helper method to write subclass entity data to NBT.
     */
    public void writeEntityToNBT(NBTTagCompound tagCompound)
    {
        super.writeEntityToNBT(tagCompound);
        tagCompound.setInteger("ExplosionPower", this.explosionPower);
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readEntityFromNBT(NBTTagCompound tagCompund)
    {
        super.readEntityFromNBT(tagCompund);

        if (tagCompund.hasKey("ExplosionPower", 99))
        {
            this.explosionPower = tagCompund.getInteger("ExplosionPower");
        }
    }
}
