From d9e6becebb8704ba07213426e399bca91c201e6f Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 11 Apr 2024 07:45:16 +0100 Subject: [PATCH] fix overlay on player head --- .../service/skin/impl/BodyRenderer.java | 58 ++++++++-------- .../service/skin/impl/HeadRenderer.java | 21 +++--- .../skin/impl/IsometricHeadRenderer.java | 67 +++++++++---------- 3 files changed, 66 insertions(+), 80 deletions(-) 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 305dfc4..20f0b0c 100644 --- a/src/main/java/cc.fascinated/service/skin/impl/BodyRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/impl/BodyRenderer.java @@ -19,40 +19,36 @@ public class BodyRenderer extends SkinRenderer { @Override public byte[] renderPart(Skin skin, String partName, boolean renderOverlay, int 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 head = this.getSkinPart(skin, Skin.PartPosition.HEAD, 1); - 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); + BufferedImage outputImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = outputImage.createGraphics(); - if (renderOverlay) { // Render the skin layers - applyOverlay(head, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1)); - applyOverlay(body, this.getSkinPart(skin, Skin.PartPosition.BODY_OVERLAY_FRONT, 1)); - applyOverlay(rightArm, this.getSkinPart(skin, Skin.PartPosition.RIGHT_ARM_OVERLAY, 1)); - applyOverlay(leftArm, this.getSkinPart(skin, Skin.PartPosition.LEFT_ARM_OVERLAY, 1)); - applyOverlay(rightLeg, this.getSkinPart(skin, Skin.PartPosition.RIGHT_LEG_OVERLAY, 1)); - applyOverlay(leftLeg, this.getSkinPart(skin, Skin.PartPosition.LEFT_LEG_OVERLAY, 1)); - } + // Get all the required body parts + BufferedImage head = this.getSkinPart(skin, Skin.PartPosition.HEAD, 1); + 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); - // 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); - } 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()); + if (renderOverlay) { // Render the skin layers + applyOverlay(head, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1)); + applyOverlay(body, this.getSkinPart(skin, Skin.PartPosition.BODY_OVERLAY_FRONT, 1)); + applyOverlay(rightArm, this.getSkinPart(skin, Skin.PartPosition.RIGHT_ARM_OVERLAY, 1)); + applyOverlay(leftArm, this.getSkinPart(skin, Skin.PartPosition.LEFT_ARM_OVERLAY, 1)); + applyOverlay(rightLeg, this.getSkinPart(skin, Skin.PartPosition.RIGHT_LEG_OVERLAY, 1)); + applyOverlay(leftLeg, 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, 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); } } \ No newline at end of file diff --git a/src/main/java/cc.fascinated/service/skin/impl/HeadRenderer.java b/src/main/java/cc.fascinated/service/skin/impl/HeadRenderer.java index 61174d7..0f7de56 100644 --- a/src/main/java/cc.fascinated/service/skin/impl/HeadRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/impl/HeadRenderer.java @@ -17,21 +17,16 @@ public class HeadRenderer extends SkinRenderer { double scale = (double) size / 8d; 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); - Graphics2D graphics = outputImage.createGraphics(); + BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = outputImage.createGraphics(); - graphics.setTransform(AffineTransform.getScaleInstance(scale, scale)); - graphics.drawImage(this.getSkinPart(skin, Skin.PartPosition.HEAD, 1), 0, 0, null); + graphics.setTransform(AffineTransform.getScaleInstance(scale, scale)); + graphics.drawImage(this.getSkinPart(skin, Skin.PartPosition.HEAD, 1), 0, 0, null); - if (renderOverlay) { // Render the skin layers - 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()); + if (renderOverlay) { // Render the skin layers + applyOverlay(outputImage, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1)); } + + return super.getBytes(outputImage, skin, partName); } } 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 d1be943..557ea78 100644 --- a/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java +++ b/src/main/java/cc.fascinated/service/skin/impl/IsometricHeadRenderer.java @@ -31,45 +31,40 @@ public class IsometricHeadRenderer extends SkinRenderer { double x, y, z; // The x, y, and z positions double zOffset = scale * 3.5d; double xOffset = scale * 2d; - try { - BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); - Graphics2D graphics = outputImage.createGraphics(); + BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = outputImage.createGraphics(); - // Get all the required head parts - BufferedImage headTop = ImageUtils.resize(this.getSkinPart(skin, Skin.PartPosition.HEAD_TOP, 1), scale); - BufferedImage headFront = ImageUtils.resize(this.getSkinPart(skin, Skin.PartPosition.HEAD_FRONT, 1), scale); - BufferedImage headRight = ImageUtils.resize(this.getSkinPart(skin, Skin.PartPosition.HEAD_RIGHT, 1), scale); + // 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); - if (renderOverlay) { // Render the skin layers - applyOverlay(headTop, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_TOP, 1)); - applyOverlay(headFront, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_FRONT, 1)); - applyOverlay(headRight, this.getSkinPart(skin, Skin.PartPosition.HEAD_OVERLAY_RIGHT, 1)); - } - - // 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()); + 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)); } + + // 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); } /**