fix overlay on player head
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m32s

This commit is contained in:
Lee 2024-04-11 07:45:16 +01:00
parent 654037c8e1
commit d9e6becebb
3 changed files with 66 additions and 80 deletions

@ -19,40 +19,36 @@ public class BodyRenderer extends SkinRenderer {
@Override @Override
public byte[] renderPart(Skin skin, String partName, boolean renderOverlay, int size) { public byte[] renderPart(Skin skin, String partName, boolean renderOverlay, int size) {
log.info("Getting {} part bytes for {} with size {}", partName, skin.getUrl(), size); log.info("Getting {} part bytes for {} with size {}", partName, skin.getUrl(), size);
try {
BufferedImage outputImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = outputImage.createGraphics();
// Get all the required body parts BufferedImage outputImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
BufferedImage head = this.getSkinPart(skin, Skin.PartPosition.HEAD, 1); Graphics2D graphics = outputImage.createGraphics();
BufferedImage body = this.getSkinPart(skin, Skin.PartPosition.BODY, 1);
BufferedImage rightArm = this.getSkinPart(skin, Skin.PartPosition.RIGHT_ARM, 1);
BufferedImage leftArm = this.getSkinPart(skin, Skin.PartPosition.LEFT_ARM, 1);
BufferedImage rightLeg = this.getSkinPart(skin, Skin.PartPosition.RIGHT_LEG, 1);
BufferedImage leftLeg = this.getSkinPart(skin, Skin.PartPosition.LEFT_LEG, 1);
if (renderOverlay) { // Render the skin layers // Get all the required body parts
applyOverlay(head, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1)); BufferedImage head = this.getSkinPart(skin, Skin.PartPosition.HEAD, 1);
applyOverlay(body, this.getSkinPart(skin, Skin.PartPosition.BODY_OVERLAY_FRONT, 1)); BufferedImage body = this.getSkinPart(skin, Skin.PartPosition.BODY, 1);
applyOverlay(rightArm, this.getSkinPart(skin, Skin.PartPosition.RIGHT_ARM_OVERLAY, 1)); BufferedImage rightArm = this.getSkinPart(skin, Skin.PartPosition.RIGHT_ARM, 1);
applyOverlay(leftArm, this.getSkinPart(skin, Skin.PartPosition.LEFT_ARM_OVERLAY, 1)); BufferedImage leftArm = this.getSkinPart(skin, Skin.PartPosition.LEFT_ARM, 1);
applyOverlay(rightLeg, this.getSkinPart(skin, Skin.PartPosition.RIGHT_LEG_OVERLAY, 1)); BufferedImage rightLeg = this.getSkinPart(skin, Skin.PartPosition.RIGHT_LEG, 1);
applyOverlay(leftLeg, this.getSkinPart(skin, Skin.PartPosition.LEFT_LEG_OVERLAY, 1)); BufferedImage leftLeg = this.getSkinPart(skin, Skin.PartPosition.LEFT_LEG, 1);
}
// Draw the body if (renderOverlay) { // Render the skin layers
graphics.drawImage(head, 4, 0, null); applyOverlay(head, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1));
graphics.drawImage(body, 4, 8, null); applyOverlay(body, this.getSkinPart(skin, Skin.PartPosition.BODY_OVERLAY_FRONT, 1));
graphics.drawImage(rightArm, skin.getModel() == Skin.Model.SLIM ? 1 : 0, 8, null); applyOverlay(rightArm, this.getSkinPart(skin, Skin.PartPosition.RIGHT_ARM_OVERLAY, 1));
graphics.drawImage(leftArm, 12, 8, null); applyOverlay(leftArm, this.getSkinPart(skin, Skin.PartPosition.LEFT_ARM_OVERLAY, 1));
graphics.drawImage(rightLeg, 4, 20, null); applyOverlay(rightLeg, this.getSkinPart(skin, Skin.PartPosition.RIGHT_LEG_OVERLAY, 1));
graphics.drawImage(leftLeg, 8, 20, null); applyOverlay(leftLeg, this.getSkinPart(skin, Skin.PartPosition.LEFT_LEG_OVERLAY, 1));
graphics.dispose(); // Clean up
return super.getBytes(ImageUtils.resize(outputImage, (double) size / HEIGHT), skin, partName);
} catch (Exception ex) {
log.error("Failed to get {} part bytes for {}", partName, skin.getUrl(), ex);
throw new RuntimeException("Failed to get " + partName + " part for " + skin.getUrl());
} }
// Draw the body
graphics.drawImage(head, 4, 0, null);
graphics.drawImage(body, 4, 8, null);
graphics.drawImage(rightArm, skin.getModel() == Skin.Model.SLIM ? 1 : 0, 8, null);
graphics.drawImage(leftArm, 12, 8, null);
graphics.drawImage(rightLeg, 4, 20, null);
graphics.drawImage(leftLeg, 8, 20, null);
graphics.dispose(); // Clean up
return super.getBytes(ImageUtils.resize(outputImage, (double) size / HEIGHT), skin, partName);
} }
} }

