Cleanup
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m30s

This commit is contained in:
Braydon 2024-04-11 07:22:24 -04:00
parent d8962cee98
commit 6993fe6681
5 changed files with 76 additions and 37 deletions

@ -0,0 +1,56 @@
/*
* MIT License
*
* Copyright (c) 2024 Braydon (Rainnny).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.braydon.mc.common.renderer;
import lombok.NonNull;
import me.braydon.mc.model.skin.ISkinPart;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
/**
* A isometric renderer for a {@link ISkinPart}.
*
* @param <T> the type of part to render
* @author Braydon
*/
public abstract class IsometricSkinRenderer<T extends ISkinPart> extends SkinRenderer<T> {
/**
* Draw a part onto the texture.
*
* @param graphics the graphics to draw to
* @param partImage the part image to draw
* @param transform the transform to apply
* @param x the x position to draw at
* @param y the y position to draw at
* @param width the part image width
* @param height the part image height
*/
protected final void drawPart(@NonNull Graphics2D graphics, @NonNull BufferedImage partImage, @NonNull AffineTransform transform,
double x, double y, int width, int height) {
graphics.setTransform(transform);
graphics.drawImage(partImage, (int) x, (int) y, width, height, null);
}
}

@ -71,7 +71,7 @@ public abstract class SkinRenderer<T extends ISkinPart> {
coordinates = part.getLegacyCoordinates(); coordinates = part.getLegacyCoordinates();
} }
int width = part.getWidth(); // The width of the part int width = part.getWidth(); // The width of the part
if (skin.getModel() == Skin.Model.SLIM && part.isArm()) { if (skin.getModel() == Skin.Model.SLIM && part.isFrontArm()) {
width--; width--;
} }
BufferedImage partTexture = getSkinPartTexture(skinImage, coordinates.getX(), coordinates.getY(), width, part.getHeight(), size); BufferedImage partTexture = getSkinPartTexture(skinImage, coordinates.getX(), coordinates.getY(), width, part.getHeight(), size);

@ -33,7 +33,7 @@ import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
/** /**
* A basic 2D renderer for a {@link ISkinPart.Custom#BODY}. * A basic 2D renderer for a {@link ISkinPart.Custom#BODY_FLAT}.
* *
* @author Braydon * @author Braydon
*/ */
@ -58,10 +58,10 @@ public final class BodySkinPartRenderer extends SkinRenderer<ISkinPart.Custom> {
// Get the Vanilla skin parts to draw // Get the Vanilla skin parts to draw
BufferedImage face = getVanillaSkinPart(skin, ISkinPart.Vanilla.FACE, -1); BufferedImage face = getVanillaSkinPart(skin, ISkinPart.Vanilla.FACE, -1);
BufferedImage body = getVanillaSkinPart(skin, ISkinPart.Vanilla.BODY_FRONT, -1); BufferedImage body = getVanillaSkinPart(skin, ISkinPart.Vanilla.BODY_FRONT, -1);
BufferedImage leftArm = getVanillaSkinPart(skin, ISkinPart.Vanilla.LEFT_ARM, -1); BufferedImage leftArm = getVanillaSkinPart(skin, ISkinPart.Vanilla.LEFT_ARM_FRONT, -1);
BufferedImage rightArm = getVanillaSkinPart(skin, ISkinPart.Vanilla.RIGHT_ARM, -1); BufferedImage rightArm = getVanillaSkinPart(skin, ISkinPart.Vanilla.RIGHT_ARM_FRONT, -1);
BufferedImage leftLeg = getVanillaSkinPart(skin, ISkinPart.Vanilla.LEFT_LEG, -1); BufferedImage leftLeg = getVanillaSkinPart(skin, ISkinPart.Vanilla.LEFT_LEG_FRONT, -1);
BufferedImage rightLeg = getVanillaSkinPart(skin, ISkinPart.Vanilla.RIGHT_LEG, -1); BufferedImage rightLeg = getVanillaSkinPart(skin, ISkinPart.Vanilla.RIGHT_LEG_FRONT, -1);
// Draw the body parts // Draw the body parts
graphics.drawImage(face, 4, 0, null); graphics.drawImage(face, 4, 0, null);

@ -24,7 +24,7 @@
package me.braydon.mc.common.renderer.impl; package me.braydon.mc.common.renderer.impl;
import lombok.NonNull; import lombok.NonNull;
import me.braydon.mc.common.renderer.SkinRenderer; import me.braydon.mc.common.renderer.IsometricSkinRenderer;
import me.braydon.mc.model.skin.ISkinPart; import me.braydon.mc.model.skin.ISkinPart;
import me.braydon.mc.model.skin.Skin; import me.braydon.mc.model.skin.Skin;
@ -37,7 +37,7 @@ import java.awt.image.BufferedImage;
* *
* @author Braydon * @author Braydon
*/ */
public final class IsometricHeadSkinPartRenderer extends SkinRenderer<ISkinPart.Custom> { public final class IsometricHeadSkinPartRenderer extends IsometricSkinRenderer<ISkinPart.Custom> {
public static final IsometricHeadSkinPartRenderer INSTANCE = new IsometricHeadSkinPartRenderer(); public static final IsometricHeadSkinPartRenderer INSTANCE = new IsometricHeadSkinPartRenderer();
private static final double SKEW_A = 26D / 45D; // 0.57777777 private static final double SKEW_A = 26D / 45D; // 0.57777777
@ -84,21 +84,4 @@ public final class IsometricHeadSkinPartRenderer extends SkinRenderer<ISkinPart.
graphics.dispose(); graphics.dispose();
return texture; return texture;
} }
/**
* Draw a part onto the texture.
*
* @param graphics the graphics to draw to
* @param partImage the part image to draw
* @param transform the transform to apply
* @param x the x position to draw at
* @param y the y position to draw at
* @param width the part image width
* @param height the part image height
*/
private void drawPart(@NonNull Graphics2D graphics, @NonNull BufferedImage partImage, @NonNull AffineTransform transform,
double x, double y, int width, int height) {
graphics.setTransform(transform);
graphics.drawImage(partImage, (int) x, (int) y, width, height, null);
}
} }

