diff --git a/src/main/java/icu/puqns67/skintypefix/mixin/accessor/HttpTextureAccessor.java b/src/main/java/icu/puqns67/skintypefix/accessor/HttpTextureAccessor.java similarity index 77% rename from src/main/java/icu/puqns67/skintypefix/mixin/accessor/HttpTextureAccessor.java rename to src/main/java/icu/puqns67/skintypefix/accessor/HttpTextureAccessor.java index ba44b5a..6ab2093 100644 --- a/src/main/java/icu/puqns67/skintypefix/mixin/accessor/HttpTextureAccessor.java +++ b/src/main/java/icu/puqns67/skintypefix/accessor/HttpTextureAccessor.java @@ -1,4 +1,4 @@ -package icu.puqns67.skintypefix.mixin.accessor; +package icu.puqns67.skintypefix.accessor; import com.mojang.blaze3d.platform.NativeImage; diff --git a/src/main/java/icu/puqns67/skintypefix/mixin/patch/HttpTextureMixin.java b/src/main/java/icu/puqns67/skintypefix/mixin/HttpTextureMixin.java similarity index 87% rename from src/main/java/icu/puqns67/skintypefix/mixin/patch/HttpTextureMixin.java rename to src/main/java/icu/puqns67/skintypefix/mixin/HttpTextureMixin.java index 97347e7..5807e4b 100644 --- a/src/main/java/icu/puqns67/skintypefix/mixin/patch/HttpTextureMixin.java +++ b/src/main/java/icu/puqns67/skintypefix/mixin/HttpTextureMixin.java @@ -1,7 +1,7 @@ -package icu.puqns67.skintypefix.mixin.patch; +package icu.puqns67.skintypefix.mixin; import com.mojang.blaze3d.platform.NativeImage; -import icu.puqns67.skintypefix.mixin.accessor.HttpTextureAccessor; +import icu.puqns67.skintypefix.accessor.HttpTextureAccessor; import net.minecraft.client.renderer.texture.HttpTexture; import net.minecraft.client.renderer.texture.SimpleTexture; import net.minecraft.resources.ResourceLocation; @@ -46,6 +46,7 @@ public abstract class HttpTextureMixin extends SimpleTexture implements HttpText } @Unique + @Nullable public NativeImage skinTypeFix$getImage() { return this.skinTypeFix$image; } @@ -54,19 +55,17 @@ public abstract class HttpTextureMixin extends SimpleTexture implements HttpText * @author Puqns67 * @reason Overwrite the load() function to create another NativeImage at loading, using for check skin. */ - @Nullable @Overwrite + @Nullable private NativeImage load(InputStream stream) { try { var result = NativeImage.read(stream); if (this.processLegacySkin) { - result = this.processLegacySkin(result); - // If this.processLegacySkin is true, the image is the player's skin, so a backup needs to be created for check - if (result != null) { - this.skinTypeFix$image = new NativeImage(64, 64, true); - this.skinTypeFix$image.copyFrom(result); - } + this.skinTypeFix$image = new NativeImage(64, 64, true); + this.skinTypeFix$image.copyFrom(result); + + result = this.processLegacySkin(result); } return result; } catch (Exception e) { diff --git a/src/main/java/icu/puqns67/skintypefix/mixin/patch/SkinManagerMixin.java b/src/main/java/icu/puqns67/skintypefix/mixin/SkinManagerMixin.java similarity index 89% rename from src/main/java/icu/puqns67/skintypefix/mixin/patch/SkinManagerMixin.java rename to src/main/java/icu/puqns67/skintypefix/mixin/SkinManagerMixin.java index 53f89ea..a0681f0 100644 --- a/src/main/java/icu/puqns67/skintypefix/mixin/patch/SkinManagerMixin.java +++ b/src/main/java/icu/puqns67/skintypefix/mixin/SkinManagerMixin.java @@ -1,4 +1,4 @@ -package icu.puqns67.skintypefix.mixin.patch; +package icu.puqns67.skintypefix.mixin; import com.llamalad7.mixinextras.sugar.Local; import com.mojang.authlib.SignatureState; @@ -7,7 +7,7 @@ import com.mojang.authlib.minecraft.MinecraftProfileTextures; import com.mojang.authlib.minecraft.MinecraftSessionService; import icu.puqns67.skintypefix.Config; import icu.puqns67.skintypefix.SkinTypeFix; -import icu.puqns67.skintypefix.mixin.accessor.HttpTextureAccessor; +import icu.puqns67.skintypefix.accessor.HttpTextureAccessor; import icu.puqns67.skintypefix.util.Utils; import icu.puqns67.skintypefix.util.image.Places; import net.minecraft.client.renderer.texture.TextureManager; @@ -76,19 +76,19 @@ public class SkinManagerMixin { // Get image from PlayerSkinTexture var skinImage = skinTexture.skinTypeFix$getImage(); if (skinImage == null) { - SkinTypeFix.LOGGER.warn("[SkinTypeFix] [{}] {GET_IMAGE} An error occurred while getting image!", uuid); + SkinTypeFix.LOGGER.warn("[{}] Unable to get image!", uuid); return skinModelOrigin; } // Check skin type var needFix = switch (skinModelOrigin) { - case SLIM -> !Places.PLAYER.isAllBlack(skinImage); - case WIDE -> Places.PLAYER.isAllBlack(skinImage); + case SLIM -> !Places.DIFF_PLAYER_SKIN.hasTransparent(skinImage); + case WIDE -> Places.DIFF_PLAYER_SKIN.hasTransparent(skinImage); }; if (needFix) { var skinModelFixed = Utils.reverseModelType(skinModelOrigin); - SkinTypeFix.LOGGER.info("[SkinTypeFix] [{}] Fixed skin type: {} -> {}", uuid, skinModelOrigin, skinModelFixed); + SkinTypeFix.LOGGER.info("[{}] Fixed skin type: {} -> {}", uuid, skinModelOrigin, skinModelFixed); return skinModelFixed; } diff --git a/src/main/java/icu/puqns67/skintypefix/util/image/Places.java b/src/main/java/icu/puqns67/skintypefix/util/image/Places.java index 6573304..e2f8fa7 100644 --- a/src/main/java/icu/puqns67/skintypefix/util/image/Places.java +++ b/src/main/java/icu/puqns67/skintypefix/util/image/Places.java @@ -5,13 +5,13 @@ import com.mojang.blaze3d.platform.NativeImage; import java.util.ArrayList; public class Places { - public static final Places PLAYER = Places.forPlayer(); + public static final Places DIFF_PLAYER_SKIN = Places.diffPlayerSkin(); private final ArrayList squares = new ArrayList<>(); public Places() { } - public static Places forPlayer() { + public static Places diffPlayerSkin() { var result = new Places(); result.add(50, 16, 51, 19); result.add(50, 16, 51, 19); @@ -29,9 +29,9 @@ public class Places { this.add(new Square(x1, y1, x2, y2)); } - public boolean isAllBlack(NativeImage image) { + public boolean hasTransparent(NativeImage image) { for (var square : this.squares) { - if (!square.isAllBlack(image)) { + if (!square.hasTransparent(image)) { return false; } } diff --git a/src/main/java/icu/puqns67/skintypefix/util/image/Point.java b/src/main/java/icu/puqns67/skintypefix/util/image/Point.java index 9d43b2d..e77e242 100644 --- a/src/main/java/icu/puqns67/skintypefix/util/image/Point.java +++ b/src/main/java/icu/puqns67/skintypefix/util/image/Point.java @@ -9,7 +9,7 @@ public record Point(int x, int y) { } } - public boolean isBlack(NativeImage image) { - return image.getPixelRGBA(x, y) == 0xff000000; + public boolean isTransparent(NativeImage image) { + return image.getPixelRGBA(x, y) >>> 24 != 0xff; } } diff --git a/src/main/java/icu/puqns67/skintypefix/util/image/Square.java b/src/main/java/icu/puqns67/skintypefix/util/image/Square.java index 45c8c1b..5b1a984 100644 --- a/src/main/java/icu/puqns67/skintypefix/util/image/Square.java +++ b/src/main/java/icu/puqns67/skintypefix/util/image/Square.java @@ -6,8 +6,8 @@ import java.util.ArrayList; public record Square(Point p1, Point p2) { public Square { - // The point close to (0,0) is p1 - if (p2.x() < p1.x() || p1.x() == p2.x() && p2.y() < p1.y()) { + // The point close to (0, 0) is p1, if the order is not correct then reverse them + if (p2.x() < p1.x() || (p2.x() == p1.x() && p2.y() < p1.y())) { var tmp = p1; p1 = p2; p2 = tmp; @@ -28,9 +28,9 @@ public record Square(Point p1, Point p2) { return result; } - public boolean isAllBlack(NativeImage image) { + public boolean hasTransparent(NativeImage image) { for (var point : this.points()) { - if (!point.isBlack(image)) { + if (!point.isTransparent(image)) { return false; } } diff --git a/src/main/resources/skintypefix.mixins.json b/src/main/resources/skintypefix.mixins.json index 4b2779c..71fc342 100644 --- a/src/main/resources/skintypefix.mixins.json +++ b/src/main/resources/skintypefix.mixins.json @@ -1,5 +1,5 @@ { - "package": "icu.puqns67.skintypefix.mixin.patch", + "package": "icu.puqns67.skintypefix.mixin", "client": [ "HttpTextureMixin", "SkinManagerMixin"