@ -17,21 +17,16 @@ public class HeadRenderer extends SkinRenderer {
double scale = (double) size / 8d; double scale = (double) size / 8d;
log.info("Getting {} part bytes for {} with size {} and scale {}", partName, skin.getUrl(), size, scale); log.info("Getting {} part bytes for {} with size {} and scale {}", partName, skin.getUrl(), size, scale);
try { BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = outputImage.createGraphics();
Graphics2D graphics = outputImage.createGraphics();
graphics.setTransform(AffineTransform.getScaleInstance(scale, scale)); graphics.setTransform(AffineTransform.getScaleInstance(scale, scale));
graphics.drawImage(this.getSkinPart(skin, Skin.PartPosition.HEAD, 1), 0, 0, null); graphics.drawImage(this.getSkinPart(skin, Skin.PartPosition.HEAD, 1), 0, 0, null);
if (renderOverlay) { // Render the skin layers if (renderOverlay) { // Render the skin layers
applyOverlay(outputImage, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1)); applyOverlay(outputImage, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1));
}
return super.getBytes(outputImage, skin, partName);
} catch (Exception ex) {
log.error("Failed to get {} part bytes for {}", partName, skin.getUrl(), ex);
throw new RuntimeException("Failed to get " + partName + " part for " + skin.getUrl());
} }
return super.getBytes(outputImage, skin, partName);
} }
} }

@ -31,45 +31,40 @@ public class IsometricHeadRenderer extends SkinRenderer {
double x, y, z; // The x, y, and z positions double x, y, z; // The x, y, and z positions
double zOffset = scale * 3.5d; double zOffset = scale * 3.5d;
double xOffset = scale * 2d; double xOffset = scale * 2d;
try { BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = outputImage.createGraphics();
Graphics2D graphics = outputImage.createGraphics();
// Get all the required head parts // Get all the required head parts
BufferedImage headTop = ImageUtils.resize(this.getSkinPart(skin, Skin.PartPosition.HEAD_TOP, 1), scale); BufferedImage headTop = this.getSkinPart(skin, Skin.PartPosition.HEAD_TOP, scale);
BufferedImage headFront = ImageUtils.resize(this.getSkinPart(skin, Skin.PartPosition.HEAD_FRONT, 1), scale); BufferedImage headFront = this.getSkinPart(skin, Skin.PartPosition.HEAD_FRONT, scale);
BufferedImage headRight = ImageUtils.resize(this.getSkinPart(skin, Skin.PartPosition.HEAD_RIGHT, 1), scale); BufferedImage headRight = this.getSkinPart(skin, Skin.PartPosition.HEAD_RIGHT, scale);
if (renderOverlay) { // Render the skin layers if (renderOverlay) { // Render the skin layers
applyOverlay(headTop, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_TOP, 1)); applyOverlay(headTop, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_TOP, scale));
applyOverlay(headFront, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1)); applyOverlay(headFront, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, scale));
applyOverlay(headRight, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_RIGHT, 1)); applyOverlay(headRight, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_RIGHT, scale));
}
// Draw the head
x = xOffset;
y = -0.5;
z = zOffset;
// The head is offset by 2 pixels for whatever reason
drawPart(graphics, headTop, HEAD_TRANSFORM, y - z, x + z, headTop.getWidth(), headTop.getHeight() + 2);
// Draw the front of the head
x = xOffset + 8 * scale;
y = 0;
z = zOffset - 0.5;
drawPart(graphics, headFront, FRONT_TRANSFORM, y + x, x + z, headFront.getWidth(), headFront.getHeight());
// Draw the right side of the head
x = xOffset;
y = 0;
z = zOffset;
drawPart(graphics, headRight, RIGHT_TRANSFORM, x + y + 1, z - y - 0.5, headRight.getWidth(), headRight.getHeight());
return super.getBytes(outputImage, skin, partName);
} catch (Exception ex) {
log.error("Failed to get {} part bytes for {}", partName, skin.getUrl(), ex);
throw new RuntimeException("Failed to get " + partName + " part for " + skin.getUrl());
} }
// Draw the top of the head
x = xOffset;
y = -0.5;
z = zOffset;
// The head is offset by 2 pixels for whatever reason
drawPart(graphics, headTop, HEAD_TRANSFORM, y - z, x + z, headTop.getWidth(), headTop.getHeight() + 2);
// Draw the front of the head
x = xOffset + 8 * scale;
y = 0;
z = zOffset - 0.5;
drawPart(graphics, headFront, FRONT_TRANSFORM, y + x, x + z, headFront.getWidth(), headFront.getHeight());
// Draw the right side of the head
x = xOffset;
y = 0;
z = zOffset;
drawPart(graphics, headRight, RIGHT_TRANSFORM, x + y + 1, z - y - 0.5, headRight.getWidth(), headRight.getHeight());
return super.getBytes(outputImage, skin, partName);
} }
/** /**