package common.item.block;

import common.block.Block;
import common.block.foliage.BlockCrops;
import common.entity.npc.EntityNPC;
import common.item.CheatTab;
import common.item.ItemStack;
import common.item.tool.ItemFood;
import common.util.BlockPos;
import common.util.Facing;
import common.world.World;

public class ItemSeedFood extends ItemFood
{
    private BlockCrops crops;
    private Block soil;

    public ItemSeedFood(int healAmount, BlockCrops crops, Block soil)
    {
        super(healAmount, false);
        this.crops = crops;
        this.soil = soil;
        this.setTab(CheatTab.PLANTS);
    }

    public Block getBlock()
    {
        return this.crops;
    }

    /**
     * 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 (side != Facing.UP)
        {
            return false;
        }
        else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
        {
            return false;
        }
        else if (worldIn.getState(pos).getBlock() == this.soil && worldIn.isAirBlock(pos.up()))
        {
            worldIn.setState(pos.up(), this.crops.getState());
            --stack.size;
            return true;
        }
        else
        {
            return false;
        }
    }
}
