mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-20 22:42:16 +00:00
Support Fabric for Minecraft 1.15.x (#75)
* Support Fabric for Minecraft 1.15.x * Remove unused imports
This commit is contained in:
1 parent
7adb0f9ef7
commit
e19b9d860f
11 files changed
+144
-23
No files matched your search
@@ -145,6 +145,10 @@ public class FakeSkinBuffer implements net.minecraft.client.renderer.IImageBuffe
|
||||
//A callback when skin loaded, nothing to do
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.skinAvailable();
|
||||
}
|
||||
|
||||
private static int getARGB(int a, int r, int g, int b) {
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
@@ -13,15 +13,13 @@ import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.utils.HttpTextureUtil;
|
||||
import customskinloader.utils.HttpTextureUtil.HttpTextureInfo;
|
||||
|
||||
import customskinloader.utils.MinecraftUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.IImageBuffer;
|
||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
|
||||
@@ -47,13 +45,11 @@ public class FakeSkinManager {
|
||||
HttpTextureInfo info = HttpTextureUtil.toHttpTextureInfo(profileTexture.getUrl());
|
||||
|
||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);
|
||||
ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation);
|
||||
|
||||
if (itextureobject != null)//Have already loaded
|
||||
if (this.textureManager.getTexture(resourcelocation) != null)//Have already loaded
|
||||
makeCallback(skinAvailableCallback, textureType, resourcelocation, profileTexture);
|
||||
else {
|
||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(),
|
||||
new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, profileTexture));
|
||||
ThreadDownloadImageData threaddownloadimagedata = MinecraftUtil.createThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, profileTexture), textureType);
|
||||
if (skinAvailableCallback instanceof FakeClientPlayer.LegacyBuffer)//Cache for client player
|
||||
FakeClientPlayer.textureCache.put(resourcelocation, threaddownloadimagedata);
|
||||
this.textureManager.loadTexture(resourcelocation, threaddownloadimagedata);
|
||||
@@ -62,7 +58,7 @@ public class FakeSkinManager {
|
||||
}
|
||||
|
||||
public void loadProfileTextures(final GameProfile profile, final SkinAvailableCallback skinAvailableCallback, final boolean requireSecure) {
|
||||
THREAD_POOL.submit(new Runnable() {
|
||||
THREAD_POOL.execute(new Runnable() {
|
||||
public void run() {
|
||||
final Map<Type, MinecraftProfileTexture> map = Maps.newHashMap();
|
||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
||||
@@ -128,5 +124,9 @@ public class FakeSkinManager {
|
||||
|
||||
FakeSkinManager.makeCallback(callback, type, location, texture);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
this.skinAvailable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,22 @@
|
||||
package customskinloader.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.IImageBuffer;
|
||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Alexander Xia
|
||||
@@ -33,6 +35,32 @@ public class MinecraftUtil {
|
||||
return Minecraft.getMinecraft().getSkinManager();
|
||||
}
|
||||
|
||||
private static boolean is_1_15_plus = false;
|
||||
private static Constructor<ThreadDownloadImageData> constructor = null;
|
||||
public static ThreadDownloadImageData createThreadDownloadImageData(File cacheFileIn, String imageUrlIn, ResourceLocation textureResourceLocation, IImageBuffer imageBufferIn, MinecraftProfileTexture.Type textureType) {
|
||||
if (constructor == null) {
|
||||
try {
|
||||
constructor = ThreadDownloadImageData.class.getConstructor(File.class, String.class, ResourceLocation.class, boolean.class, Runnable.class); // For 1.15+
|
||||
is_1_15_plus = true;
|
||||
} catch (NoSuchMethodException e1) {
|
||||
try {
|
||||
constructor = ThreadDownloadImageData.class.getConstructor(File.class, String.class, ResourceLocation.class, IImageBuffer.class); // For 1.15-
|
||||
} catch (NoSuchMethodException e2) {
|
||||
throw new RuntimeException(e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (is_1_15_plus) {
|
||||
return constructor.newInstance(cacheFileIn, imageUrlIn, textureResourceLocation, textureType == MinecraftProfileTexture.Type.SKIN, imageBufferIn);
|
||||
} else {
|
||||
return constructor.newInstance(cacheFileIn, imageUrlIn, textureResourceLocation, imageBufferIn);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static ArrayList<String> minecraftVersion = new ArrayList<String>();
|
||||
private static String minecraftMainVersion = null;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.minecraft.client.renderer;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import net.minecraft.client.renderer.texture.NativeImage;
|
||||
|
||||
public interface IImageBuffer extends Runnable {
|
||||
BufferedImage parseUserSkin(BufferedImage image);
|
||||
|
||||
NativeImage func_195786_a(NativeImage image);
|
||||
|
||||
void skinAvailable();
|
||||
}
|
||||
+2
-2
@@ -30,7 +30,7 @@ minecraft {
|
||||
}
|
||||
|
||||
jar {
|
||||
exclude 'net/**'
|
||||
exclude 'net/minecraft/client/renderer/texture/**'
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -41,7 +41,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.spongepowered:mixin:0.7.11-SNAPSHOT'
|
||||
implementation 'org.spongepowered:mixin:0.8-SNAPSHOT'
|
||||
}
|
||||
|
||||
mixin {
|
||||
|
||||
@@ -24,11 +24,7 @@
|
||||
"mixins.customskinloader.json"
|
||||
],
|
||||
|
||||
"requires": {
|
||||
"fabricloader": ">=0.4.0",
|
||||
"fabric": "*"
|
||||
},
|
||||
"suggests": {
|
||||
"flamingo": "*"
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.0"
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,13 @@
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"package": "customskinloader.fabric.mixin",
|
||||
"client": [
|
||||
"MixinFakeSkinManager",
|
||||
"MixinGuiPlayerTabOverlay",
|
||||
"MixinMinecraft",
|
||||
"MixinSkinManager"
|
||||
],
|
||||
"refmap": "mixins.customskinloader.refmap.json",
|
||||
"plugin": "customskinloader.fabric.MixinConfigPlugin",
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package customskinloader.fabric;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
|
||||
public class MixinConfigPlugin implements IMixinConfigPlugin {
|
||||
public static boolean hasITextureObject = true;
|
||||
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRefMapperConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMixins() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
if (!hasITextureObject && targetClassName.equals("customskinloader.fake.FakeSkinManager")) {
|
||||
for (MethodNode mn : targetClass.methods) {
|
||||
if (mn.name.equals("loadSkin") && mn.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/class_1071$class_1072;)Lnet/minecraft/class_2960;")) {
|
||||
for (AbstractInsnNode ain : mn.instructions.toArray()) {
|
||||
if (ain instanceof MethodInsnNode) {
|
||||
MethodInsnNode min = (MethodInsnNode) ain;
|
||||
min.desc = min.desc.replace("Lnet/minecraft/class_1062;", "Lnet/minecraft/class_1044;");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package customskinloader.fabric.mixin;
|
||||
|
||||
import customskinloader.fake.FakeSkinManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
/**
|
||||
* @see customskinloader.fabric.MixinConfigPlugin#preApply
|
||||
*/
|
||||
@Mixin(FakeSkinManager.class)
|
||||
public abstract class MixinFakeSkinManager {
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||
import customskinloader.fabric.MixinConfigPlugin;
|
||||
import customskinloader.fake.FakeSkinManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
@@ -24,7 +25,12 @@ public abstract class MixinSkinManager {
|
||||
method = "Lnet/minecraft/client/resources/SkinManager;<init>(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V",
|
||||
at = @At("RETURN")
|
||||
)
|
||||
private void initFakeSkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService, CallbackInfo callbackInfo) {
|
||||
private void inject_init(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService, CallbackInfo callbackInfo) {
|
||||
try {
|
||||
Class.forName("net.minecraft.class_1062", false, SkinManager.class.getClassLoader()); // net.minecraft.client.texture.Texture
|
||||
} catch (ClassNotFoundException e) {
|
||||
MixinConfigPlugin.hasITextureObject = false;
|
||||
}
|
||||
this.fakeManager = new FakeSkinManager(textureManagerInstance, skinCacheDirectory, sessionService);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ jar {
|
||||
"Implementation-Timestamp" : new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
])
|
||||
}
|
||||
exclude 'net/minecraft/client/renderer/**'
|
||||
exclude 'net/minecraft/client/renderer/texture/**'
|
||||
exclude 'net/minecraftforge/**'
|
||||
}
|
||||
sourceSets {
|
||||
|
||||
Reference in new issue
Block a user