Skip to content

Commit 9ac167e

Browse files
committed
Fix old skins with black pixels in the hat area
1 parent 2491832 commit 9ac167e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Diff for: src/org/jmc/models/Head.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,26 @@ private static boolean exportPlayerTexture(String textureUrl, NamespaceID texId)
228228
if (texture.getHeight() == 32) { // Expand old 32px high player textures to new 64px size
229229
Log.debug("Expanding "+texId+" height from 32px to 64px");
230230
BufferedImage expandedTex = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
231-
expandedTex.getGraphics().drawImage(texture, 0, 0, 64, 32, 0, 0, 64, 32, null);
231+
Graphics2D expandedGraphics = expandedTex.createGraphics();
232+
expandedGraphics.drawImage(texture, 0, 0, 64, 32, 0, 0, 64, 32, null);
233+
234+
// Fix old skins that have opaque black pixels in the hat area (Notch)
235+
boolean blackHat = true;
236+
for (int x = 32; x < 64 && blackHat; x++) {
237+
for (int y = 0; y < 16; y++) {
238+
Color pixel = new Color(texture.getRGB(x, y), true);
239+
if (pixel.getRed() != 0 || pixel.getGreen() != 0 || pixel.getBlue() != 0 || pixel.getAlpha() != 255) {
240+
blackHat = false;
241+
break;
242+
}
243+
}
244+
}
245+
if (blackHat) {
246+
expandedGraphics.setColor(new Color(0,0,0,0));
247+
expandedGraphics.setComposite(AlphaComposite.Src);
248+
expandedGraphics.fillRect(32, 0, 32, 16);
249+
}
250+
232251
texture = expandedTex;
233252
}
234253
TextureEntry texEntry = Registries.getTexture(texId);

0 commit comments

Comments
 (0)