Skip to content

Commit

Permalink
Workaround name looksups and fallback skins
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAcPT committed Aug 2, 2024
1 parent e621000 commit e621000
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions nmsr-aas/src/model/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use nmsr_rendering::high_level::types::PlayerPartTextureType;
use std::{collections::HashMap, sync::Arc};
use strum::EnumCount;
use tracing::{instrument, trace_span, Instrument, Span};
use uuid::Uuid;

pub mod default_skins;
pub mod geyser;
Expand Down Expand Up @@ -403,36 +404,49 @@ impl RenderRequestResolver {
let resolved = self.resolve_raw(request).await;

// TODO: Clean-up this code.
if let (Err(_), RenderRequestEntry::MojangPlayerUuid(uuid)) = (&resolved, &request.entry) {
if let Err(_) = &resolved {
if self
.mojang_requests_client
.mojank_config()
.use_default_skins_when_missing
{
let optional_slim_model = request.model.map(|m| m == RenderRequestEntryModel::Alex);
let uuid = match &request.entry {
RenderRequestEntry::GeyserPlayerUuid(u)
| RenderRequestEntry::MojangOfflinePlayerUuid(u)
| RenderRequestEntry::MojangPlayerUuid(u) => Some(*u),
RenderRequestEntry::TextureHash(_) | RenderRequestEntry::PlayerSkin(_, _) => {
None
}
RenderRequestEntry::MojangPlayerName(_) => Some(Uuid::new_v4()),
};

let (default_skin, is_default_slim) =
DefaultSkinResolver::resolve_default_skin_for_uuid_parts(
*uuid,
optional_slim_model,
);
if let Some(uuid) = uuid {
let optional_slim_model =
request.model.map(|m| m == RenderRequestEntryModel::Alex);

let new_entry =
RenderRequestEntry::default_skin_hash(default_skin, is_default_slim);
let (default_skin, is_default_slim) =
DefaultSkinResolver::resolve_default_skin_for_uuid_parts(
uuid,
optional_slim_model,
);

// I didn't really want to clone the entire request, but I don't see a way around it.
let mut new_request = request.clone();
new_request.entry = new_entry;
let new_entry =
RenderRequestEntry::default_skin_hash(default_skin, is_default_slim);

let mut result = self.resolve_raw(&new_request).await?;
// Hijhack the model to be the same as the original request.
result.model = if is_default_slim {
RenderRequestEntryModel::Alex
} else {
RenderRequestEntryModel::Steve
};
// I didn't really want to clone the entire request, but I don't see a way around it.
let mut new_request = request.clone();
new_request.entry = new_entry;

let mut result = self.resolve_raw(&new_request).await?;
// Hijhack the model to be the same as the original request.
result.model = if is_default_slim {
RenderRequestEntryModel::Alex
} else {
RenderRequestEntryModel::Steve
};

return Ok(result);
return Ok(result);
}
}
}

Expand Down

0 comments on commit e621000

Please sign in to comment.