Take overlay renders into account for caching skin parts
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Has been cancelled

This commit is contained in:
Braydon 2024-04-11 04:38:59 -04:00
parent 16e23e82f9
commit 5f37b6b768
2 changed files with 7 additions and 7 deletions

@ -43,7 +43,7 @@ public final class CachedSkinPartTexture implements Serializable {
* The id of this cache element. * The id of this cache element.
* <p> * <p>
* This ID is in the given format: * This ID is in the given format:
* skinPart:<query>-<part>-<size>-<ext> * skinPart:<query>-<part>-<renderOverlays>-<size>-<ext>
* </p> * </p>
*/ */
@Id private transient final String id; @Id private transient final String id;

@ -192,24 +192,24 @@ public final class MojangService {
size = DEFAULT_PART_TEXTURE_SIZE; size = DEFAULT_PART_TEXTURE_SIZE;
} }
size = Math.min(size, MAX_PART_TEXTURE_SIZE); // Limit the size to 512 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<CachedSkinPartTexture> cached = skinPartTextureCache.findById(id); // Get the cached texture Optional<CachedSkinPartTexture> cached = skinPartTextureCache.findById(id); // Get the cached texture
if (cached.isPresent()) { // Respond with the cache if present if (cached.isPresent()) { // Respond with the cache if present
return cached.get().getTexture(); 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 { try {
CachedPlayer player = getPlayer(query, false); // Retrieve the player 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) { } catch (Exception ignored) {
// Simply ignore, and fallback to the default skin // Simply ignore, and fallback to the default skin
} }
if (target == null) { // Fallback to the default skin if (skin == null) { // Fallback to the default skin
target = Skin.DEFAULT_STEVE; 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 // Convert BufferedImage to byte array
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {