SkinUtils.java 1.54 KB
Newer Older
1 2 3 4 5 6 7
package com.owlmaddie.skin;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.AbstractTexture;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.util.Identifier;

8 9 10 11
/**
 * SkinUtils contains functions to check for certain black and white pixel values in a skin, to determine
 * if the skin contains a custom hidden icon to show in the player chat message.
 */
12 13
public class SkinUtils {
    public static boolean checkCustomSkinKey(Identifier skinId) {
14
        // Grab the AbstractTexture from the TextureManager
15 16
        AbstractTexture tex = MinecraftClient.getInstance().getTextureManager().getTexture(skinId);

17
        // Check if it implements our Mixin interface: IPlayerSkinTexture
18
        if (tex instanceof IPlayerSkinTexture iSkin) {
19
            // Get the NativeImage we stored in the Mixin
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
            NativeImage image = iSkin.getLoadedImage();
            if (image != null) {
                int width = image.getWidth();
                int height = image.getHeight();

                // Check we have the full 64x64
                if (width == 64 && height == 64) {
                    // Example: black & white pixel at (31,48) and (32,48)
                    int color31_48 = image.getColor(31, 49);
                    int color32_48 = image.getColor(32, 49);
                    return (color31_48 == 0xFF000000 && color32_48 == 0xFFFFFFFF);
                }
            }
        }

        // If it's still loading, or not a PlayerSkinTexture, or no NativeImage loaded yet
        return false;
    }
}