Shooting tnt with bows??

Discussion in 'Plugin Development' started by Denisdemnis, Jan 4, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Denisdemnis

    How can I write a method in the EventsClass for shooting tnt with a bow? And the event?
     
  2. Offline

    KarimAKL

    @Denisdemnis I think you can listen to the EntityShootBowEvent and then set the projectile to an instance of TNTPrimed.
     
  3. Offline

    Denisdemnis

    Thank you, but how do I change the entity's projectile?
     
  4. Offline

    xelatercero

    @Denisdemnis

    I dont know if this is the best way but i got it working like this:

    Code:java
    1. @EventHandler
    2. public void onBowShot(EntityShootBowEvent e) {
    3.  
    4. Entity projectile = e.getProjectile();
    5. TNTPrimed tnt = projectile.getWorld().spawn(e.getProjectile().getLocation(), TNTPrimed.class);
    6.  
    7. if(projectile instanceof Arrow) {
    8. //Edit: like this the tnt explodes almost instantly on impact
    9. tnt.setTicksLived(5);
    10. tnt.setFuseTicks(20);
    11.  
    12.  
    13. tnt.setVelocity(projectile.getVelocity());
    14. e.setProjectile(tnt);
    15.  
    16. }
    17.  
    18. }
     
    Last edited: Jan 4, 2020
  5. Offline

    Denisdemnis

    Thank you so much!
     
  6. Offline

    xelatercero

Thread Status:
Not open for further replies.

Share This Page