From 5f37b6b768816c3e9b934187e57408758d8d6112 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Thu, 11 Apr 2024 04:38:59 -0400 Subject: [PATCH] Take overlay renders into account for caching skin parts --- .../mc/model/cache/CachedSkinPartTexture.java | 2 +- .../java/me/braydon/mc/service/MojangService.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/braydon/mc/model/cache/CachedSkinPartTexture.java b/src/main/java/me/braydon/mc/model/cache/CachedSkinPartTexture.java index 1bfe48a..c90b8d7 100644 --- a/src/main/java/me/braydon/mc/model/cache/CachedSkinPartTexture.java +++ b/src/main/java/me/braydon/mc/model/cache/CachedSkinPartTexture.java @@ -43,7 +43,7 @@ public final class CachedSkinPartTexture implements Serializable { * The id of this cache element. *

* This ID is in the given format: - * skinPart:--- + * skinPart:---- *

*/ @Id private transient final String id; diff --git a/src/main/java/me/braydon/mc/service/MojangService.java b/src/main/java/me/braydon/mc/service/MojangService.java index 28d5bc0..ff932dc 100644 --- a/src/main/java/me/braydon/mc/service/MojangService.java +++ b/src/main/java/me/braydon/mc/service/MojangService.java @@ -192,24 +192,24 @@ public final class MojangService { size = DEFAULT_PART_TEXTURE_SIZE; } size = Math.min(size, MAX_PART_TEXTURE_SIZE); // Limit the size to 512 - String id = "%s-%s-%s-%s".formatted(query.toLowerCase(), part.name(), size, extension); // The id of the skin part + String id = "%s-%s-%s-%s-%s".formatted(query.toLowerCase(), part.name(), overlays, size, extension); // The id of the skin part Optional cached = skinPartTextureCache.findById(id); // Get the cached texture if (cached.isPresent()) { // Respond with the cache if present return cached.get().getTexture(); } - Skin target = null; // The target skin to get the skin part of + Skin skin = null; // The target skin to get the skin part of try { CachedPlayer player = getPlayer(query, false); // Retrieve the player - target = player.getSkin(); // Use the player's skin + skin = player.getSkin(); // Use the player's skin } catch (Exception ignored) { // Simply ignore, and fallback to the default skin } - if (target == null) { // Fallback to the default skin - target = Skin.DEFAULT_STEVE; + if (skin == null) { // Fallback to the default skin + skin = Skin.DEFAULT_STEVE; } - BufferedImage texture = part.render(target, overlays, size); // Render the skin part + BufferedImage texture = part.render(skin, overlays, size); // Render the skin part // Convert BufferedImage to byte array try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {