implement overlays for skins (skin layers)
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m38s

This commit is contained in:
Lee 2024-04-11 06:54:06 +01:00
parent 9b7b761ffd
commit c8b6f2aad8
3 changed files with 35 additions and 52 deletions

View File

@ -148,38 +148,37 @@ public class Skin {
/**
* Skin postions
*/
HEAD(8, 8, 8, 8, null),
HEAD_TOP(8, 0, 8, 8, null),
HEAD_FRONT(8, 8, 8, 8, null),
HEAD_RIGHT(0, 8, 8, 8, null),
HEAD(8, 8, 8, 8, false),
HEAD_TOP(8, 0, 8, 8, false),
HEAD_FRONT(8, 8, 8, 8, false),
HEAD_RIGHT(0, 8, 8, 8, false),
BODY(20, 20, 8, 12, null),
BODY_BACK(20, 36, 8, 12, null),
BODY_LEFT(32, 52, 8, 12, null),
BODY_RIGHT(44, 20, 8, 12, null),
BODY(20, 20, 8, 12, false),
BODY_BACK(20, 36, 8, 12, false),
BODY_LEFT(32, 52, 8, 12, false),
BODY_RIGHT(44, 20, 8, 12, false),
RIGHT_ARM(44, 20, 4, 12, null),
LEFT_ARM(36, 52, 4, 12, new LegacyPartPositionData(43, 20, true)),
RIGHT_ARM(44, 20, 4, 12, false),
LEFT_ARM(36, 52, 4, 12, true),
RIGHT_LEG(4, 20, 4, 12, null),
LEFT_LEG(20, 52, 4, 12, new LegacyPartPositionData(3, 20, true)),
RIGHT_LEG(4, 20, 4, 12, false),
LEFT_LEG(20, 52, 4, 12, true),
/**
* Skin overlay (layer) positions
*/
// todo: finish these below
HEAD_OVERLAY_TOP(40, 0, 8, 8, null),
HEAD_OVERLAY_FRONT(40, 8, 8, 8, null),
HEAD_OVERLAY_RIGHT(32, 8, 8, 8, null),
HEAD_OVERLAY_LEFT(48, 8, 8, 8, null),
HEAD_OVERLAY_TOP(40, 0, 8, 8, false),
HEAD_OVERLAY_FRONT(40, 8, 8, 8, false),
HEAD_OVERLAY_RIGHT(32, 8, 8, 8, false),
HEAD_OVERLAY_LEFT(48, 8, 8, 8, false),
BODY_OVERLAY_FRONT(20, 36, 8, 12, null),
BODY_OVERLAY_FRONT(20, 36, 8, 12, false),
RIGHT_ARM_OVERLAY(44, 36, 8, 12, null),
LEFT_ARM_OVERLAY(52, 52, 8, 12, null),
RIGHT_ARM_OVERLAY(44, 36, 8, 12, false),
LEFT_ARM_OVERLAY(52, 52, 8, 12, false),
RIGHT_LEG_OVERLAY(4, 36, 4, 12, null),
LEFT_LEG_OVERLAY(4, 52, 20, 12, null);
RIGHT_LEG_OVERLAY(4, 36, 4, 12, false),
LEFT_LEG_OVERLAY(4, 52, 20, 12, false);
/**
* The x, and y position of the part.
@ -192,23 +191,9 @@ public class Skin {
private final int width, height;
/*
* The part position data for legacy skins.
* This can be null to use the default position.
* Should the part be flipped horizontally?
*/
private final LegacyPartPositionData legacyData;
}
@AllArgsConstructor @Getter
public static class LegacyPartPositionData {
/**
* The x, and y position of the part.
*/
private int x, y;
/**
* Should the part be flipped?
*/
private boolean flipped;
private final boolean flipped;
}
/**

View File

@ -44,19 +44,14 @@ public abstract class SkinRenderer {
if (skinImage == null) {
return null;
}
BufferedImage part;
Skin.LegacyPartPositionData legacyData = position.getLegacyData();
if (skin.isLegacy() && legacyData != null) {
part = skinImage.getSubimage(legacyData.getX(), legacyData.getY(), position.getWidth(), position.getHeight());
if (legacyData.isFlipped()) {
part = ImageUtils.flip(part);
}
} else {
part = skinImage.getSubimage(position.getX(), position.getY(), position.getWidth(), position.getHeight());
}
int width = skin.getModel() == Skin.Model.SLIM && position.name().contains("ARM") ? position.getWidth() - 1 : position.getWidth();
BufferedImage part = skinImage.getSubimage(position.getX(), position.getY(), width, position.getHeight());
if (part == null) {
return null;
}
if (position.isFlipped()) { // Flip the part horizontally
part = ImageUtils.flip(part);
}
return ImageUtils.resize(part, scale);
} catch (Exception ex) {
return null;

View File

@ -32,15 +32,18 @@ public class BodyRenderer extends SkinRenderer {
BufferedImage leftLeg = this.getSkinPart(skin, Skin.PartPosition.LEFT_LEG, 1);
if (renderOverlay) { // Render the skin layers
Graphics2D overlayGraphics = head.createGraphics();
applyOverlay(overlayGraphics, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1));
applyOverlay(head.createGraphics(), this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1));
applyOverlay(body.createGraphics(), this.getSkinPart(skin, Skin.PartPosition.BODY_OVERLAY_FRONT, 1));
applyOverlay(rightArm.createGraphics(), this.getSkinPart(skin, Skin.PartPosition.RIGHT_ARM_OVERLAY, 1));
applyOverlay(leftArm.createGraphics(), this.getSkinPart(skin, Skin.PartPosition.LEFT_ARM_OVERLAY, 1));
applyOverlay(rightLeg.createGraphics(), this.getSkinPart(skin, Skin.PartPosition.RIGHT_LEG_OVERLAY, 1));
applyOverlay(leftLeg.createGraphics(), this.getSkinPart(skin, Skin.PartPosition.LEFT_LEG_OVERLAY, 1));
}
// Draw the body
graphics.drawImage(head, 4, 0, null);
graphics.drawImage(body, 4, 8, null);
graphics.drawImage(rightArm, 0, 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);