BiomesOPlenty/common/biomesoplenty/items/ItemBOPSeeds.java
2013-11-30 03:25:48 -05:00

89 lines
2.8 KiB
Java

package biomesoplenty.items;
import biomesoplenty.BiomesOPlenty;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.IPlantable;
public class ItemBOPSeeds extends Item implements IPlantable
{
/**
* The type of block this seed turns into (wheat or pumpkin stems for instance)
*/
private int blockType;
/** BlockID of the block the seeds can be planted on. */
private int soilBlockID;
public ItemBOPSeeds(int par1, int par2, int par3)
{
super(par1);
this.blockType = par2;
this.soilBlockID = par3;
this.setCreativeTab(BiomesOPlenty.tabBiomesOPlenty);
}
@Override
public void registerIcons(IconRegister iconRegister)
{
itemIcon = iconRegister.registerIcon("biomesoplenty:beetrootseeds");
}
/**
* Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
* True if something happen and false if it don't. This is for ITEMS, not BLOCKS
*/
@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
if (par7 != 1)
{
return false;
}
else if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack))
{
int i1 = par3World.getBlockId(par4, par5, par6);
Block soil = Block.blocksList[i1];
if (soil != null && soil.canSustainPlant(par3World, par4, par5, par6, ForgeDirection.UP, this) && par3World.isAirBlock(par4, par5 + 1, par6))
{
par3World.setBlock(par4, par5 + 1, par6, this.blockType);
--par1ItemStack.stackSize;
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
@Override
public EnumPlantType getPlantType(World world, int x, int y, int z)
{
return (blockType == Block.netherStalk.blockID ? EnumPlantType.Nether : EnumPlantType.Crop);
}
@Override
public int getPlantID(World world, int x, int y, int z)
{
return blockType;
}
@Override
public int getPlantMetadata(World world, int x, int y, int z)
{
return 0;
}
}