Getting a unique entity id and "registering" it

Discussion in 'Plugin Development' started by iKeirNez, Nov 10, 2013.

Thread Status:
Not open for further replies.
  1. I'm messing about with packets just now and want to find out how to get a unique entity id (one that hasn't been used.) I know you can use

    1. new Random().nextInt(Integer.MAX_VALUE);

    But that isn't always guaranteed to be an unused entity id. Even if it isn't being used at the time, what's to stop an entity being spawned in later with the same entity id? I don't want another entity using the same id as it'll make the server/clients crash or error.

    So what I would like to know is how do I get an unused entity id and prevent it from being used from entities spawning? I don't mind if it uses anything hacky like Reflection as my project already uses that.

  2. Offline


    Why don't you use UUID? I believe you can get it with .getUniqueEntityID()

  3. Because it needs to be an entity id, packets only accept entity ids, not UUIDs
  4. Offline


    why would you need an unique entity is using packets? What are you trying to do? And why can't you just use a list storing the ints you already used?
  5. It's for faking a wither spawn, you need to send it's id, it's not about ids that I use, it's about other things such as vanilla minecraft I don't want using them.
  6. Offline


    Idk can you parse an UUID to an int?
  7. I have no issue generating one, but I need one that isn't being used and will never be used by anything else. It's fine though, I found out I can use -1 as the entity id
  8. Offline


    You can always use -player.getEntityId() for client side packet hackery if you need an unused entity id, and it'll be unique for each player!
    joserobjr likes this.
  9. Good point, didn't think of that. Cheers
Thread Status:
Not open for further replies.

Share This Page