Arrow Knockback

Discussion in 'Plugin Development' started by Xp10d3, Jun 11, 2021.

  1. Offline


    Hello. Dumb question lol. I'm attempting to rework arrows entirely and base it off the force of the arrow, but am confused on changing the knockback of them. According to the docs (which yes is for 1.7.10, but since I'm working with 1.8.9 and Spigot docs are blocked on my laptop, it's fine haha) getKnockbackStrength() is based on Punch, so would getKnockbackStrength() for a non-enchanted bow return 0? Essentially, I want to set the knockback of the arrow to be dependent on the force of the arrow (which I can get via a map of when I store the force from BowShootEvent) and the current knockback of the arrow.

    2. @EventHandler
    3. public void onEntityDamage(EntityDamageByEntityEvent event) {
    4. if (event.getDamager() instanceof Arrow) {
    5. Arrow arrow = (Arrow) event.getDamager();
    6. if (force.containsKey(arrow.getUniqueId())) {
    7. Bukkit.getLogger().info("FOR TESTING. Force contained " + arrow.getUniqueId() + ". Applied force of " + 2 * force.get(arrow.getUniqueId()));
    8. //Player player = (Player) event.getEntity();
    9. event.setCancelled(true);
    10. double forcee = force.get(arrow.getUniqueId());
    11. event.setDamage(2 * forcee);
    12. Vector vector = arrow.getVelocity();
    13. arrow.setVelocity(vector.multiply(1.2));
    14. int curKb = arrow.getKnockbackStrength();
    15. int kb = (int) (forcee + curKb);
    16. arrow.setKnockbackStrength(kb);
    17. }
    18. } else {
    19. return;
    20. }
    21. }
  2. Offline


    All that typing for this question?
    Why don't you try it?
  3. Offline


    @Xp10d3 I believe your issue is that you are cancelling the event, therefore, cancelling the knockback and damage. Just don't cancel the event.
  4. Offline


    Fair; sorry for wasting your time.

    Alright; I'll try that.

Share This Page