package common.item;

import common.block.Block;
import common.entity.npc.EntityNPC;
import common.util.BlockPos;
import common.util.Facing;
import common.world.World;

public class ItemSeedFood extends ItemFood
{
    private Block crops;

    /** Block ID of the soil this seed food should be planted on. */
    private Block soilId;

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

    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.soilId && worldIn.isAirBlock(pos.up()))
        {
            worldIn.setState(pos.up(), this.crops.getState());
            --stack.stackSize;
            return true;
        }
        else
        {
            return false;
        }
    }
}
