Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More accurate player head layers #353

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,21 @@ public void update(File storageFolder, File fallback) {
}

public BufferedImage createHead(BufferedImage skinTexture) {
BufferedImage head = new BufferedImage(8, 8, skinTexture.getType());
BufferedImage head;

BufferedImage layer1 = skinTexture.getSubimage(8, 8, 8, 8);
BufferedImage layer2 = skinTexture.getSubimage(40, 8, 8, 8);

try {
head = new BufferedImage(48, 48, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = head.createGraphics();
g.drawImage(layer1, 0, 0, null);
g.drawImage(layer2, 0, 0, null);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
g.drawImage(layer1, 4, 4, 40, 40, null);
g.drawImage(layer2, 0, 0, 48, 48, null);
} catch (Throwable t) { // There might be problems with headless servers when loading the graphics class, so we catch every exception and error on purpose here
Logger.global.noFloodWarning("headless-graphics-fail",
"Could not access Graphics2D to render player-skin texture. Try adding '-Djava.awt.headless=true' to your startup flags or ignore this warning.");

head = new BufferedImage(8, 8, skinTexture.getType());
layer1.copyData(head.getRaster());
}

Expand Down