On player interact with a dropped item

Discussion in 'Plugin Development' started by NonameSL, May 12, 2014.

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

    NonameSL

    How do I declare a player interacting with an item on the floor, and when the player does send the item flying? (I know how to launch it but how do I declare the interact event?)
     
  2. Offline

    Onlineids

    This event: Event
     
  3. Offline

    NonameSL

    Onlineids thanks, but how do I launch the item? using this code:
    Code:
    Item item = e.getItem();
                        item.setVelocity(p.getLocation().getDirection().multiply(2));
                        item.setVelocity(new Vector(p.getVelocity().getX(), 1.0D, p.getVelocity().getZ()));
    only makes the item fly up. but when I apply the code on both the player and the item it flies them both. Why isn't this working?
     
  4. Offline

    NonameSL

  5. NonameSL Okay, I'm confused. When the player tries to pick up the item, what do you want to happen?
     
  6. Offline

    NonameSL

    I want the item to be launched (with all the vector stuff). How can I do that?
     
  7. NonameSL Isn't that what your setVelocity already does? :S
     
  8. Offline

    zDylann

    Listen for the PlayerPickupItemEvent, If it's the item you want to launch, then cancel the event and apply vector/velocity. I'm not entirely sure that's what you want, but it seems like it. If you need help with understanding how to apply velocity there are tons of threads about this already.
     
  9. Offline

    NonameSL

    That is exactly what I am doing! My code:
    Code:java
    1.  
    2. e.setCancelled(true);
    3. Item item = e.getItem();
    4. item.setVelocity(p.getLocation().getDirection().multiply(2));
    5. item.setVelocity(new Vector(p.getVelocity().getX(), 1.0D, p.getVelocity().getZ()));
    6.  

    Why is this not launching the item forward like it does with the player? Why is this only launching the item up?
     
  10. Offline

    zDylann


    So are you trying to make the item shoot away from where the player is facing?
     
  11. Offline

    NonameSL

    That is exactly what I am trying to do. If you will, to simulate a ball kicking.
     
  12. Offline

    qlimax5000

    NonameSL
    It only shoots up because Java is so fast that as soon as it starts flying forward you reset the movement to 0 2 0 instead use item.getVelocity().getX() and .getZ() on the x and z. That'll make it fly high and forward.
     
  13. Offline

    NonameSL

    qlimax5000 I dont quite understand what you're saying. What should I do to fix the problem exactly?
     
  14. Offline

    qlimax5000

    item.setVelocity(player.getLocation().getDirection().multiply(2));
    item.setVelocity(item.getVelocity().getX(), 2, item.getVelocity().getZ());

    The mistake was that first you shot it with the player facing and then later set it to 0,2,0 which stops it from moving sideways (because x and z values were 0)
     
Thread Status:
Not open for further replies.

Share This Page