Jump to content

[SOLVED][1.7.10] Accessing ResourceLocation of player's skin while not ingame


Recommended Posts

Posted

So, I'm building a GUI, and for the mod I'm creating, I need to access the current player's skin as a ResourceLocation object. The getLocationSkin() function within the AbstractClientPlayer class is returning nulls, most likely because the player object hasn't been initialized (my GUI is accessed from the main menu).

My question is: how can I get a ResourceLocation of the current player's skin, even from the main menu?

The reason I want a ResourceLocation is so that I can use TextureUtil.readImageData(ResourceManager,ResourceLocation) to break it up into an int array.

Also two other simple side questions: how do you access the current player's name within code (e.g. ForgeDevName) and is it possible to change the default name to a different name for testing purposes?

Thanks for any help.

 

Posted

1. AbstractClientPlayer#getLocationSkin is just a method to get the buffered player skin (so when you join a world the first time, the ResourceLocation gets buffered there). To get the player skin independent from the actual player entity, you'll need to do this:

- Create a new GameProfile instance with the first parameter being null and the second one the player name; save this in a variable

- Get the profile map from

Minecraft.getMinecraft().func_152342_ad().func_152788_a(myGameProfile)

and save it as a variable, too, where myGameProfile is the variable from before

- Check the map if it contains the key

Type.SKIN

, where Type is an enum from the

com.mojang.authlib.minecraft

package

- If it does, get the ResourceLocation by calling the method

minecraft.func_152342_ad().func_152792_a((MinecraftProfileTexture)map.get(Type.SKIN), Type.SKIN)

which returns one.

- If it doesn't, use the default steve skin with

AbstractClientPlayer.locationStevePng

 

2.

Minecraft.getMinecraft().getSession().getUsername()

3. I believe by adding --username "MyDesiredUsername" to the JVM arguments, but I can be wrong.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

The code fits in perfectly, thanks for the help! There's only one problem; profmap.get(Type.SKIN) keeps returning false, even when I the flag to change the username to my own (which also works fine, I might add). Changing the --username and --password flags to my credentials also returns false. I'm not sure whether there is a problem in my code, or the skin simply doesn't download due to the fact that it's in a development environment. In case there's something wrong, I've made a pastebin link: http://pastebin.com/P1Vvph6V

Also, I'll be sure to make a mental note of the answers to the other two questions. Thanks for all the help so far!

Posted

I noticed that, too, when you have a player head and place it / put it on, it shows the default skin in dev mode.

Try to compile it and see if it works on a "real" environment.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Compiling it didn't seem to work. I used some logging to figure out that GameProfile game does have my username, Rockdude101, inside its instance, but the profile Map still isn't returning true. I changed the if statement to always be true, and sure enough, there was a NullPointerException at this line in SkinManager.func_152789_a:

 

final ResourceLocation resourcelocation = new ResourceLocation("skins/" + p_152789_1_.getHash());

 

The problem spot in my code is probably this line, in that case:

 

Map profmap = mc.func_152342_ad().func_152788_a(game);

 

I'm finding it very difficult to understand this piece of code, due to the complex structure of it, so any insight on this would be any helpful.

  • 2 months later...
Posted

This thread has been inactive for quite a while, but I managed to find a solution. Basically, I used some of the code from ThreadDownloadImageData.func_152433_a() to get a BufferedImage, and simply ran the code from TextureUtils.readImageData(), without the first line, to get the int[] I wanted.

Here's a link to the pastebin: http://pastebin.com/fzWmheB9

Also, let me know if there are any major mistakes in the code.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.