Jump to content

[1.10.2] downloading and applying player skins


Maxk

Recommended Posts

I have a link that gives out custom skins based on player name, e.g. "http://myserver/skins/name.png". The mod is client side, I need it to download the skin for a player from this link, store it somewhere (cache it?) and use it for rendering players. Here is what I have:

 

public class mySkins{

    Minecraft mc;
    public static String skinsURL = "http://myserver/skins/%s.png";
    public HashMap<String,ResourceLocation> skins = new HashMap<>();

    ...

@SubscribeEvent
public void onMyEvent(RenderPlayerEvent.Pre event){
    AbstractClientPlayer acp = (AbstractClientPlayer)event.getEntityPlayer();
    if (skins.containsKey(acp.getName())){
    } else {
        System.out.println("downloadskin started " + acp.getName() + " " + acp.getLocationSkin());

        ThreadDownloadImageData tdid = new ThreadDownloadImageData(
                (File)null,
                String.format(skinsURL,acp.getName()),
                acp.getLocationSkin(),
                new ImageBufferDownload());

        mc.getTextureManager().loadTexture(acp.getLocationSkin(),tdid);
        skins.put(acp.getName(),acp.getLocationSkin());
        System.out.println("downloadskin ended");
    }
}

 

This does download proper skin but applies it to "minecraft:textures/entity/alex.png", obviously. So basically this only shows that link and download is working fine.

 

I need to

1.  cache downloaded skin and get its ResourceLocation

2.  apply this ResourceLocation while rendering player

 

Now if I go like this

@SubscribeEvent
public void onMyEvent(RenderPlayerEvent.Pre event){
    AbstractClientPlayer acp = (AbstractClientPlayer)event.getEntityPlayer();
    if (skins.containsKey(acp.getName())){
        //i want to somehow appply skins.get(acp.getName())
    } else {
        System.out.println("downloadskin started " + acp.getName() + " " + acp.getLocationSkin());
        ResourceLocation res = new ResourceLocation("myskins/" + acp.getName().toLowerCase() + ".png");
        ThreadDownloadImageData tdid = new ThreadDownloadImageData((File)null,String.format(skinsURL,acp.getName()),res,new ImageBufferDownload());
        mc.getTextureManager().loadTexture(res,tdid);
        skins.put(acp.getName(),res);
        System.out.println("downloadskin ended");
    }
}

 

it gives NullPointer at loadTexture

 

[18:28:01] [Client thread/WARN]: Failed to load texture: minecraft:myskins/nickname.png
java.io.FileNotFoundException: minecraft:myskins/nickname.png

 

How do I go about this? I've tried changing first File argument in new ThreadDownloadImageData to non-null, also tried different ResrourceLocation's for res and still cant get it to work. To clarify, I dont need skins to be stored on hard drive, but only cached in memory while minecraft is running, so basically every time client joins the game, it will redownload skins for every player he meets

Link to comment
Share on other sites

2 hours ago, diesieben07 said:

Don't make custom skins.

Can I have more details on this? Should I not do this because it is against the rules or because it is not possible? 

Edited by Maxk
Link to comment
Share on other sites

Out of my depth here. But if not possible to change skin directly (never looked into it)....

 

CarryOn and metamorph (both on github) use models to change how the client renders the player.  So, you could create a custom player model based on image or if not that many, server could return index to prefabs in your mod and simply (morph) player to use that model.

 

 

Edited by aw_wolfe
Link to comment
Share on other sites

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.