    001package net.minecraft.dispenser;
    002
    003import net.minecraft.block.BlockRail;
    004import net.minecraft.entity.item.EntityMinecart;
    005import net.minecraft.item.ItemMinecart;
    006import net.minecraft.item.ItemStack;
    007import net.minecraft.server.MinecraftServer;
    008import net.minecraft.util.EnumFacing;
    009import net.minecraft.world.World;
    010
    011public 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.getFront(par1IBlockSource.func_82620_h());
    030        World var4 = par1IBlockSource.getWorld();
    031        double var5 = par1IBlockSource.getX() + (double)((float)var3.getFrontOffsetX() * 1.125F);
    032        double var7 = par1IBlockSource.getY();
    033        double var9 = par1IBlockSource.getZ() + (double)((float)var3.getFrontOffsetZ() * 1.125F);
    034        int var11 = par1IBlockSource.getXInt() + var3.getFrontOffsetX();
    035        int var12 = par1IBlockSource.getYInt();
    036        int var13 = par1IBlockSource.getZInt() + var3.getFrontOffsetZ();
    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}