mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-19 11:59:08 +00:00
Fix repeated player skull texture download attempts during RenderTick on downloading failure. (#331)
This commit is contained in:
1 parent
2f26a07dc9
commit
6bf959de49
4 files changed
+45
-9
No files matched your search
@@ -27,7 +27,10 @@ import customskinloader.utils.HttpTextureUtil;
|
||||
import customskinloader.utils.TextureUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.IImageBuffer;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.renderer.texture.NativeImage;
|
||||
import net.minecraft.client.renderer.texture.ReloadableTexture;
|
||||
import net.minecraft.client.renderer.texture.SkinTextureDownloader;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.PlayerSkin$Model;
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
@@ -35,11 +38,12 @@ import net.minecraft.client.resources.SkinManager$1;
|
||||
import net.minecraft.client.resources.SkinManager$CacheKey;
|
||||
import net.minecraft.client.resources.SkinManager$SkinAvailableCallback;
|
||||
import net.minecraft.client.resources.SkinManager$TextureCache;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class FakeSkinManager {
|
||||
/**
|
||||
* 1.20.1-
|
||||
* Invoked from {@link SkinManager(TextureManager , File, MinecraftSessionService)}
|
||||
* Invoked from {@link SkinManager(TextureManager, File, MinecraftSessionService)}
|
||||
*/
|
||||
public static void setSkinCacheDir(File skinCacheDirectory) {
|
||||
HttpTextureUtil.defaultCacheDir = skinCacheDirectory;
|
||||
@@ -108,6 +112,29 @@ public class FakeSkinManager {
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 24w46a+
|
||||
* Invoked from {@link SkinManager$TextureCache#registerTexture(MinecraftProfileTexture)}
|
||||
*/
|
||||
public static CompletableFuture<?> clearCachedFuture(CompletableFuture<?> future) {
|
||||
CompletableFuture<Object> completableFuture = new CompletableFuture<>();
|
||||
future.thenAccept(completableFuture::complete);
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
/**
|
||||
* 24w46a+
|
||||
* Invoked from {@link SkinTextureDownloader#lambda$registerTextureInManager$2(Minecraft, ResourceLocation, NativeImage)}
|
||||
*/
|
||||
public static void registerTextureInManager(TextureManager manager, ResourceLocation location, AbstractTexture texture) {
|
||||
Object texture0 = FakeInterfaceManager.ResourceLocation_getTexture(location);
|
||||
if (texture0 != null) {
|
||||
manager.registerAndLoad(location, (ReloadableTexture) texture0);
|
||||
} else {
|
||||
manager.loadTexture(location, texture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final static String KEY = "CustomSkinLoaderInfo";
|
||||
/**
|
||||
|
||||
@@ -3,10 +3,12 @@ package net.minecraft.client.renderer.texture;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class SkinTextureDownloader {
|
||||
public static CompletableFuture<?> downloadAndRegisterSkin(ResourceLocation location, Path path, String string, boolean b) { return null; }
|
||||
public static NativeImage processLegacySkin(NativeImage nativeImage, String url) { return null; }
|
||||
public static NativeImage lambda$downloadAndRegisterSkin$0(Path path, String url, boolean b) { return null; }
|
||||
public static ResourceLocation lambda$registerTextureInManager$2(Minecraft minecraft, ResourceLocation location, NativeImage image) { return null; }
|
||||
}
|
||||
+13
@@ -1,5 +1,7 @@
|
||||
package customskinloader.mixin;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import customskinloader.fake.FakeSkinManager;
|
||||
@@ -7,7 +9,9 @@ import net.minecraft.client.resources.SkinManager$TextureCache;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
|
||||
|
||||
public abstract class MixinSkinManager$TextureCache {
|
||||
@@ -40,6 +44,15 @@ public abstract class MixinSkinManager$TextureCache {
|
||||
@Shadow
|
||||
private MinecraftProfileTexture.Type type;
|
||||
|
||||
@Inject(
|
||||
method = "Lnet/minecraft/client/resources/SkinManager$TextureCache;registerTexture(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Ljava/util/concurrent/CompletableFuture;",
|
||||
at = @At("RETURN"),
|
||||
cancellable = true
|
||||
)
|
||||
private void inject_registerTexture(CallbackInfoReturnable<CompletableFuture<?>> cir) {
|
||||
cir.setReturnValue(FakeSkinManager.clearCachedFuture(cir.getReturnValue()));
|
||||
}
|
||||
|
||||
@ModifyArgs(
|
||||
method = "Lnet/minecraft/client/resources/SkinManager$TextureCache;registerTexture(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Ljava/util/concurrent/CompletableFuture;",
|
||||
at = @At(
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package customskinloader.mixin;
|
||||
|
||||
import customskinloader.fake.itf.FakeInterfaceManager;
|
||||
import customskinloader.fake.FakeSkinManager;
|
||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||
import net.minecraft.client.renderer.texture.ReloadableTexture;
|
||||
import net.minecraft.client.renderer.texture.SkinTextureDownloader;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -21,11 +20,6 @@ public abstract class MixinSkinTextureDownloader {
|
||||
)
|
||||
)
|
||||
private static void redirect_lambda$registerTextureInManager$2(TextureManager manager, ResourceLocation location, AbstractTexture texture) {
|
||||
Object texture0 = FakeInterfaceManager.ResourceLocation_getTexture(location);
|
||||
if (texture0 != null) {
|
||||
manager.registerAndLoad(location, (ReloadableTexture) texture0);
|
||||
} else {
|
||||
manager.loadTexture(location, texture);
|
||||
}
|
||||
FakeSkinManager.registerTextureInManager(manager, location, texture);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user