From c8b6f2aad85b31242ba487fbf5a2a11df1fdb93c Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 11 Apr 2024 06:54:06 +0100 Subject: [PATCH] implement overlays for skins (skin layers) --- .../java/cc.fascinated/model/player/Skin.java | 61 +++++++------------ .../service/skin/SkinRenderer.java | 15 ++--- .../service/skin/impl/BodyRenderer.java | 11 ++-- 3 files changed, 35 insertions(+), 52 deletions(-) diff --git a/src/main/java/cc.fascinated/model/player/Skin.java b/src/main/java/cc.fascinated/model/player/Skin.java index 798917a..70ae2fa 100644 --- a/src/main/java/cc.fascinated/model/player/Skin.java +++ b/src/main/java/cc.fascinated/model/player/Skin.java @@ -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; } /** diff --git a/src/main/java/cc.fascinated/service/skin/SkinRenderer.java b/src/main/java/cc.fascinated/service/skin/SkinRenderer.java index 3606a1f..a2fb900 100644 --- a/src/main/java/cc.fascinated/service/skin/SkinRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/SkinRenderer.java @@ -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; diff --git a/src/main/java/cc.fascinated/service/skin/impl/BodyRenderer.java b/src/main/java/cc.fascinated/service/skin/impl/BodyRenderer.java index 47e4832..fcbbd8d 100644 --- a/src/main/java/cc.fascinated/service/skin/impl/BodyRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/impl/BodyRenderer.java @@ -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);