package common.item;

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

public class ItemSeeds extends Item
{
    private Block crops;

    /** BlockID of the block the seeds can be planted on. */
    private Block soilBlockID;

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

    public Transforms getTransform() {
    	return Transforms.OFFSET1;
    }
}
