Arrows And Enchantments

Discussion in 'Plugin Development' started by RingOfStorms, Sep 3, 2012.

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

    RingOfStorms

    So were all awrare or enchanted bows and they shoot cool arrows. What I want to know is how does the arrow hold the enchantment data? Is it a pre-defined metadata value? Or is it something else?

    Reason I ask is because I want to add in an enchantment after an arrow is shot via the launchProjectile function. The function returns an arrow that you can manipulate, and I want to know if there is an easy way to add enchantments to it.
     
  2. well, what is it that you want?
    you can't add enchantments to non enchantable items with bukki(as far as i know)
     
  3. Offline

    RingOfStorms

    I want to use the launchprojectile(arrow.class), and use that returned arrow, but put the enchantment effects, if any that were on the user's bow in hand onto that arrow.

    So lets say you're holding a flame aspect bow. You shoot, plugin cancels event, then does a launchprojectile(arrow.class) - how do I get that arrow I launched in to have that flame aspect on it?
     
  4. Offline

    travja

    So you want infinate arrows with the enchantments from the bow? If so, just add an arrow every time they shoot.
     
  5. Offline

    RingOfStorms

    Edit: so in other words, how to Arrows carry the enchantment normally, after a bow shoots, it must get passed on somehow? If I know this then maybe I can implement the same thing with the LaunchProjectile function.
     
  6. Offline

    travja

    What exactly are you trying to accomplish? Same as shooting a bow or infinite arrows?
     
  7. Offline

    RingOfStorms

    Any enchantment.. that includes infinite arrows, or power, or flame, or punch, etc.

    So any enchantment, just like a regular bow, which is what i am getting at. How does a regular enchantment bow (not just infinite) pass its enchantments onto its arrows shot?
     
  8. Offline

    travja

  9. Offline

    RingOfStorms

  10. Offline

    travja

    I'm not sure either.. You could use ProjectileHitEvent or EntityDamageEvent....
     
  11. Offline

    RingOfStorms

    Yea but then how do you apply the damage enchants? That is the next problem (if we can't apply them to the arrow).
     
  12. Offline

    RingOfStorms

  13. when the arrows hit it probably traces back to the bow and see what enchants it has. but still don't get what you want to do...
     
  14. Offline

    Courier

    For the fire enchantment, just ignite the arrow.
    For the other enchantments, I think you will need to reference CraftBukkit and use NMS :/
    Get the n.m.s.EntityArrow:
    Code:java
    1. net.minecraft.server.EntityArrow nmsArrow = ((CraftArrow)arrow).getHandle();
    For the damage enchantment, you need to call nmsArrow.b(double) which is the equivalent of setDamage(). I don't know what the damage values should be. You can mess around with shooting arrows normally and seeing what damage value they have with nmsArrow.d() (which is the equivalent of getDamage()). For the knockback, call nmsArrow.a(int) (which is setKnockback()).

    EDIT: By the way... I haven't tested this; it is just what I gathered from looking through the source. If it doesn't work, you can look through there and see where I went wrong.
     
  15. Offline

    RingOfStorms

Thread Status:
Not open for further replies.

Share This Page