Add Forge 1.20.1 HD 3D Skin Layers compatibility

This commit is contained in:
f1den committed 2026-07-11 19:36:48 +03:00
1 parent 2034c75f7d
commit efac5d242b
9 files changed
+259 -3

No files matched your search

@@ -2,6 +2,10 @@ package xyz.nightsync.skinsg.mixin;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.renderer.texture.HttpTexture;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.DefaultPlayerSkin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -18,6 +22,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
*/
@Mixin(HttpTexture.class)
public abstract class SkinMagicMixin {
private static final Logger SKINSG_LOGGER = LoggerFactory.getLogger("skinsg");
@Shadow
private static void setNoAlpha(NativeImage img, int x1, int y1, int x2, int y2) {}
@@ -27,8 +32,9 @@ public abstract class SkinMagicMixin {
@Inject(method = "processLegacySkin", at = @At("HEAD"), cancellable = true)
private void skinsg$processLegacySkin(NativeImage image, CallbackInfoReturnable<@Nullable NativeImage> cir) {
final int h = image.getHeight();
final int w = image.getWidth();
try {
final int h = image.getHeight();
final int w = image.getWidth();
final int s = w / 8;
final int x64 = s * 8;
@@ -80,5 +86,28 @@ public abstract class SkinMagicMixin {
cir.setReturnValue(image);
cir.cancel();
} catch (Exception | LinkageError error) {
SKINSG_LOGGER.error("[SkinsG] Failed to process skin image; falling back to the default Steve skin.", error);
try {
image.close();
} catch (RuntimeException closeError) {
SKINSG_LOGGER.debug("[SkinsG] Failed to close rejected skin image.", closeError);
}
cir.setReturnValue(skinsg$loadSteve());
cir.cancel();
}
}
private static NativeImage skinsg$loadSteve() {
try {
var resource = Minecraft.getInstance().getResourceManager()
.getResource(DefaultPlayerSkin.getDefaultSkin()).orElseThrow();
try (var stream = resource.open()) {
return NativeImage.read(stream);
}
} catch (Exception | LinkageError fallbackError) {
SKINSG_LOGGER.error("[SkinsG] Default Steve skin could not be loaded; vanilla will use its fallback.", fallbackError);
return null;
}
}
}