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