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