package common.item.block;

import common.block.Block;
import common.block.foliage.BlockBush;
import common.entity.npc.EntityNPC;
import common.item.CheatTab;
import common.item.Item;
import common.item.ItemStack;
import common.model.Transforms;
import common.util.BlockPos;
import common.util.Facing;
import common.world.World;

public class ItemSeeds extends Item
{
    private BlockBush crops;
    private Block soil;

    public ItemSeeds(BlockBush crops, Block soil)
    {
        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;
        }
    }

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