[solved] Whats the difference between entity.getUniqueId() and entity.getEntityId()?

Discussion in 'Plugin Development' started by phondeux, Jun 1, 2012.

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

    phondeux

    I'm making a plugin to add some sfx to some mobs and need to single out specific ones. I need to know which id is the proper one to use to keep track of the mobs.

    Specifically, I want to check onspawn, give a mob a 1 in 10 chance of being unique, then give that unique mob a sfx while it exists. Is there a better way to track mobs then making a list of entity id's and periodically looping through them and grabbing the entity location and applying the sfx?

    Maybe I should just make a List<Entity> instead?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  2. Offline

    Njol

    The unique id is persistent across server restarts while the entity id is not. An Entity object is also not persistent across server restarts as it uses the entity id as identifier.
    I suggest to make a Set<UUID> of the unique ids of the mobs, as this can easily be saved & loaded.

    If you want to apply potion effects of any color to mobs you should read this thread: How to create the swirly particle potion effect
     
    com. BOY and phondeux like this.
  3. Offline

    phondeux

    What do you mean that the UUID can easily be saved and loaded? What is the UUID, anyway? I saw that as a return value on getUniqueId() but was uncertain of how to use it. Is it just a long int or alphanumeric string?

    Also, once I have the uniqueid how do I grab the mob again?
     
  4. Offline

    Njol

    It's an UUID
    I just realized that there is not such method as world.getEntity(id) - so I guess you'll have to loop through all loaded entities and compare their UUID with the ones you have stored.
    But depending on what you want to do you might not even need to do this, but can e.g. only check an entity's UUID on death and make something happen if it is contained in the list.
    And for reapplying the effects you would have to check newly loaded entities no matter how you store them, as not all entities are loaded when the world loads. This might also be the reason why there's no method to get an entity from it's id.
     
    phondeux likes this.
  5. Offline

    phondeux

    Thanks for answering all my questions njol!
     
Thread Status:
Not open for further replies.

Share This Page