Skip to content

Commit

Permalink
Fix repeated player skull texture download attempts during RenderTick…
Browse files Browse the repository at this point in the history
… on downloading failure. (#331)
  • Loading branch information
ZekerZhayard authored Feb 8, 2025
1 parent 2f26a07 commit 6bf959d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
29 changes: 28 additions & 1 deletion Common/src/main/java/customskinloader/fake/FakeSkinManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@
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;
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;
Expand Down Expand Up @@ -108,6 +112,29 @@ public static Object[] createThreadDownloadImageData(ImmutableList<Object> list,
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";
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
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; }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package customskinloader.mixin;

import java.util.concurrent.CompletableFuture;

import com.google.common.collect.ImmutableList;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import customskinloader.fake.FakeSkinManager;
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 {
Expand Down Expand Up @@ -40,6 +44,15 @@ public abstract static class V2 {
@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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}

0 comments on commit 6bf959d

Please # to comment.