    001package net.minecraft.dispenser;
    002
    003import net.minecraft.block.BlockDispenser;
    004import net.minecraft.entity.item.EntityItem;
    005import net.minecraft.item.ItemStack;
    006import net.minecraft.util.EnumFacing;
    007import net.minecraft.world.World;
    008
    009public class BehaviorDefaultDispenseItem implements IBehaviorDispenseItem
    010{
    011    /**
    012     * Dispenses the specified ItemStack from a dispenser.
    013     */
    014    public final ItemStack dispense(IBlockSource par1IBlockSource, ItemStack par2ItemStack)
    015    {
    016        ItemStack var3 = this.dispenseStack(par1IBlockSource, par2ItemStack);
    017        this.playDispenseSound(par1IBlockSource);
    018        this.spawnDispenseParticles(par1IBlockSource, EnumFacing.getFront(par1IBlockSource.func_82620_h()));
    019        return var3;
    020    }
    021
    022    /**
    023     * Dispense the specified stack, play the dispense sound and spawn particles.
    024     */
    025    protected ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack)
    026    {
    027        EnumFacing var3 = EnumFacing.getFront(par1IBlockSource.func_82620_h());
    028        IPosition var4 = BlockDispenser.func_82525_a(par1IBlockSource);
    029        ItemStack var5 = par2ItemStack.splitStack(1);
    030        func_82486_a(par1IBlockSource.getWorld(), var5, 6, var3, var4);
    031        return par2ItemStack;
    032    }
    033
    034    public static void func_82486_a(World par0World, ItemStack par1ItemStack, int par2, EnumFacing par3EnumFacing, IPosition par4IPosition)
    035    {
    036        double var5 = par4IPosition.getX();
    037        double var7 = par4IPosition.getY();
    038        double var9 = par4IPosition.getZ();
    039        EntityItem var11 = new EntityItem(par0World, var5, var7 - 0.3D, var9, par1ItemStack);
    040        double var12 = par0World.rand.nextDouble() * 0.1D + 0.2D;
    041        var11.motionX = (double)par3EnumFacing.getFrontOffsetX() * var12;
    042        var11.motionY = 0.20000000298023224D;
    043        var11.motionZ = (double)par3EnumFacing.getFrontOffsetZ() * var12;
    044        var11.motionX += par0World.rand.nextGaussian() * 0.007499999832361937D * (double)par2;
    045        var11.motionY += par0World.rand.nextGaussian() * 0.007499999832361937D * (double)par2;
    046        var11.motionZ += par0World.rand.nextGaussian() * 0.007499999832361937D * (double)par2;
    047        par0World.spawnEntityInWorld(var11);
    048    }
    049
    050    /**
    051     * Play the dispense sound from the specified block.
    052     */
    053    protected void playDispenseSound(IBlockSource par1IBlockSource)
    054    {
    055        par1IBlockSource.getWorld().playAuxSFX(1000, par1IBlockSource.getXInt(), par1IBlockSource.getYInt(), par1IBlockSource.getZInt(), 0);
    056    }
    057
    058    /**
    059     * Order clients to display dispense particles from the specified block and facing.
    060     */
    061    protected void spawnDispenseParticles(IBlockSource par1IBlockSource, EnumFacing par2EnumFacing)
    062    {
    063        par1IBlockSource.getWorld().playAuxSFX(2000, par1IBlockSource.getXInt(), par1IBlockSource.getYInt(), par1IBlockSource.getZInt(), this.func_82488_a(par2EnumFacing));
    064    }
    065
    066    private int func_82488_a(EnumFacing par1EnumFacing)
    067    {
    068        return par1EnumFacing.getFrontOffsetX() + 1 + (par1EnumFacing.getFrontOffsetZ() + 1) * 3;
    069    }
    070}