Skip to content

Commit 6bf959d

Browse files
authored
Fix repeated player skull texture download attempts during RenderTick on downloading failure. (#331)
1 parent 2f26a07 commit 6bf959d

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

Common/src/main/java/customskinloader/fake/FakeSkinManager.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,23 @@
2727
import customskinloader.utils.TextureUtil;
2828
import net.minecraft.client.Minecraft;
2929
import net.minecraft.client.renderer.IImageBuffer;
30+
import net.minecraft.client.renderer.texture.AbstractTexture;
3031
import net.minecraft.client.renderer.texture.NativeImage;
32+
import net.minecraft.client.renderer.texture.ReloadableTexture;
33+
import net.minecraft.client.renderer.texture.SkinTextureDownloader;
3134
import net.minecraft.client.renderer.texture.TextureManager;
3235
import net.minecraft.client.resources.PlayerSkin$Model;
3336
import net.minecraft.client.resources.SkinManager;
3437
import net.minecraft.client.resources.SkinManager$1;
3538
import net.minecraft.client.resources.SkinManager$CacheKey;
3639
import net.minecraft.client.resources.SkinManager$SkinAvailableCallback;
3740
import net.minecraft.client.resources.SkinManager$TextureCache;
41+
import net.minecraft.util.ResourceLocation;
3842

3943
public class FakeSkinManager {
4044
/**
4145
* 1.20.1-
42-
* Invoked from {@link SkinManager(TextureManager , File, MinecraftSessionService)}
46+
* Invoked from {@link SkinManager(TextureManager, File, MinecraftSessionService)}
4347
*/
4448
public static void setSkinCacheDir(File skinCacheDirectory) {
4549
HttpTextureUtil.defaultCacheDir = skinCacheDirectory;
@@ -108,6 +112,29 @@ public static Object[] createThreadDownloadImageData(ImmutableList<Object> list,
108112
return params;
109113
}
110114

115+
/**
116+
* 24w46a+
117+
* Invoked from {@link SkinManager$TextureCache#registerTexture(MinecraftProfileTexture)}
118+
*/
119+
public static CompletableFuture<?> clearCachedFuture(CompletableFuture<?> future) {
120+
CompletableFuture<Object> completableFuture = new CompletableFuture<>();
121+
future.thenAccept(completableFuture::complete);
122+
return completableFuture;
123+
}
124+
125+
/**
126+
* 24w46a+
127+
* Invoked from {@link SkinTextureDownloader#lambda$registerTextureInManager$2(Minecraft, ResourceLocation, NativeImage)}
128+
*/
129+
public static void registerTextureInManager(TextureManager manager, ResourceLocation location, AbstractTexture texture) {
130+
Object texture0 = FakeInterfaceManager.ResourceLocation_getTexture(location);
131+
if (texture0 != null) {
132+
manager.registerAndLoad(location, (ReloadableTexture) texture0);
133+
} else {
134+
manager.loadTexture(location, texture);
135+
}
136+
}
137+
111138

112139
private final static String KEY = "CustomSkinLoaderInfo";
113140
/**

Dummy/src/main/java/net/minecraft/client/renderer/texture/SkinTextureDownloader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import java.nio.file.Path;
44
import java.util.concurrent.CompletableFuture;
55

6+
import net.minecraft.client.Minecraft;
67
import net.minecraft.util.ResourceLocation;
78

89
public class SkinTextureDownloader {
910
public static CompletableFuture<?> downloadAndRegisterSkin(ResourceLocation location, Path path, String string, boolean b) { return null; }
1011
public static NativeImage processLegacySkin(NativeImage nativeImage, String url) { return null; }
1112
public static NativeImage lambda$downloadAndRegisterSkin$0(Path path, String url, boolean b) { return null; }
13+
public static ResourceLocation lambda$registerTextureInManager$2(Minecraft minecraft, ResourceLocation location, NativeImage image) { return null; }
1214
}

Vanilla/Common/src/main/java/customskinloader/mixin/MixinSkinManager$TextureCache.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package customskinloader.mixin;
22

3+
import java.util.concurrent.CompletableFuture;
4+
35
import com.google.common.collect.ImmutableList;
46
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
57
import customskinloader.fake.FakeSkinManager;
68
import net.minecraft.client.resources.SkinManager$TextureCache;
79
import org.spongepowered.asm.mixin.Mixin;
810
import org.spongepowered.asm.mixin.Shadow;
911
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
1013
import org.spongepowered.asm.mixin.injection.ModifyArgs;
14+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1115
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
1216

1317
public abstract class MixinSkinManager$TextureCache {
@@ -40,6 +44,15 @@ public abstract static class V2 {
4044
@Shadow
4145
private MinecraftProfileTexture.Type type;
4246

47+
@Inject(
48+
method = "Lnet/minecraft/client/resources/SkinManager$TextureCache;registerTexture(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Ljava/util/concurrent/CompletableFuture;",
49+
at = @At("RETURN"),
50+
cancellable = true
51+
)
52+
private void inject_registerTexture(CallbackInfoReturnable<CompletableFuture<?>> cir) {
53+
cir.setReturnValue(FakeSkinManager.clearCachedFuture(cir.getReturnValue()));
54+
}
55+
4356
@ModifyArgs(
4457
method = "Lnet/minecraft/client/resources/SkinManager$TextureCache;registerTexture(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Ljava/util/concurrent/CompletableFuture;",
4558
at = @At(

Vanilla/Common/src/main/java/customskinloader/mixin/MixinSkinTextureDownloader.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package customskinloader.mixin;
22

3-
import customskinloader.fake.itf.FakeInterfaceManager;
3+
import customskinloader.fake.FakeSkinManager;
44
import net.minecraft.client.renderer.texture.AbstractTexture;
5-
import net.minecraft.client.renderer.texture.ReloadableTexture;
65
import net.minecraft.client.renderer.texture.SkinTextureDownloader;
76
import net.minecraft.client.renderer.texture.TextureManager;
87
import net.minecraft.util.ResourceLocation;
@@ -21,11 +20,6 @@ public abstract class MixinSkinTextureDownloader {
2120
)
2221
)
2322
private static void redirect_lambda$registerTextureInManager$2(TextureManager manager, ResourceLocation location, AbstractTexture texture) {
24-
Object texture0 = FakeInterfaceManager.ResourceLocation_getTexture(location);
25-
if (texture0 != null) {
26-
manager.registerAndLoad(location, (ReloadableTexture) texture0);
27-
} else {
28-
manager.loadTexture(location, texture);
29-
}
23+
FakeSkinManager.registerTextureInManager(manager, location, texture);
3024
}
3125
}

0 commit comments

Comments
 (0)