| 1 | package net.minecraft.dispenser;
|
| 2 |
|
| 3 | import net.minecraft.block.BlockDispenser;
|
| 4 | import net.minecraft.entity.item.EntityItem;
|
| 5 | import net.minecraft.item.ItemStack;
|
| 6 | import net.minecraft.util.EnumFacing;
|
| 7 | import net.minecraft.world.World;
|
| 8 |
|
| 9 | public class BehaviorDefaultDispenseItem implements IBehaviorDispenseItem
|
| 10 | {
|
| 11 | /**
|
| 12 | * Dispenses the specified ItemStack from a dispenser.
|
| 13 | */
|
| 14 | public final ItemStack dispense(IBlockSource source, ItemStack stack)
|
| 15 | {
|
| 16 | ItemStack itemstack = this.dispenseStack(source, stack);
|
| 17 | this.playDispenseSound(source);
|
| 18 | this.spawnDispenseParticles(source, BlockDispenser.getFacing(source.getBlockMetadata()));
|
| 19 | return itemstack;
|
| 20 | }
|
| 21 |
|
| 22 | /**
|
| 23 | * Dispense the specified stack, play the dispense sound and spawn particles.
|
| 24 | */
|
| 25 | protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
| 26 | {
|
| 27 | EnumFacing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
|
| 28 | IPosition iposition = BlockDispenser.getDispensePosition(source);
|
| 29 | ItemStack itemstack = stack.splitStack(1);
|
| 30 | doDispense(source.getWorld(), itemstack, 6, enumfacing, iposition);
|
| 31 | return stack;
|
| 32 | }
|
| 33 |
|
| 34 | public static void doDispense(World worldIn, ItemStack stack, int speed, EnumFacing facing, IPosition position)
|
| 35 | {
|
| 36 | double d0 = position.getX();
|
| 37 | double d1 = position.getY();
|
| 38 | double d2 = position.getZ();
|
| 39 |
|
| 40 | if (facing.getAxis() == EnumFacing.Axis.Y)
|
| 41 | {
|
| 42 | d1 = d1 - 0.125D;
|
| 43 | }
|
| 44 | else
|
| 45 | {
|
| 46 | d1 = d1 - 0.15625D;
|
| 47 | }
|
| 48 |
|
| 49 | EntityItem entityitem = new EntityItem(worldIn, d0, d1, d2, stack);
|
| 50 | double d3 = worldIn.rand.nextDouble() * 0.1D + 0.2D;
|
| 51 | entityitem.motionX = (double)facing.getFrontOffsetX() * d3;
|
| 52 | entityitem.motionY = 0.20000000298023224D;
|
| 53 | entityitem.motionZ = (double)facing.getFrontOffsetZ() * d3;
|
| 54 | entityitem.motionX += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
|
| 55 | entityitem.motionY += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
|
| 56 | entityitem.motionZ += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
|
| 57 | worldIn.spawnEntityInWorld(entityitem);
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * Play the dispense sound from the specified block.
|
| 62 | */
|
| 63 | protected void playDispenseSound(IBlockSource source)
|
| 64 | {
|
| 65 | source.getWorld().playAuxSFX(1000, source.getBlockPos(), 0);
|
| 66 | }
|
| 67 |
|
| 68 | /**
|
| 69 | * Order clients to display dispense particles from the specified block and facing.
|
| 70 | */
|
| 71 | protected void spawnDispenseParticles(IBlockSource source, EnumFacing facingIn)
|
| 72 | {
|
| 73 | source.getWorld().playAuxSFX(2000, source.getBlockPos(), this.func_82488_a(facingIn));
|
| 74 | }
|
| 75 |
|
| 76 | private int func_82488_a(EnumFacing facingIn)
|
| 77 | {
|
| 78 | return facingIn.getFrontOffsetX() + 1 + (facingIn.getFrontOffsetZ() + 1) * 3;
|
| 79 | }
|
| 80 | }
|
| 81 |
|