    001package net.minecraft.item;
    002
    003import net.minecraft.block.BlockDispenser;
    004import net.minecraft.block.BlockRailBase;
    005import net.minecraft.creativetab.CreativeTabs;
    006import net.minecraft.dispenser.IBehaviorDispenseItem;
    007import net.minecraft.entity.item.EntityMinecart;
    008import net.minecraft.entity.player.EntityPlayer;
    009import net.minecraft.world.World;
    010
    011public class ItemMinecart extends Item
    012{
    013    private static final IBehaviorDispenseItem field_96602_b = new BehaviorDispenseMinecart();
    014    public int minecartType;
    015
    016    public ItemMinecart(int par1, int par2)
    017    {
    018        super(par1);
    019        this.maxStackSize = 1;
    020        this.minecartType = par2;
    021        this.setCreativeTab(CreativeTabs.tabTransport);
    022        BlockDispenser.dispenseBehaviorRegistry.putObject(this, field_96602_b);
    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        int i1 = par3World.getBlockId(par4, par5, par6);
    032
    033        if (BlockRailBase.isRailBlock(i1))
    034        {
    035            if (!par3World.isRemote)
    036            {
    037                EntityMinecart entityminecart = EntityMinecart.func_94090_a(par3World, (double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), this.minecartType);
    038
    039                if (par1ItemStack.hasDisplayName())
    040                {
    041                    entityminecart.func_96094_a(par1ItemStack.getDisplayName());
    042                }
    043
    044                par3World.spawnEntityInWorld(entityminecart);
    045            }
    046
    047            --par1ItemStack.stackSize;
    048            return true;
    049        }
    050        else
    051        {
    052            return false;
    053        }
    054    }
    055}