Skip to content

Commit 6ffbe6a

Browse files
committed
rework: improve the accuracy of skin type determination
* Move code (icu.puqns67.skintypefix.mixin.accessor => icu.puqns67.skintypefix.accessor, icu.puqns67.skintypefix.mixin.patch => icu.puqns67.skintypefix.mixin). * Fix the start and end points of the square may be in the wrong order. * Update the format of log messages.
1 parent 2b4b823 commit 6ffbe6a

File tree

7 files changed

+27
-28
lines changed

7 files changed

+27
-28
lines changed

Diff for: src/main/java/icu/puqns67/skintypefix/mixin/accessor/HttpTextureAccessor.java renamed to src/main/java/icu/puqns67/skintypefix/accessor/HttpTextureAccessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package icu.puqns67.skintypefix.mixin.accessor;
1+
package icu.puqns67.skintypefix.accessor;
22

33
import com.mojang.blaze3d.platform.NativeImage;
44

Diff for: src/main/java/icu/puqns67/skintypefix/mixin/patch/HttpTextureMixin.java renamed to src/main/java/icu/puqns67/skintypefix/mixin/HttpTextureMixin.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package icu.puqns67.skintypefix.mixin.patch;
1+
package icu.puqns67.skintypefix.mixin;
22

33
import com.mojang.blaze3d.platform.NativeImage;
4-
import icu.puqns67.skintypefix.mixin.accessor.HttpTextureAccessor;
4+
import icu.puqns67.skintypefix.accessor.HttpTextureAccessor;
55
import net.fabricmc.api.EnvType;
66
import net.fabricmc.api.Environment;
77
import net.minecraft.client.renderer.texture.HttpTexture;
@@ -22,7 +22,7 @@ public abstract class HttpTextureMixin extends SimpleTexture implements HttpText
2222
private static Logger LOGGER;
2323
@Unique
2424
@Nullable
25-
protected NativeImage image = null;
25+
protected NativeImage skinTypeFix$image = null;
2626
@Shadow
2727
@Nullable
2828
private CompletableFuture<?> future;
@@ -46,27 +46,26 @@ public HttpTextureMixin(ResourceLocation location) {
4646
}
4747

4848
@Unique
49+
@Nullable
4950
public NativeImage skinTypeFix$getImage() {
50-
return this.image;
51+
return this.skinTypeFix$image;
5152
}
5253

