001 package net.minecraft.item; 002 003 import net.minecraft.block.BlockRail; 004 import net.minecraft.creativetab.CreativeTabs; 005 import net.minecraft.entity.item.EntityMinecart; 006 import net.minecraft.entity.player.EntityPlayer; 007 import net.minecraft.world.World; 008 009 public class ItemMinecart extends Item 010 { 011 public int minecartType; 012 013 public ItemMinecart(int par1, int par2) 014 { 015 super(par1); 016 this.maxStackSize = 1; 017 this.minecartType = par2; 018 this.setCreativeTab(CreativeTabs.tabTransport); 019 } 020 021 /** 022 * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return 023 * True if something happen and false if it don't. This is for ITEMS, not BLOCKS 024 */ 025 public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) 026 { 027 int var11 = par3World.getBlockId(par4, par5, par6); 028 029 if (BlockRail.isRailBlock(var11)) 030 { 031 if (!par3World.isRemote) 032 { 033 par3World.spawnEntityInWorld(new EntityMinecart(par3World, (double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), this.minecartType)); 034 } 035 036 --par1ItemStack.stackSize; 037 return true; 038 } 039 else 040 { 041 return false; 042 } 043 } 044 }