Skip to content

Instantly share code, notes, and snippets.

@CatDany
Last active April 20, 2023 23:14
Show Gist options
  • Save CatDany/0e71ca7cd9b42a254e49 to your computer and use it in GitHub Desktop.
Save CatDany/0e71ca7cd9b42a254e49 to your computer and use it in GitHub Desktop.
Minecraft Authentification UUID System Explained (How does Minecraft UUID system work?)
> Since 1.7 came out, there's a "GameProfile" assigned to every player now. You can get GameProfile of a player by using EntityPlayer.getGameProfile(). Yeah, with that said, you probably still wonder how does Minecraft UUID system work. Let me start explaining that.
>>>>>>>>>>>>>>>>>>>>>>>> DISCLAIMER! <<<<<<<<<<<<<<<<<<<<<<<<
>> 1. English is not my main language, I could make mistakes
>> 2. I could be wrong.
1. UUID in Java
> There's a concept of Universally Unique Identifier. If you're not familiar with it, try reading that*. If you have no time (too lazy) to read it, I'm going to cut a long story short here. UUID is an ID made out of 128 bits (16 bytes, 2 longs). It's called "unique" because the random number generator used when doing UUID.randomUUID() is very strong. According to wikipedia "only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%", so yeah, pretty strong. UUIDs can be converted to hexadecimal string and backwards. They can also be generated from any amount of bytes as a random seed(UUID.nameUUIDFromBytes(byte[])), that's what Minecraft uses to get UUIDs from account / nickname.
2. Getting UUID from player's account
> There's a UUID assigned with every Minecraft account. When the player enters the game, session id, as well as account UUID, is provided in program arguments. Then it converts into a real UUID by using UUID.fromString(arg). This UUID will be sent to the server when the played connects to it, identificator is also used in constructor of a GameProfile (new GameProfile(UUID, username)).
3. Getting UUID from an offline player
> Remember, I mentioned UUID.nameUUIDFromBytes(byte[])? Minecraft generates an offline UUID from bytes of string "OfflinePlayer:<nickname>", in other words: "UUID.nameUUIDFromBytes(("OfflinePlayer:" + getName()).getBytes(Charsets.UTF_8)". That's why when you change "online-mode" in settings.properties, everyone loses their inventories and player infos. UUID is changed, so it leads to another file in "playerdata" folder of your world.
That's probably all the explanation of this whole UUID auth system.
Source:
> Me researching minecraft sources while I'm modding
* https://en.wikipedia.org/wiki/Universally_unique_identifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment