    001    package net.minecraft.dispenser;
    002
    003    import net.minecraft.block.BlockRail;
    004    import net.minecraft.entity.item.EntityMinecart;
    005    import net.minecraft.item.ItemMinecart;
    006    import net.minecraft.item.ItemStack;
    007    import net.minecraft.server.MinecraftServer;
    008    import net.minecraft.util.EnumFacing;
    009    import net.minecraft.world.World;
    010
    011    public class BehaviorDispenseMinecart extends BehaviorDefaultDispenseItem
    012    {
    013        /** Reference to the BehaviorDefaultDispenseItem object. */
    014        private final BehaviorDefaultDispenseItem defaultItemDispenseBehavior;
    015
    016        final MinecraftServer mcServer;
    017
    018        public BehaviorDispenseMinecart(MinecraftServer par1MinecraftServer)
    019        {
    020            this.mcServer = par1MinecraftServer;
    021            this.defaultItemDispenseBehavior = new BehaviorDefaultDispenseItem();
    022        }
    023
    024        /**
    025         * Dispense the specified stack, play the dispense sound and spawn particles.
    026         */
    027        public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack)
    028        {
    029            EnumFacing var3 = EnumFacing.func_82600_a(par1IBlockSource.func_82620_h());
    030            World var4 = par1IBlockSource.getWorld();
    031            double var5 = par1IBlockSource.getX() + (double)((float)var3.func_82601_c() * 1.125F);
    032            double var7 = par1IBlockSource.getY();
    033            double var9 = par1IBlockSource.getZ() + (double)((float)var3.func_82599_e() * 1.125F);
    034            int var11 = par1IBlockSource.getXInt() + var3.func_82601_c();
    035            int var12 = par1IBlockSource.getYInt();
    036            int var13 = par1IBlockSource.getZInt() + var3.func_82599_e();
    037            int var14 = var4.getBlockId(var11, var12, var13);
    038            double var15;
    039
    040            if (BlockRail.isRailBlock(var14))
    041            {
    042                var15 = 0.0D;
    043            }
    044            else
    045            {
    046                if (var14 != 0 || !BlockRail.isRailBlock(var4.getBlockId(var11, var12 - 1, var13)))
    047                {
    048                    return this.defaultItemDispenseBehavior.dispense(par1IBlockSource, par2ItemStack);
    049                }
    050
    051                var15 = -1.0D;
    052            }
    053
    054            EntityMinecart var17 = new EntityMinecart(var4, var5, var7 + var15, var9, ((ItemMinecart)par2ItemStack.getItem()).minecartType);
    055            var4.spawnEntityInWorld(var17);
    056            par2ItemStack.splitStack(1);
    057            return par2ItemStack;
    058        }
    059
    060        /**
    061         * Play the dispense sound from the specified block.
    062         */
    063        protected void playDispenseSound(IBlockSource par1IBlockSource)
    064        {
    065            par1IBlockSource.getWorld().playAuxSFX(1000, par1IBlockSource.getXInt(), par1IBlockSource.getYInt(), par1IBlockSource.getZInt(), 0);
    066        }
    067    }