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

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

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

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