package common.entity.animal;

import common.entity.item.EntityItem;
import common.entity.npc.EntityNPC;
import common.entity.types.EntityLiving;
import common.init.Blocks;
import common.init.Items;
import common.init.SoundEvent;
import common.item.ItemShears;
import common.item.ItemStack;
import common.model.ParticleType;
import common.world.World;

public class EntityMooshroom extends EntityCow
{
    public EntityMooshroom(World worldIn)
    {
        super(worldIn);
        this.setSize(0.9F, 1.3F);
		this.spawnableBlocks.clear();
		this.spawnableBlocks.add(Blocks.mycelium);
    }

    /**
     * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
     */
    public boolean interact(EntityNPC player)
    {
        ItemStack itemstack = player.inventory.getCurrentItem();

        if (itemstack != null && itemstack.getItem() == Items.bowl && !this.isChild())
        {
            if (itemstack.stackSize == 1)
            {
                player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Items.mushroom_stew));
                return true;
            }

            if (player.inventory.addItemStackToInventory(new ItemStack(Items.mushroom_stew))) // && !player.creative)
            {
                player.inventory.decrStackSize(player.inventory.currentItem, 1);
                return true;
            }
        }

        if (itemstack != null && itemstack.getItem() instanceof ItemShears && !this.isChild())
        {
            this.setDead();
            this.worldObj.spawnParticle(ParticleType.EXPLOSION_LARGE, this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, 0.0D, 0.0D, 0.0D);

            if (!this.worldObj.client)
            {
                EntityCow entitycow = new EntityCow(this.worldObj);
                entitycow.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotYaw, this.rotPitch);
                entitycow.setHealth(this.getHealth());
                entitycow.yawOffset = this.yawOffset;

                if (this.hasCustomName())
                {
                    entitycow.setCustomNameTag(this.getCustomNameTag());
                }

                this.worldObj.spawnEntityInWorld(entitycow);

                for (int i = 0; i < 5; ++i)
                {
                    this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY + (double)this.height, this.posZ, new ItemStack(Blocks.red_mushroom)));
                }

                itemstack.damageItem(1, player);
                this.playSound(SoundEvent.CUT, 1.0F);
            }

            return true;
        }
        else
        {
            return super.interact(player);
        }
    }

    public EntityMooshroom createChild(EntityLiving ageable)
    {
        return new EntityMooshroom(this.worldObj);
    }
    
	public int getColor() {
		return 0x7c4c83;
	}
}
