A list of skin component coordinates and the Mojang API.
Mojang provides a very simple JSON API for retrieving information about any player in their database. The response format is very straightforward, but the status codes can be confusing and sometimes not match what was actually returned. Please read this documentation carefully to understand how to interact with their API.
If you already have the UUID of the player, you can go ahead and skin this step. This request is made to convert a player's username into a UUID, a unique string of characters identifying a specific player regardless of how many times they have changed their username.
Retrieve UUID by Username
By using the UUID from response in the
idfield in the request made above, you can now retrieve the profile information for the player by making another request to their session server. A UUID with or without dashes will still yield the same result.
Retrieve Profile by UUID
The response value from the request made above contains a
propertiesvalue, which is an array of objects. You will need to filter through the code above to find which object has the
nameproperty set to
"textures". It is not a good idea to just select the first value in the array because it may change at any time in the future. Here is some sample code on how to find the correct value:
value = ""
for property in response.properties:
if property.name != "textures":
value = property.value
if len(value) < 1:
raise Exception("'textures' property was not found in response")
All player lookups using this method should contain a textures property. If the player does not contain a textures property for some odd reason, you should instead use the default regular (Steve) skin. The contents of the
valuevariable is Base64-encoded (standard encoding) JSON. You will need to refer to your language's standard or third party libraries to figure out how to decode it. For this example, I will continue using Python as it is simple to read and convert to other languages.
valuevariable that we found above, you will need to decode from Base64 to UTF-8. This can be done using something like this:
decoded_value = base64.b64decode(value).decode('utf-8')
The value of this
decoded_valuevariable will be a JSON object, but still in string format. You will need to load this value into an actual object that we can use:
parsed_value = json.loads(decoded_value)
The value of
parsed_valuewill now look something like this:
The result above is from a player with a regular (Steve) model skin, which uses 4 pixel wide arms. Minecraft also has another variant of skin which is a slim (Alex) model. This variant uses 3 pixel wide arms. If the model has a slim variant, the response will contain extra metadata properties:
You will need to check to see if the
modelvalue is set to
slimunder the metadata property if you wish to use the player skin for rendering images, or else you will overlap skin components. You can now make a request to the
textures.SKIN.urlvalue to get the player's skin as a PNG image. This image should either be 64×64 or 64×32 (old skins).
If you encounter an older skin format (which can be checked if the height of the skin image is 32 pixels), then you will need to do a bit of fiddling to get the components to be extracted properly. In Minecraft versions before 1.8, there was no dedicated skin texture for the left arms and legs. Instead, Minecraft used the corresponding component from the right side and flipped the image horizontally. There was also no overlay (or 2nd layer), which is why the image is only 32 pixels tall instead of the typical 64 pixels in modern formats.
In some skins uploaded to Minecraft, the image contains opaque pixels where there should be transparency (such as the overlay components). In order to fix the transparency issue, you will need to parse the PNG image into a format that allows you to modify pixel data individually. There should be a built-in or third party library in your language to do this. Here are the steps to fixing the transparency issue:
- 1.Look at the color and alpha value of the pixel at
(0, 0)(aka alpha signature)
- 2.Loop over all pixels in the image and compare them to the value retrieved from step 1
- 1.If the R, G, B and alpha values match the alpha signature, then set the alpha value for this current pixel to 255 (or fully opaque).
- 2.If any of the R, G, B or alpha values do not match the alpha signature, do not change this pixel and move to the next.
- 3.Save this modified skin image as a new variable, separate from the original skin image retrieved from Minecraft.
This second alpha-fixed image will only be used for rendering the overlay layer. You will still use the original image for any base layer components.