package common.item;

import common.entity.npc.EntityNPC;
import common.init.Blocks;
import common.init.SoundEvent;
import common.material.Material;
import common.util.BlockPos;
import common.util.Facing;
import common.world.World;

public class ItemFireball extends Item
{
    public ItemFireball()
    {
        this.setTab(CheatTab.tabTools);
    }

    /**
     * Called when a Block is right-clicked with this Item
     */
    public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
    {
        if (worldIn.client)
        {
            return true;
        }
        else
        {
            pos = pos.offset(side);

            if (!playerIn.canPlayerEdit(pos, side, stack))
            {
                return false;
            }
            else
            {
                if (worldIn.getState(pos).getBlock().getMaterial() == Material.air)
                {
                    worldIn.playSound(SoundEvent.FIREBALL, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 1.0F);
                    worldIn.setState(pos, Blocks.fire.getState());
                }

//                if (!playerIn.creative)
//                {
                --stack.stackSize;
//                }

                return true;
            }
        }
    }
}
