mcapi 0.2.0

Unified async Rust client for the Minecraft ecosystem (Mojang, Modrinth, CurseForge, Yggdrasil, Blessing Skin, Loaders, Java Runtimes, and SLP)
Documentation
use serde::{Deserialize, Serialize};

pub use crate::profile::{
    ProfileProperty, TextureEntry, TextureMetadata, TextureType, TexturesPayload,
};

use crate::error::{Error, Result};
use crate::profile::decode_textures_property;
use crate::uuid::McUuid;

/// A Minecraft player profile returned by Yggdrasil authentication or session endpoints.
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct GameProfile {
    pub id: McUuid,
    pub name: String,
    #[serde(default)]
    pub properties: Vec<ProfileProperty>,
}

impl GameProfile {
    /// Decodes the Base64 `textures` property payload if present.
    pub fn decode_textures(&self) -> Result<TexturesPayload> {
        decode_textures_property(&self.properties)?.ok_or(Error::MissingTexturesProperty)
    }
}

/// Minimal profile entry returned by `POST /api/profiles/minecraft`.
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ProfileLookupEntry {
    pub id: McUuid,
    pub name: String,
}

/// Skin arm geometry model.
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
pub enum SkinModel {
    #[default]
    #[serde(rename = "default", alias = "")]
    Classic,
    #[serde(rename = "slim")]
    Slim,
}

impl SkinModel {
    /// Returns the form field value expected by Yggdrasil texture upload endpoints.
    pub const fn as_form_value(self) -> &'static str {
        match self {
            SkinModel::Classic => "",
            SkinModel::Slim => "slim",
        }
    }
}