Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download player_head/skull texture even if no owner name present #162

Merged
merged 1 commit into from
Jul 31, 2021

Conversation

remiscarlet
Copy link
Contributor

Hi there.

I'm really not much of a Java person but I did want to fix a small functionality bug that wasn't captured as part of #156's fix. Please let me know if there are any "Java-isms" I'm not following or any other feedback. Happy to revise this PR/add evidence if necessary.


While the minecraft wiki currently states "Name: Username of owner. If missing or empty, the head appears as a Steve head.", this is observably incorrect.

Below are three valid player skulls where only the third one renders as the default steve head. The first one contains a texture value but no name while the second one contains both name and texture value. (Data captured via F3+I in-game)

minecraft:player_head[rotation=3]{SkullOwner:{Id:[I;-374731252,80498042,-1089022018,-75442154],Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODI5ZTg4NThlNGUwYzE3NTEzMTNlZjU4YWRhZjM0YzIxNjk4N2Y3NzhiMmI5ODQ4MWU5ZWNiOTFhNzE5NCJ9fX0="}]}}}
minecraft:player_head[rotation=13]{SkullOwner:{Id:[I;553703739,-2015082768,-1803964419,-471486417],Properties:{textures:[{Value:"ewogICJ0aW1lc3RhbXAiIDogMTYyNjQyMTc1MTcxMiwKICAicHJvZmlsZUlkIiA6ICIyMTAwZDkzYjg3ZTQ0NmYwOTQ3OWFmZmRlM2U1YjAyZiIsCiAgInByb2ZpbGVOYW1lIiA6ICJEaXZpbmVBcXVhU2FtYSIsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgInVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9iOGRkM2IwMTVjMmQxY2VmNmY2M2ExMDUzY2ZiZTdmOWY3MTRlYjFmMGZmMDdiYmQ1YjI0YzNmMGViODZhMmYyIiwKICAgICAgIm1ldGFkYXRhIiA6IHsKICAgICAgICAibW9kZWwiIDogInNsaW0iCiAgICAgIH0KICAgIH0KICB9Cn0="}]},Name:"DivineAquaSama"}}
minecraft:player_head[rotation=11]{}

This commit fixes the incorrect assumption that any valid textured player head has a Name tag as well. The downloaded texture name will use the player name if present as player_<name>.png. If no name is present, it will fall back to using the textures.minecraft.net's texture ID from the URL decoded from the B64 texture url as player_<tex_id>.png.


FWIW, I'm getting these skulls via a Bukkit/Spigot plugin - Head Database. Presumably the plugin doesn't bother adding the owner name in the NBT data since the skulls render fine without it.

While the minecraft wiki currently states "Name: Username of owner. If missing or empty, the head appears as a Steve head.", this is observably incorrect.

```
minecraft:player_head[rotation=3]{SkullOwner:{Id:[I;-374731252,80498042,-1089022018,-75442154],Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODI5ZTg4NThlNGUwYzE3NTEzMTNlZjU4YWRhZjM0YzIxNjk4N2Y3NzhiMmI5ODQ4MWU5ZWNiOTFhNzE5NCJ9fX0="}]}}}
```

```
minecraft:player_head[rotation=13]{SkullOwner:{Id:[I;553703739,-2015082768,-1803964419,-471486417],Properties:{textures:[{Value:"ewogICJ0aW1lc3RhbXAiIDogMTYyNjQyMTc1MTcxMiwKICAicHJvZmlsZUlkIiA6ICIyMTAwZDkzYjg3ZTQ0NmYwOTQ3OWFmZmRlM2U1YjAyZiIsCiAgInByb2ZpbGVOYW1lIiA6ICJEaXZpbmVBcXVhU2FtYSIsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgInVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9iOGRkM2IwMTVjMmQxY2VmNmY2M2ExMDUzY2ZiZTdmOWY3MTRlYjFmMGZmMDdiYmQ1YjI0YzNmMGViODZhMmYyIiwKICAgICAgIm1ldGFkYXRhIiA6IHsKICAgICAgICAibW9kZWwiIDogInNsaW0iCiAgICAgIH0KICAgIH0KICB9Cn0="}]},Name:"DivineAquaSama"}}
```

```
minecraft:player_head[rotation=11]{}
```

All three of the above are valid player skulls but only the third one renders with no texture in-game. The first one contains a texture value with no name while the second one does contain a name.

This commit fixes the incorrect assumption that any valid textured player head has a `Name` tag as well. The downloaded texture name will use the player name if present as `player_<name>.png`. If no name is present, it will fall back to using the textures.minecraft.net's texture ID from the URL decoded from the B64 texture url.
@remiscarlet
Copy link
Contributor Author

remiscarlet commented Jul 18, 2021

For what it's worth I tried tinkering a bit more on what constitutes a valid textured player_head and got some interesting results compared to what the minecraft wiki states.

Using the following as the base "full command" in a command block:

/setblock ~ ~1 ~ minecraft:player_head[rotation=13]{
    SkullOwner:{
        Id: [I;553703739,-2015082768,-1803964419,-471486417],
        Name:"DivineAquaSama",
        Properties:{
            textures:[
                {
                    Value: "ewogICJ0aW1lc3RhbXAiIDogMTYyNjQyMTc1MTcxMiwKICAicHJvZmlsZUlkIiA6ICIyMTAwZDkzYjg3ZTQ0NmYwOTQ3OWFmZmRlM2U1YjAyZiIsCiAgInByb2ZpbGVOYW1lIiA6ICJEaXZpbmVBcXVhU2FtYSIsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgInVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9iOGRkM2IwMTVjMmQxY2VmNmY2M2ExMDUzY2ZiZTdmOWY3MTRlYjFmMGZmMDdiYmQ1YjI0YzNmMGViODZhMmYyIiwKICAgICAgIm1ldGFkYXRhIiA6IHsKICAgICAgICAibW9kZWwiIDogInNsaW0iCiAgICAgIH0KICAgIH0KICB9Cn0="
                }
            ]
        }
    }
}

I modified the command in various ways to see if a valid textured head would be created
image

While I haven't bothered trying to modify the base64 encoded json value's contents, at the very least the condition for rendering a textured player head seems to be that so long as either SkullOwner:{Name} or SkullOwner:{Id} are present the head renders (assuming the base64 string
is valid).

name = ((TAG_String)nameNbt).value;
} else {
String url = extractSkullOwnerTextureUrl(textureB64);
name = url.substring(url.lastIndexOf('/') + 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmdanggg2
Copy link
Collaborator

Nice work, thanks for the PR. I'll try and quickly test it out soon.

@mmdanggg2 mmdanggg2 merged commit b93ef97 into jmc2obj:master Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants