Get entity by id

Discussion in 'Plugin Development' started by phips99, Aug 25, 2013.

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

    phips99

    Hey,
    I already tried this with a loop. I loop through every single entity in a chunk and if an entity has a specific entity id I do my stuff. But is there another way to get a specific entity by the id?
     
  2. Offline

    KevoSoftworks

    phips99

    You can try to get the entity by it's uuid. I believe there is a function for that (called from a world), but I'm not too sure.
     
  3. Offline

    phips99

    KevoSoftworks Nope the only method which returns an Entity is the spawnEntity method...
     
  4. phips99
    This should work just fine.
    Code:
    Chunk c = null; // = someChunk;
    UUID id = null; // = someUUID;
     
    for (Entity e: c.getEntities()) {
        if (e.getUniqueId() == id) {
            // stuff
        }
    }
     
  5. Offline

    KevoSoftworks

    phips99

    hmm, then your only option is looping through the enities in a world.
    However, if you spawn the entities by yourself, you could store their id in a List or Map, and call them from there, which saves some resources.

    Assist
    The OP asked for a way without a loop, but you are right about that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. KevoSoftworks
    Yeah, sorry. Noticed it right after I posted that.

    They should make a getEntityById() method in World class, though that would be the same as looping through them and comparing ids.
     
Thread Status:
Not open for further replies.

Share This Page