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