@ -93,17 +93,17 @@ public interface ISkinPart {
// Body // Body
BODY_FRONT(new Coordinates(20, 20), 8, 12), BODY_FRONT(new Coordinates(20, 20), 8, 12),
BODY_BACK(new Coordinates(20, 36), 8, 12),
BODY_LEFT(new Coordinates(32, 52), 4, 12),
BODY_RIGHT(new Coordinates(44, 20), 4, 12),
// Arms // Arms
LEFT_ARM(new Coordinates(44, 20), 4, 12), LEFT_ARM_TOP(new Coordinates(36, 48), 4, 4),
RIGHT_ARM(new Coordinates(36, 52), new LegacyCoordinates(44, 20, true), 4, 12), RIGHT_ARM_TOP(new Coordinates(44, 16), 4, 4),
LEFT_ARM_FRONT(new Coordinates(44, 20), 4, 12),
RIGHT_ARM_FRONT(new Coordinates(36, 52), new LegacyCoordinates(44, 20, true), 4, 12),
// Legs // Legs
LEFT_LEG(new Coordinates(4, 20), 4, 12), LEFT_LEG_FRONT(new Coordinates(4, 20), 4, 12), // Front
RIGHT_LEG(new Coordinates(20, 52), new LegacyCoordinates(4, 20, true), 4, 12); RIGHT_LEG_FRONT(new Coordinates(20, 52), new LegacyCoordinates(4, 20, true), 4, 12); // Front
/** /**
* The coordinates of this part. * The coordinates of this part.
@ -155,12 +155,12 @@ public interface ISkinPart {
} }
/** /**
* Is this part an arm? * Is this part a front arm?
* *
* @return whether this part is an arm * @return whether this part is a front arm
*/ */
public boolean isArm() { public boolean isFrontArm() {
return this == LEFT_ARM || this == RIGHT_ARM; return this == LEFT_ARM_FRONT || this == RIGHT_ARM_FRONT;
} }
/** /**
@ -215,7 +215,7 @@ public interface ISkinPart {
@AllArgsConstructor @Getter @AllArgsConstructor @Getter
enum Custom implements ISkinPart { enum Custom implements ISkinPart {
HEAD(IsometricHeadSkinPartRenderer.INSTANCE), HEAD(IsometricHeadSkinPartRenderer.INSTANCE),
BODY(BodySkinPartRenderer.INSTANCE); BODY_FLAT(BodySkinPartRenderer.INSTANCE);
/** /**
* The custom renderer to use for this part. * The custom renderer to use for this part.