Skip to content

Commit

Permalink
Fix capes of a *smaller* size throwing an error (GeyserMC#1998)
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy authored Mar 4, 2021
1 parent e0e435f commit f926b83
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,22 @@ private static byte[] requestImage(String imageUrl, CapeProvider provider) throw

// if the requested image is a cape
if (provider != null) {
if (image.getWidth() > 64) {
if (image.getWidth() > 64 || image.getHeight() > 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 if (image.getWidth() < 64 || image.getHeight() < 32) {
// Bedrock doesn't like smaller-sized capes, either.
BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_ARGB);
Graphics g = newImage.createGraphics();
g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
g.dispose();
image.flush();
image = newImage;
}
} else {
// Very rarely, skins can be larger than Minecraft's default.
Expand Down

0 comments on commit f926b83

Please sign in to comment.