2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【minecraft】自作カスタムヘッドURLの作り方

Last updated at Posted at 2020-02-11

はじめに・・・

Minecraftでは建築などに用いられるカスタムヘッドというものが存在する。

プラグイン開発をしているとこれがとても便利なのでその使い方を説明しておく。

それを自作する方法があるのでそれを紹介していく。

1.まずはスキンを描こう。

描くのは頭部のみ。

簡単でしょ?

まずは以下のスキンをダウンロードして描いてね。
[Steave] [Alex]

完成したら自分のMinecraftアカウントに割り当てましょう。

2.UUIDを取得

MinecraftにはMCIDとは別にそのアカウントにあてられた変更できないUUIDというものがあります。

それを取得する必要があるのでNameMCにアクセスしてMCIDで検索します。
alt
名前 | UUID | サーバーアドレス | スキンという部分に自分のMCIDを書き込み検索してください。

たいてい1項目しかヒットしませんがもし複数ヒットした場合は自分のプロフィールを選択してください。

Minecraft プロフィール内のUUIDの2段目、-で区切られていないほうをコピーしておきましょう。

3.スキンを取得

<UUID>を先ほどコピーしておいたものに置き換えURLにアクセスします。
https://sessionserver.mojang.com/session/minecraft/profile/<UUID>

{"id":"1c2b6991e8ce4e5db4d8ec3f0cdc5f8e","name":"Monster2408","properties":[{"name":"textures","value":"eyJ0aW1lc3RhbXAiOjE1ODE0NDIzNTI2OTksInByb2ZpbGVJZCI6IjFjMmI2OTkxZThjZTRlNWRiNGQ4ZWMzZjBjZGM1ZjhlIiwicHJvZmlsZU5hbWUiOiJNb25zdGVyMjQwOCIsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS80ZDQ5NzFiNzFlMzBlMzJjNGJkNzY5YWEzMTk5Y2U3YmJmNmU1YmQ2YzlmNGYxYjAyNjEzNzkyYmQ4MzJkOWUwIn19fQ=="}]}

こちらがわたくしの取得したものですが、"value"というものが含まれております。このあとの"から"の間をコピーします。

BASE64にデコード

BASE64にアクセスします。
Type (or paste) here...に先ほどコピーしたIDを貼り付けます。

< DECODE >というボタンをクリックして下のボックスるからhttp://から始まるURLを取得します。
私が取得したURL↓
http://textures.minecraft.net/texture/c30a08a2e7d77cc58c2ef05b18560f5abcc45a04c6ec38f76b43135aa36db034

実際に使用してみる

CustomHead.java
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import org.apache.commons.codec.binary.Base64;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import java.lang.reflect.Field;
import java.util.UUID;

public class CustomHead {
    public static ItemStack getSkull(String url) {
        ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
        if(url.isEmpty())return head;

        SkullMeta headMeta = (SkullMeta) head.getItemMeta();
        GameProfile profile = new GameProfile(UUID.randomUUID(), null);
        byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
        profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
        Field profileField = null;
        try {
            profileField = headMeta.getClass().getDeclaredField("profile");
            profileField.setAccessible(true);
            profileField.set(headMeta, profile);
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
            e1.printStackTrace();
        }
        head.setItemMeta(headMeta);
        return head;
    }
}

あとはCustomHead.getSkull("URL")で取得するのみ。

さいごに

暇があったらコマンドで取得する方法調べときます(その時は追記します。)

じゃあ、おつ~

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?