Making items throwable?

Discussion in 'Plugin Development' started by Theodossis, Aug 5, 2012.

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

    Theodossis

    I am making a plugin and i want to make slimeballs throwable like egg.
    Thanks,
    Theodossis
     
  2. Offline

    CorrieKay

    Im guessing you could probably spawn an entity of an item, get the item stack, set the type to slimeball, then set the items velocity. But thats just a (debatably) educated guess.​
     
    PogoStick29 likes this.
  3. Offline

    Loog

    I have also been wondering how you would do this.
    CorrieKay How would we do that? code?
     
  4. Offline

    Malikk

    That's how I've done it in the past. Pretty simple actually.

    This is from MobCatcher.

    Code:
    public void playerThrowEvent(Player player){
            
            ItemStack eggItem = player.getItemInHand();
            ItemStack throwStack = new ItemStack(eggItem);
            throwStack.setAmount(1);
            int amt = eggItem.getAmount();
            Location pLoc = player.getEyeLocation();
            
            Item thrownEggItem = player.getWorld().dropItem(pLoc, throwStack);
            thrownEggItem.setVelocity(pLoc.getDirection());
    
             eggItem.setAmount(amt - 1);
             player.setItemInHand(eggItem);
    
            }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  5. Offline

    CorrieKay

    ooooh, thats where the drop item method is. I tried using the player object, and it didnt work. Good job :3
     
  6. Offline

    Firefly


    Don't forget dropItemNaturally() is there as well for a more "natural" looking drop :D
     
  7. Offline

    Malikk

    dropItemNaturally wouldn't be good in this situation, since we want to set it's velocity to a specific direction.
     
  8. Offline

    Firefly

    I know, I was just pointing out to Corrie ;)
     
    CorrieKay likes this.
  9. Offline

    willis62501

    Wait, I need help, how do I set the item to a Slime ball
     
  10. Offline

    Garris0n

  11. Offline

    willis62501

    Garris0n I'm still confused, how do I use this stuff, Like how would I code it?

    These JavaDocs just confuse me, I don't know what way to use them
     
  12. Offline

    Garris0n

  13. Offline

    willis62501

  14. Offline

    Licio123

    Guys is there a way to return the location where the eggItem used to arive?
     
  15. Offline

    ChipDev

    Err.. I would use runnables as there is no EntityMoveEvent.
     
  16. Offline

    Skionz

    Not sure what you want the the ProjectileHitEvent is called when a projectile hits something. If you want to get the projectile while it is in mid air then you will have to do what ChipDev said and use runnables.
     
  17. Offline

    FabeGabeMC

    Stop this necromancy! Halloween is over! :p
    EDIT: Plus, this gets the award for the longest time a thread hasn't been marked as solved, but has been necro-posted in twice, as far as I know. Congrats! Here's your trick or treat candy [cake]
     
    acer5999, Th3Br1x and Skionz like this.
  18. Offline

    Licio123

    Ok However how runnables will help me
     
  19. Offline

    Skionz

    Add the projectile to a list and when the scheduler runs, iterate through the list and get the locations of the Projectiles.
     
  20. Offline

    Licio123

    OK thank you
     
    Skionz likes this.
Thread Status:
Not open for further replies.

Share This Page