    001package net.minecraft.item;
    002
    003import net.minecraft.block.Block;
    004import net.minecraft.entity.player.EntityPlayer;
    005import net.minecraft.world.World;
    006import net.minecraftforge.common.EnumPlantType;
    007import net.minecraftforge.common.ForgeDirection;
    008import net.minecraftforge.common.IPlantable;
    009
    010public class ItemSeedFood extends ItemFood implements IPlantable
    011{
    012    /** Block ID of the crop this seed food should place. */
    013    private int cropId;
    014
    015    /** Block ID of the soil this seed food should be planted on. */
    016    private int soilId;
    017
    018    public ItemSeedFood(int par1, int par2, float par3, int par4, int par5)
    019    {
    020        super(par1, par2, par3, false);
    021        this.cropId = par4;
    022        this.soilId = par5;
    023    }
    024
    025    /**
    026     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
    027     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
    028     */
    029    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    030    {
    031        if (par7 != 1)
    032        {
    033            return false;
    034        }
    035        else if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack))
    036        {
    037            int i1 = par3World.getBlockId(par4, par5, par6);
    038            Block soil = Block.blocksList[i1];
    039
    040            if (soil != null && soil.canSustainPlant(par3World, par4, par5, par6, ForgeDirection.UP, this) && par3World.isAirBlock(par4, par5 + 1, par6))
    041            {
    042                par3World.setBlock(par4, par5 + 1, par6, this.cropId);
    043                --par1ItemStack.stackSize;
    044                return true;
    045            }
    046            else
    047            {
    048                return false;
    049            }
    050        }
    051        else
    052        {
    053            return false;
    054        }
    055    }
    056
    057    @Override
    058    public EnumPlantType getPlantType(World world, int x, int y, int z)
    059    {
    060        return EnumPlantType.Crop;
    061    }
    062
    063    @Override
    064    public int getPlantID(World world, int x, int y, int z)
    065    {
    066        return cropId;
    067    }
    068
    069    @Override
    070    public int getPlantMetadata(World world, int x, int y, int z)
    071    {
    072        return 0;
    073    }
    074}