From 9acb7c259a86337a033585ee2cc262d246d2ea3a Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 11 Apr 2024 08:08:57 +0100 Subject: [PATCH] cleanup isometric head --- .../java/cc.fascinated/model/player/Skin.java | 5 ++- .../cc.fascinated/service/PlayerService.java | 2 +- .../service/skin/impl/BodyRenderer.java | 1 - .../skin/impl/IsometricHeadRenderer.java | 35 +++++++------------ 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/main/java/cc.fascinated/model/player/Skin.java b/src/main/java/cc.fascinated/model/player/Skin.java index 96d2bf9..3822090 100644 --- a/src/main/java/cc.fascinated/model/player/Skin.java +++ b/src/main/java/cc.fascinated/model/player/Skin.java @@ -115,7 +115,7 @@ public class Skin { /** * The skin part renderer for the part. */ - private final SkinRenderer skinRenderer; + private final SkinRenderer renderer; /** * Gets the name of the part. @@ -151,7 +151,7 @@ public class Skin { 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_LEFT(0, 8, 8, 8, null), BODY(20, 20, 8, 12, null), BODY_BACK(20, 36, 8, 12, null), @@ -169,7 +169,6 @@ public class Skin { */ 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), BODY_OVERLAY_FRONT(20, 36, 8, 12, null), diff --git a/src/main/java/cc.fascinated/service/PlayerService.java b/src/main/java/cc.fascinated/service/PlayerService.java index 9ecc878..ffd6e26 100644 --- a/src/main/java/cc.fascinated/service/PlayerService.java +++ b/src/main/java/cc.fascinated/service/PlayerService.java @@ -139,7 +139,7 @@ public class PlayerService { } long before = System.currentTimeMillis(); - byte[] skinPartBytes = part.getSkinRenderer().renderPart(player.getSkin(), part.getName(), renderOverlay, size); + byte[] skinPartBytes = part.getRenderer().renderPart(player.getSkin(), part.getName(), renderOverlay, size); log.info("Took {}ms to render skin part {} for player: {}", System.currentTimeMillis() - before, part.getName(), player.getUniqueId()); CachedPlayerSkinPart skinPart = new CachedPlayerSkinPart( key, 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 20f0b0c..ad8aa96 100644 --- a/src/main/java/cc.fascinated/service/skin/impl/BodyRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/impl/BodyRenderer.java @@ -7,7 +7,6 @@ import lombok.Getter; import lombok.extern.log4j.Log4j2; import java.awt.*; -import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; @Getter @Log4j2 diff --git a/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java b/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java index 557ea78..6e09b1c 100644 --- a/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java @@ -1,6 +1,5 @@ package cc.fascinated.service.skin.impl; -import cc.fascinated.common.ImageUtils; import cc.fascinated.model.player.Skin; import cc.fascinated.service.skin.SkinRenderer; import lombok.Getter; @@ -19,16 +18,15 @@ public class IsometricHeadRenderer extends SkinRenderer { /** * The head transforms */ - private static final AffineTransform HEAD_TRANSFORM = new AffineTransform(1d, -SKEW_A, 1, SKEW_A, 0, 0); - private static final AffineTransform FRONT_TRANSFORM = new AffineTransform(1d, -SKEW_A, 0d, SKEW_B, 0d, SKEW_A); - private static final AffineTransform RIGHT_TRANSFORM = new AffineTransform(1d, SKEW_A, 0d, SKEW_B, 0d, 0d); + private static final AffineTransform HEAD_TOP_TRANSFORM = new AffineTransform(1D, -SKEW_A, 1, SKEW_A, 0, 0); + private static final AffineTransform FACE_TRANSFORM = new AffineTransform(1D, -SKEW_A, 0D, SKEW_B, 0d, SKEW_A); + private static final AffineTransform HEAD_LEFT_TRANSFORM = new AffineTransform(1D, SKEW_A, 0D, SKEW_B, 0D, 0D); @Override public byte[] renderPart(Skin skin, String partName, boolean renderOverlay, int size) { double scale = (size / 8d) / 2.5; log.info("Getting {} part bytes for {} with size {} and scale {}", partName, skin.getUrl(), size, scale); - double x, y, z; // The x, y, and z positions double zOffset = scale * 3.5d; double xOffset = scale * 2d; BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); @@ -37,32 +35,23 @@ public class IsometricHeadRenderer extends SkinRenderer { // Get all the required head parts BufferedImage headTop = this.getSkinPart(skin, Skin.PartPosition.HEAD_TOP, scale); BufferedImage headFront = this.getSkinPart(skin, Skin.PartPosition.HEAD_FRONT, scale); - BufferedImage headRight = this.getSkinPart(skin, Skin.PartPosition.HEAD_RIGHT, scale); + BufferedImage headLeft = this.getSkinPart(skin, Skin.PartPosition.HEAD_LEFT, scale); if (renderOverlay) { // Render the skin layers applyOverlay(headTop, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_TOP, scale)); applyOverlay(headFront, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, scale)); - applyOverlay(headRight, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_RIGHT, scale)); + applyOverlay(headLeft, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_LEFT, scale)); } - // 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 top of the left + drawPart(graphics, headTop, HEAD_TOP_TRANSFORM, -0.5 - zOffset, xOffset + zOffset, 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 face of the head + double x = xOffset + 8 * scale; + drawPart(graphics, headFront, FACE_TRANSFORM, x, x + zOffset - 0.5, 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()); + // Draw the left side of the head + drawPart(graphics, headLeft, HEAD_LEFT_TRANSFORM, xOffset + 1, zOffset - 0.5, headLeft.getWidth(), headLeft.getHeight()); return super.getBytes(outputImage, skin, partName); }