add skin overlays to all images if it's enabled
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m35s
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m35s
This commit is contained in:
@ -4,24 +4,29 @@ import cc.fascinated.common.ImageUtils;
|
||||
import cc.fascinated.model.skin.ISkinPart;
|
||||
import cc.fascinated.model.skin.Skin;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
@Log4j2
|
||||
public abstract class SkinRenderer<T extends ISkinPart> {
|
||||
|
||||
/**
|
||||
* Get the texture of a part of a skin.
|
||||
* Get the texture of a part of the skin.
|
||||
*
|
||||
* @param skin the skin to get the part texture from
|
||||
* @param part the part of the skin to get
|
||||
* @param size the size to scale the texture to
|
||||
* @param renderOverlays should the overlays be rendered
|
||||
* @return the texture of the skin part
|
||||
*/
|
||||
@SneakyThrows
|
||||
public BufferedImage getVanillaSkinPart(Skin skin, ISkinPart.Vanilla part, double size) {
|
||||
public BufferedImage getVanillaSkinPart(Skin skin, ISkinPart.Vanilla part, double size, boolean renderOverlays) {
|
||||
ISkinPart.Vanilla.Coordinates coordinates = part.getCoordinates(); // The coordinates of the part
|
||||
|
||||
// The skin texture is legacy, use legacy coordinates
|
||||
@ -37,6 +42,16 @@ public abstract class SkinRenderer<T extends ISkinPart> {
|
||||
if (coordinates instanceof ISkinPart.Vanilla.LegacyCoordinates legacyCoordinates && legacyCoordinates.isFlipped()) {
|
||||
partTexture = ImageUtils.flip(partTexture);
|
||||
}
|
||||
|
||||
// Draw part overlays
|
||||
ISkinPart.Vanilla[] overlayParts = part.getOverlays();
|
||||
if (overlayParts != null && renderOverlays) {
|
||||
log.info("Applying overlays to part: {}", part.name());
|
||||
for (ISkinPart.Vanilla overlay : overlayParts) {
|
||||
applyOverlay(partTexture.createGraphics(), getVanillaSkinPart(skin, overlay, size, false));
|
||||
}
|
||||
}
|
||||
|
||||
return partTexture;
|
||||
}
|
||||
|
||||
|
@ -21,12 +21,12 @@ public class BodyRenderer extends SkinRenderer<ISkinPart.Custom> {
|
||||
Graphics2D graphics = texture.createGraphics(); // Create the graphics for drawing
|
||||
|
||||
// Get the Vanilla skin parts to draw
|
||||
BufferedImage face = getVanillaSkinPart(skin, ISkinPart.Vanilla.FACE, -1);
|
||||
BufferedImage body = getVanillaSkinPart(skin, ISkinPart.Vanilla.BODY_FRONT, -1);
|
||||
BufferedImage leftArm = getVanillaSkinPart(skin, ISkinPart.Vanilla.LEFT_ARM_FRONT, -1);
|
||||
BufferedImage rightArm = getVanillaSkinPart(skin, ISkinPart.Vanilla.RIGHT_ARM_FRONT, -1);
|
||||
BufferedImage leftLeg = getVanillaSkinPart(skin, ISkinPart.Vanilla.LEFT_LEG_FRONT, -1);
|
||||
BufferedImage rightLeg = getVanillaSkinPart(skin, ISkinPart.Vanilla.RIGHT_LEG_FRONT, -1);
|
||||
BufferedImage face = getVanillaSkinPart(skin, ISkinPart.Vanilla.FACE, -1, renderOverlays);
|
||||
BufferedImage body = getVanillaSkinPart(skin, ISkinPart.Vanilla.BODY_FRONT, -1, renderOverlays);
|
||||
BufferedImage leftArm = getVanillaSkinPart(skin, ISkinPart.Vanilla.LEFT_ARM_FRONT, -1, renderOverlays);
|
||||
BufferedImage rightArm = getVanillaSkinPart(skin, ISkinPart.Vanilla.RIGHT_ARM_FRONT, -1, renderOverlays);
|
||||
BufferedImage leftLeg = getVanillaSkinPart(skin, ISkinPart.Vanilla.LEFT_LEG_FRONT, -1, renderOverlays);
|
||||
BufferedImage rightLeg = getVanillaSkinPart(skin, ISkinPart.Vanilla.RIGHT_LEG_FRONT, -1, renderOverlays);
|
||||
|
||||
// Draw the body parts
|
||||
graphics.drawImage(face, 4, 0, null);
|
||||
|
@ -28,9 +28,9 @@ public class IsometricHeadRenderer extends IsometricSkinRenderer<ISkinPart.Custo
|
||||
Graphics2D graphics = texture.createGraphics(); // Create the graphics for drawing
|
||||
|
||||
// Get the Vanilla skin parts to draw
|
||||
BufferedImage headTop = getVanillaSkinPart(skin, ISkinPart.Vanilla.HEAD_TOP, scale);
|
||||
BufferedImage face = getVanillaSkinPart(skin, ISkinPart.Vanilla.FACE, scale);
|
||||
BufferedImage headLeft = getVanillaSkinPart(skin, ISkinPart.Vanilla.HEAD_LEFT, scale);
|
||||
BufferedImage headTop = getVanillaSkinPart(skin, ISkinPart.Vanilla.HEAD_TOP, scale, renderOverlays);
|
||||
BufferedImage face = getVanillaSkinPart(skin, ISkinPart.Vanilla.FACE, scale, renderOverlays);
|
||||
BufferedImage headLeft = getVanillaSkinPart(skin, ISkinPart.Vanilla.HEAD_LEFT, scale, renderOverlays);
|
||||
|
||||
// Draw the top head part
|
||||
drawPart(graphics, headTop, HEAD_TOP_TRANSFORM, -0.5 - zOffset, xOffset + zOffset, headTop.getWidth(), headTop.getHeight() + 2);
|
||||
|
@ -17,7 +17,7 @@ public class SquareRenderer extends SkinRenderer<ISkinPart.Vanilla> {
|
||||
@Override
|
||||
public BufferedImage render(Skin skin, ISkinPart.Vanilla part, boolean renderOverlays, int size) {
|
||||
double scale = size / 8D;
|
||||
BufferedImage partImage = getVanillaSkinPart(skin, part, scale); // Get the part image
|
||||
BufferedImage partImage = getVanillaSkinPart(skin, part, scale, renderOverlays); // Get the part image
|
||||
if (!renderOverlays) { // Not rendering overlays
|
||||
return partImage;
|
||||
}
|
||||
@ -26,13 +26,6 @@ public class SquareRenderer extends SkinRenderer<ISkinPart.Vanilla> {
|
||||
Graphics2D graphics = texture.createGraphics(); // Create the graphics for drawing
|
||||
graphics.drawImage(partImage, 0, 0, null);
|
||||
|
||||
// Draw part overlays
|
||||
ISkinPart.Vanilla[] overlayParts = part.getOverlays();
|
||||
if (overlayParts != null) {
|
||||
for (ISkinPart.Vanilla overlay : overlayParts) {
|
||||
applyOverlay(graphics, getVanillaSkinPart(skin, overlay, scale));
|
||||
}
|
||||
}
|
||||
graphics.dispose();
|
||||
return texture;
|
||||
}
|
||||
|
Reference in New Issue
Block a user