Advertisement
Guest User

ArrowTrapHook.java

a guest
Apr 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.97 KB | None | 0 0
  1. public class ArrowTrapHook extends BehaviorProjectileDispense
  2. {
  3.      /**
  4.      * Dispenses the specified ItemStack from a dispenser.
  5.      * @return
  6.      */
  7.     //Commented out because "cannot override the final method from BehaviorDefaultDispenseItem"
  8.    //public ItemStack dispense(IBlockSource source, ItemStack stack)
  9.    //{
  10.      // ItemStack itemstack = this.dispenseStack(source, stack);
  11.      // this.playDispenseSound(source);
  12.     //   this.spawnDispenseParticles(source, (EnumFacing)source.getBlockState().getValue(ArrowTrap.FACING));
  13.    //  return itemstack;
  14.  // }
  15.    
  16.     @Override
  17.     protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack stackIn) {
  18.         return null;
  19.         // TODO Auto-generated method stub
  20.     }
  21.  
  22.     /**
  23.      * Dispense the specified stack, play the dispense sound and spawn particles.
  24.      */
  25.     public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
  26.     {
  27.         EnumFacing enumfacing = (EnumFacing)source.getBlockState().getValue(ArrowTrap.FACING);
  28.         IPosition iposition = ArrowTrap.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.spawnEntity(entityitem);
  58.     }
  59.  
  60.     /**
  61.      * Play the dispense sound from the specified block.
  62.      */
  63.     public void playDispenseSound(IBlockSource source)
  64.     {
  65.         source.getWorld().playEvent(1000, source.getBlockPos(), 0);
  66.     }
  67.  
  68.     /**
  69.      * Order clients to display dispense particles from the specified block and facing.
  70.      */
  71.     public void spawnDispenseParticles(IBlockSource source, EnumFacing facingIn)
  72.     {
  73.         source.getWorld().playEvent(2000, source.getBlockPos(), this.getWorldEventDataFrom(facingIn));
  74.     }
  75.  
  76.     public int getWorldEventDataFrom(EnumFacing facingIn)
  77.     {
  78.         return facingIn.getFrontOffsetX() + 1 + (facingIn.getFrontOffsetZ() + 1) * 3;
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement