Solved How to get the arrow ItemStack before bow shooting?

Discussion in 'Plugin Development' started by YogurtSmudge, Aug 14, 2017.

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

    YogurtSmudge

    So I'm making a plugin where you right-click a arrow with the name "Lightning" and when you shoot it, it strikes lightning in the spot, which works. The problem is, the bow shoots the closest arrow itemstack (I think)? So in other words if a bow is in slot 1 in your hotbar, a stack of normal arrows is in slot 2, and the lightning arrow in slot 3, you basically have 65 lightning arrows. Because the bow grabs the first itemstack of arrows. So my question is, is there any possible way to grab a arrow itemstack?

    Thanks.
     
  2. Offline

    PenguinOwl

    Just use first(Material.ARROW) on the inventory interface to fetch the first arrow in the inventory
     
    YogurtSmudge likes this.
  3. Offline

    YogurtSmudge

    Right, but it returns an int? What do I do with the int? This is first time I have heard of .first();
    Sorry.
     
  4. Offline

    PenguinOwl

    It returns the slot number as an int, starting at 0 for slot 1
     
    YogurtSmudge likes this.
  5. Offline

    YogurtSmudge

    Yeah I got it, I figured it out. I used:

    int firstarrowslot = p.getInventory().first(Material.ARROW);
    ItemStack firstarrowitem = p.getInventory().getItem(firstarrowslot);

    Thanks @PenguinOwl
     
  6. Offline

    PenguinOwl

    Glad to help.
     
Thread Status:
Not open for further replies.

Share This Page