mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
backport to 1.20
This commit is contained in:
@@ -3,7 +3,6 @@ package net.lionarius.skinrestorer.mixin;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.minecraft.server.Services;
|
||||
import net.minecraft.server.players.GameProfileCache;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -11,12 +10,10 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mixin(SkullBlockEntity.class)
|
||||
public abstract class SkullBlockEntityMixin {
|
||||
@@ -24,31 +21,30 @@ public abstract class SkullBlockEntityMixin {
|
||||
@Shadow
|
||||
private static GameProfileCache profileCache;
|
||||
|
||||
@Inject(method = "fetchGameProfile", at = @At("HEAD"),
|
||||
@Inject(method = "updateGameprofile", at = @At("HEAD"),
|
||||
cancellable = true)
|
||||
private static void fetchProfileByName(String name, CallbackInfoReturnable<CompletableFuture<Optional<GameProfile>>> cir) {
|
||||
if (profileCache == null)
|
||||
private static void fetchProfileByName(GameProfile profile, Consumer<GameProfile> profileConsumer, CallbackInfo ci) {
|
||||
if (profileCache == null || profile.isComplete())
|
||||
return;
|
||||
|
||||
var profileOpt = profileCache.get(name);
|
||||
var profileOpt = profileCache.get(profile.getName());
|
||||
|
||||
skinrestorer$replaceSkin(profileOpt, cir);
|
||||
skinrestorer$replaceSkin(profileOpt, profileConsumer, ci);
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static void skinrestorer$replaceSkin(Optional<GameProfile> profileOpt, CallbackInfoReturnable<CompletableFuture<Optional<GameProfile>>> cir) {
|
||||
private static void skinrestorer$replaceSkin(Optional<GameProfile> profileOpt, Consumer<GameProfile> profileConsumer, CallbackInfo ci) {
|
||||
if (profileOpt.isEmpty())
|
||||
return;
|
||||
|
||||
var profile = PlayerUtils.cloneGameProfile(profileOpt.get());
|
||||
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||
cir.setReturnValue(CompletableFuture.supplyAsync(() -> {
|
||||
var skin = SkinRestorer.getSkinStorage().getSkin(profile.getId(), false);
|
||||
PlayerUtils.applyRestoredSkin(profile, skin.value());
|
||||
|
||||
return Optional.of(profile);
|
||||
}));
|
||||
profileConsumer.accept(profile);
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user