5354
/**
5455
* @author Puqns67
5556
* @reason Overwrite the load() function to create another NativeImage at loading, using for check skin.
5657
*/
57-
@Nullable
5858
@Overwrite
59+
@Nullable
5960
private NativeImage load(InputStream stream) {
6061
try {
6162
var result = NativeImage.read(stream);
6263
if (this.processLegacySkin) {
63-
result = this.processLegacySkin(result);
64-
6564
// If this.processLegacySkin is true, the image is the player's skin, so a backup needs to be created for check
66-
if (result != null) {
67-
this.image = new NativeImage(64, 64, true);
68-
this.image.copyFrom(result);
69-
}
65+
this.skinTypeFix$image = new NativeImage(64, 64, true);
66+
this.skinTypeFix$image.copyFrom(result);
67+
68+
result = this.processLegacySkin(result);
7069
}
7170
return result;
7271
} catch (Exception e) {

Diff for: src/main/java/icu/puqns67/skintypefix/mixin/patch/SkinManagerMixin.java renamed to src/main/java/icu/puqns67/skintypefix/mixin/SkinManagerMixin.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package icu.puqns67.skintypefix.mixin.patch;
1+
package icu.puqns67.skintypefix.mixin;
22

33
import com.llamalad7.mixinextras.sugar.Local;
44
import com.mojang.authlib.SignatureState;
55
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
66
import com.mojang.authlib.minecraft.MinecraftProfileTextures;
77
import com.mojang.authlib.minecraft.MinecraftSessionService;
88
import icu.puqns67.skintypefix.SkinTypeFix;
9-
import icu.puqns67.skintypefix.mixin.accessor.HttpTextureAccessor;
9+
import icu.puqns67.skintypefix.accessor.HttpTextureAccessor;
1010
import icu.puqns67.skintypefix.util.Utils;
1111
import icu.puqns67.skintypefix.util.image.Places;
1212
import net.fabricmc.api.EnvType;
@@ -75,14 +75,14 @@ private void onRegisterTextures(
7575
// Get image from PlayerSkinTexture
7676
var skinImage = skinTexture.skinTypeFix$getImage();
7777
if (skinImage == null) {
78-
SkinTypeFix.LOGGER.warn("[SkinTypeFix] [{}] {GET_IMAGE} An error occurred while getting image!", uuid);
78+
SkinTypeFix.LOGGER.warn("[SkinTypeFix] [{}] Unable to get image!", uuid);
7979
return skinModelOrigin;
8080
}
8181

8282
// Check skin type
8383
var needFix = switch (skinModelOrigin) {
84-
case SLIM -> !Places.PLAYER.isAllBlack(skinImage);
85-
case WIDE -> Places.PLAYER.isAllBlack(skinImage);
84+
case SLIM -> !Places.DIFF_PLAYER_SKIN.hasTransparent(skinImage);
85+
case WIDE -> Places.DIFF_PLAYER_SKIN.hasTransparent(skinImage);
8686
};
8787

8888
if (needFix) {

Diff for: src/main/java/icu/puqns67/skintypefix/util/image/Places.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import java.util.ArrayList;
66

77
public class Places {
8-
public static final Places PLAYER = Places.forPlayer();
8+
public static final Places DIFF_PLAYER_SKIN = Places.diffPlayerSkin();
99
private final ArrayList<Square> squares = new ArrayList<>();
1010

1111
public Places() {
1212
}
1313

14-
public static Places forPlayer() {
14+
public static Places diffPlayerSkin() {
1515
var result = new Places();
1616
result.add(50, 16, 51, 19);
1717
result.add(50, 16, 51, 19);
@@ -29,9 +29,9 @@ public void add(int x1, int y1, int x2, int y2) {
2929
this.add(new Square(x1, y1, x2, y2));
3030
}
3131

32-
public boolean isAllBlack(NativeImage image) {
32+
public boolean hasTransparent(NativeImage image) {
3333
for (var square : this.squares) {
34-
if (!square.isAllBlack(image)) {
34+
if (!square.hasTransparent(image)) {
3535
return false;
3636
}
3737
}

Diff for: src/main/java/icu/puqns67/skintypefix/util/image/Point.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public record Point(int x, int y) {
99
}
1010
}
1111

12-
public boolean isBlack(NativeImage image) {
13-
return image.getPixelRGBA(x, y) == 0xff000000;
12+
public boolean isTransparent(NativeImage image) {
13+
return image.getPixelRGBA(x, y) >>> 24 != 0xff;
1414
}
1515
}

Diff for: src/main/java/icu/puqns67/skintypefix/util/image/Square.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
public record Square(Point p1, Point p2) {
88
public Square {
9-
// The point close to (0,0) is p1
10-
if (p2.x() < p1.x() || p1.x() == p2.x() && p2.y() < p1.y()) {
9+
// The point close to (0, 0) is p1, if the order is not correct then reverse them
10+
if (p2.x() < p1.x() || (p2.x() == p1.x() && p2.y() < p1.y())) {
1111
var tmp = p1;
1212
p1 = p2;
1313
p2 = tmp;
@@ -28,9 +28,9 @@ public ArrayList<Point> points() {
2828
return result;
2929
}
3030

31-
public boolean isAllBlack(NativeImage image) {
31+
public boolean hasTransparent(NativeImage image) {
3232
for (var point : this.points()) {
33-
if (!point.isBlack(image)) {
33+
if (!point.isTransparent(image)) {
3434
return false;
3535
}
3636
}

Diff for: src/main/resources/skintypefix.mixins.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"package": "icu.puqns67.skintypefix.mixin.patch",
2+
"package": "icu.puqns67.skintypefix.mixin",
33
"client": [
44
"HttpTextureMixin",
55
"SkinManagerMixin"

0 commit comments

Comments
 (0)