Stop arrows from bouncing

Discussion in 'Spigot Plugin Development' started by NoobDoesMC, Apr 9, 2018.

  1. I shoot 5 successive arrows quickly from a player:

    Code (Java):
    BukkitTask barrageTask = new BukkitRunnable() {
      int arrowCounter = 0;

      public void run() {
        if (arrowCounter == 5) {
        Vector arrowVelocity = player.getLocation().getDirection().multiply(2.0);
        EntityArrow arrow = ((CraftArrow) player.launchProjectile(Arrow.class, arrowVelocity)).getHandle();
        arrow.fromPlayer = 0;
    }.runTaskTimer(plugin, 0L, 1L);
    Only the first and maybe last/second-last arrows hit the entity target.

    The rest of the arrows bounce off, and often damage the shooter.

    How can I stop arrows from bouncing, or at least stop bounced arrows from damaging the shooter.
  2. It doesn't, probably same issue as

    I've also been trying
    Code (Java):
    Vector arrowVelocity = playerDirection.multiply(1.5).add(boostY);
    Arrow arrow = (Arrow) this.player.launchProjectile(Arrow.class, arrowVelocity);
    EntityArrow entityArrow = ((CraftArrow) arrow).getHandle();
    entityArrow.fromPlayer = 0;
    but they still bounce.

    Anyone got a solution? Stop arrows from bouncing off entities and hitting other entities after they bounce?
  3. BananaPuncher714


    Set the entity's invulnerable time to 0 ticks after getting hit by an arrow. This will allow it to get damaged immediately and your arrows shouldn't bounce off.
    • Agree Agree x 1
  4. I've already experimented with this. I don't like this behaviour. Melee can also be used during the time they have a 0-tick hit cool down, and the barrage does way too much dmg if every arrow hits.

    I like the current damage interval, just want the arrows to not bounce.
  5. You could pair this with an Entity damage event and cancel damage that wouldn't happen with the normal invulnerable ticks.
  6. What's the normal invulnerable ticks?

    Is there a time since last damage tracker on entities?
  7. Get it with player.getNoDamageTicks() to find out, I don't remember.
    No, as far as I know. You could implement it yourself though.
  8. 20 ticks, you can change it though

    no, you have to implement it yourself
  9. Not sure about this but try .setShooter(Player) to stop it from damaging you, I think I read somewhere that this prevents damage to the shooter.
  10. Pretty sure the shooter is already the player, .getShooter().getName() returns that player's name