package common.entity.projectile;

import common.entity.DamageSource;
import common.entity.types.EntityLiving;
import common.tags.TagObject;
import common.util.HitPosition;
import common.vars.Vars;
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 (Vars.damageFireball && movingObject.entity != null)
            {
                movingObject.entity.attackEntityFrom(DamageSource.causeFireballDamage(this, this.shootingEntity), 8);
                this.applyEnchantments(this.shootingEntity, movingObject.entity);
            }

            boolean flag = Vars.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 writeEntity(TagObject tagCompound)
    {
        super.writeEntity(tagCompound);
        tagCompound.setInt("ExplosionPower", this.explosionPower);
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readEntity(TagObject tagCompund)
    {
        super.readEntity(tagCompund);
        this.explosionPower = tagCompund.getInt("ExplosionPower");
    }
}
