Skip to content

Commit

Permalink
Fix capes being scaled wrong and invisible skins (GeyserMC#1940)
Browse files Browse the repository at this point in the history
* Fix capes being scaled wrong and invisible skins

* Flush old image objects

* Remove alpha workaround and fix more scaling issues

* Remove unnecessary scale

* Reduce diff

Co-authored-by: Camotoy <[email protected]>
  • Loading branch information
rtm516 and Camotoy authored Mar 3, 2021
1 parent e4e9758 commit e0e435f
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,23 @@ private static byte[] requestImage(String imageUrl, CapeProvider provider) throw
// if the requested image is a cape
if (provider != null) {
if (image.getWidth() > 64) {
image = scale(image, 64, 32);
// Prevent weirdly-scaled capes from being cut off
BufferedImage newImage = new BufferedImage(128, 64, BufferedImage.TYPE_INT_ARGB);
Graphics g = newImage.createGraphics();
g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
g.dispose();
image.flush();
image = scale(newImage, 64, 32);
}
} else {
// Very rarely, skins can be larger than Minecraft's default.
// Bedrock will not render anything above a width of 128.
if (image.getWidth() > 128) {
image = scale(image, 128, image.getHeight() / (image.getWidth() / 128));
// On Height: Scale by the amount we divided width by, or simply cut down to 128
image = scale(image, 128, image.getHeight() >= 256 ? (image.getHeight() / (image.getWidth() / 128)) : 128);
}

// TODO remove alpha channel
}

byte[] data = bufferedImageToImageData(image);
Expand Down

0 comments on commit e0e435f

Please sign in to comment.