Item spray fountain

Discussion in 'Plugin Development' started by oasis9, Nov 6, 2014.

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

    oasis9

    I have a server, obviously, and I would like to have items spray out when a mob is killed. My problem is that the items bunch together, and don't look very good. I'd also like them to disappear after a short amount of time, and not be able to be picked up - packets, maybe? I've tried spawning actual items, but that didn't work all too well, as I stated above.

    Thanks in advance,
    Bob.
     
  2. Offline

    adam753

    You should be able to do this with normal ItemStacks without any packets or fancy stuff. To prevent them merging, you want to give each one a different name or bit of lore. Since you don't want them being picked up and it doesn't matter what you name them, you could just do this each time you spawn one:
    Code:
    ItemMeta itemMeta = item.getItemMeta();
    itemMeta.setDisplayName(random.nextInt().toString()); //java.util.Random
    item.setItemMeta(itemMeta);
    As for making it so you can't pick them up, you've got two choices. Option 1 is add the ItemStack to a list and cancel PlayerPickupItemEvent if the item's in that list. Option 2 is do item.setPickupDelay(999999). As you've said you want them to disappear after a bit (you're probably using schedulers), using this method to make the items non-pick-up-able for a lot of ticks should suit you.
     
    oasis9 likes this.
  3. Offline

    jensdeboom

    oasis9 to make the items disappear:
    - listen for ItemSpawnEvent
    - start a delayed task
    - e.getEntity().remove();
     
    oasis9 likes this.
  4. Offline

    adam753

    jensdeboom
    Shouldn't be any need to listen to ItemSpawnEvent if he's spawning the items himself.
     
    oasis9 likes this.
  5. Offline

    Skionz

    jensdeboom Just use UUID.randomUUID().toString() for the name so they don't stack
     
    oasis9 likes this.
  6. oasis9 likes this.
  7. Offline

    jensdeboom

    Skionz ? why are u tagging me lol
     
  8. Offline

    Skionz

  9. Offline

    oasis9

    jensdeboom That part's the easy one. Thanks guys, this should have been obvious, but at least I know now. Thanks again.

    adventuretc I may use that later, thanks for the suggestion - it looks amazing - but I don't think I need to take it that far just for this.

    Skionz I see you're not on spigot #1649, I got it just in time, I love how it's cross version compatible. I can't connect to your server on 1.8, as going to check it out. Meh.

    Skionz I tried your way, works marvelously! Thanks guys for your help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page