(Neo)forge impl, fabric cleanup

This commit is contained in:
Phoenix-Starlight 2023-10-19 19:55:56 -07:00
parent b1efc154be
commit c6f805cfe2
3 changed files with 45 additions and 3 deletions

View File

@ -1,7 +1,6 @@
package org.embeddedt.modernfix.fabric.mixin.perf.cache_profile_texture_url;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import org.apache.commons.io.FilenameUtils;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
import org.embeddedt.modernfix.duck.ICachedProfileTexture;

View File

@ -2,7 +2,6 @@ package org.embeddedt.modernfix.fabric.mixin.perf.cache_profile_texture_url;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
@ -25,7 +24,7 @@ public abstract class YggdrasilGsonDeserializerMixin {
target = "Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;getUrl()Ljava/lang/String;"
)
)
private String setCachedURL(MinecraftProfileTexture texture, Operation<String> original) {
private String setCachedHash(MinecraftProfileTexture texture, Operation<String> original) {
// Because we don't have it set from deserialization
String url = original.call(texture);
((ICachedProfileTexture)texture).setCachedHash(url);

View File

@ -0,0 +1,44 @@
package org.embeddedt.modernfix.forge.mixin.perf.cache_profile_texture_url;
import com.google.common.cache.CacheBuilder;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.resources.SkinManager;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import java.util.concurrent.TimeUnit;
import java.util.Map;
@Mixin(value=SkinManager.class)
@ClientOnlyMixin
public abstract class SkinManagerMixin {
/**
* @author Fury_Phoenix
* @reason No lib mixins on (neo)forge, yet
* **/
@Unique
private final Map<MinecraftProfileTexture, String> hashCache = CacheBuilder.newBuilder()
.expireAfterAccess(60, TimeUnit.SECONDS)
.concurrencyLevel(1)
// Excessive use of type hinting due to it assuming Object as the broadest correct type
.<MinecraftProfileTexture, String>build()
.asMap();
@WrapOperation
(
method = "registerTexture",
at = @At(
value = "INVOKE",
target = "Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;getHash()Ljava/lang/String;",
remap = false
)
)
private String stashCachedHash(SkinManager manager, Operation<String> original, MinecraftProfileTexture texture) {
return hashCache.computeIfAbsent(texture, k -> original.call());
}
}