Skip to content

Commit

Permalink
fix: make FaceIcon get its details asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Nov 14, 2023
1 parent 2987273 commit 7be6e52
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions common/src/main/java/dev/ftb/mods/ftblibrary/icon/FaceIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,18 @@ private FaceIcon(GameProfile p) {
head = skin.withUV(8F, 8F, 8F, 8F, 64F, 64F);
hat = Icon.empty();

try {
PlayerSkin playerSkin = Minecraft.getInstance().getSkinManager().getOrLoad(profile).get();
var texture = playerSkin.texture();
skin = new ImageIcon(texture);
head = skin.withUV(8F, 8F, 8F, 8F, 64F, 64F);
hat = skin.withUV(40F, 8F, 8F, 8F, 64F, 64F);
} catch (Exception ex) {
LOGGER.warn("Failed to load skin for " + profile.getName());
}
// playerSkin.registerSkins(profile, (type, resourceLocation, minecraftProfileTexture) -> {
// if (type == MinecraftProfileTexture.Type.SKIN) {
// skin = new ImageIcon(resourceLocation);
// head = skin.withUV(8F, 8F, 8F, 8F, 64F, 64F);
// hat = skin.withUV(40F, 8F, 8F, 8F, 64F, 64F);
// }
// }, true);
Minecraft.getInstance().getSkinManager().getOrLoad(profile).whenComplete((playerSkin, throwable) -> {
if (playerSkin != null) {
var texture = playerSkin.texture();
skin = new ImageIcon(texture);
head = skin.withUV(8F, 8F, 8F, 8F, 64F, 64F);
hat = skin.withUV(40F, 8F, 8F, 8F, 64F, 64F);
} else if (throwable != null) {
LOGGER.warn("Failed to load skin for {}: {} ", profile.getName(), throwable.getMessage());
} else {
LOGGER.warn("Failed to load skin for {} ?", profile.getName());
}
});
}

@Override
Expand Down

0 comments on commit 7be6e52

Please sign in to comment.