package common.entity.projectile;

import common.entity.DamageSource;
import common.entity.animal.EntityChicken;
import common.entity.types.EntityLiving;
import common.entity.types.EntityThrowable;
import common.init.Config;
import common.init.ItemRegistry;
import common.init.Items;
import common.model.ParticleType;
import common.util.HitPosition;
import common.world.World;

public class EntityEgg extends EntityThrowable
{
    public EntityEgg(World worldIn)
    {
        super(worldIn);
    }

    public EntityEgg(World worldIn, EntityLiving throwerIn)
    {
        super(worldIn, throwerIn);
    }

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

    /**
     * Called when this EntityThrowable hits a block or entity.
     */
    protected void onImpact(HitPosition p_70184_1_)
    {
        if (p_70184_1_.entity != null && Config.knockEgg)
        {
            p_70184_1_.entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
        }

        if (!this.worldObj.client && this.rand.chance(8) && Config.mobs && Config.spawnEggChicken)
        {
            int i = this.rand.chance(1, 4, 32);

//            if (this.rand.chance(32))
//            {
//                i = 4;
//            }

            for (int j = 0; j < i; ++j)
            {
                EntityChicken entitychicken = new EntityChicken(this.worldObj);
                entitychicken.setGrowingAge(-24000);
                entitychicken.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotYaw, 0.0F);
                this.worldObj.spawnEntityInWorld(entitychicken);
            }
        }

        double d0 = 0.08D;

        for (int k = 0; k < 8; ++k)
        {
            this.worldObj.spawnParticle(ParticleType.ITEM_CRACK, this.posX, this.posY, this.posZ, ((double)this.rand.floatv() - 0.5D) * 0.08D, ((double)this.rand.floatv() - 0.5D) * 0.08D, ((double)this.rand.floatv() - 0.5D) * 0.08D, ItemRegistry.getIdFromItem(Items.egg));
        }

        if (!this.worldObj.client)
        {
            this.setDead();
        }
    }
}
