Dropping ItemStack from player like when pressing 'Q'

Discussion in 'Plugin Development' started by r3Fuze, Oct 24, 2011.

Thread Status:
Not open for further replies.
  1. I'm trying to get an ItemStack to drop from the player like it would drop when pressing Q.
    Figured out. Code:
    Code:java
    1. // Drop item
    2. dropItem(player, 0.2, new ItemStack(Material.DIAMOND, 1));
    3.  
    4. // Method
    5. public static Item dropItem(Player player, double vec, ItemStack is) {
    6. Location l = player.getLocation();
    7. l.setY(l.getY() + 1);
    8. Item item = l.getWorld().dropItem(l, is);
    9. Vector v = l.getDirection().multiply(vec);
    10. v.setY(0.2);
    11. item.setVelocity(v);
    12. return item;
    13. }


    And another question is: Is it possible to change the maxstack size of a GenericCustomItem in Spout ? (You might be the man for this @Afforess )

    EDIT: here is a drawing of what I am looking for:
    [​IMG]
     
    ArcheCane and Samkio like this.
  2. Offline

    nisovin

    Umm... you remove it from their inventory and do World.dropItem().
     
  3. That only drops it at their feet. I want it to drop with a bit of velocity away from the player.
     
  4. Offline

    nisovin

    World.dropItem() will return an Item entity, which you can set velocity for.
     
  5. Offline

    Afforess

    Not at the moment, the ability to set the max stack size has not been added yet. :/

    Keep in mind the API is still experimental.
     
    r3Fuze likes this.
Thread Status:
Not open for further replies.

Share This Page