Jump to content

Recommended Posts

Posted (edited)

I've been trying to make a mod where you could "steal" parts of the player, and get them as items, but I've run into a problem: I don't have a single clue on how to get player's skin texture, nor how to apply it to the item model. I tried to seek examples on this forum and even look up how SkullBlockRenderer class works, but I didn't find an exact answer to my question anywhere

Edited by AppleBeanie
  • AppleBeanie changed the title to [1.20.1] Getting players skin texture by their UUID
  • 2 months later...
Posted

Just a few months ago I was creating my own plugin for Minecraft 1.20.2 spigot that did the same thing, but the skins were not saved, if you can understand this code that I made a long time ago it may help you.

 

//This is a class method
	private static String APIRequest(String value, String url, String toSearch) {
        try {
            URL api = new URL(url + value);
            HttpURLConnection connection = (HttpURLConnection) api.openConnection();

            connection.setRequestMethod("GET");

            int responseCode = connection.getResponseCode();

            if (responseCode == HttpURLConnection.HTTP_OK) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

                StringBuilder response = new StringBuilder();

                for (String responseChar; (responseChar = reader.readLine()) != null; ) response.append(responseChar);

                reader.close();

                JSONObject responseObject = new JSONObject(response.toString());

                if (!toSearch.equals("id"))
                    return responseObject
                            .getJSONArray("properties")
                            .getJSONObject(0)
                            .getString("value");
                else return responseObject.getString("id");
            }
            else {
                AntiGianka.ConsoleMessage(ChatColor.RED, String.format(
                        "Could not get %s. Response code: %s",
                        ((toSearch.equals("id")) ? "UUID" : "texture"),
                        responseCode
                ));
            }
        } catch (MalformedURLException error) {
            AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error);
        } catch (IOException error) {
            AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while attempting to connect to the URL. Error: " + error);
        }
        return "";
    }

//other class method
    private void SkinGetter() {
        String uuid;
        String textureCoded;

        if ((uuid = APIRequest(args[0], "https://api.mojang.com/users/profiles/minecraft/", "id")).isEmpty() ||
                (textureCoded = APIRequest(uuid, "https://sessionserver.mojang.com/session/minecraft/profile/", "value")).isEmpty()
        ) sender.sendMessage(ChatColor.RED +
                String.format(
                        "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.",
                        args[0], args[0]
                )
        );
        else SkinSetter(textureCoded);
    }

//other more
    private void SkinSetter(String textureCoded) {
        JSONObject profile = new JSONObject(new String(Base64.getDecoder().decode(textureCoded)));

        try {
            URL textureUrl = new URL(profile.getJSONObject("textures").
                    getJSONObject("SKIN").
                    getString("url"));

            if (sender instanceof Player && args.length == 1) {
                PlayerTextures playerTextures = ((Player) sender).getPlayerProfile().getTextures();
                playerTextures.setSkin(textureUrl);

                ((Player) sender).getPlayerProfile().setTextures(playerTextures);

                if (((Player) sender).getPlayerProfile().getTextures().getSkin() != null) sender.sendMessage(((Player) sender).getPlayerProfile().getTextures().getSkin().toString());
                else sender.sendMessage("Null");

                sender.sendMessage("Skin changed successfully.a");
            }
            else {

            }
            AntiGianka.ConsoleMessage(ChatColor.GREEN, "Skin command executed successfully.");
        } catch (MalformedURLException error) {
            sender.sendMessage(ChatColor.RED +
                    String.format(
                            "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.",
                            args[0], args[0]
                    )
            );
            AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error);
        }
    }

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

×
×
  • Create New...

Important Information

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