package de.winniepat.citrus.mixins;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import de.winniepat.citrus.cosmetics.capes.CapeHandler;
import de.winniepat.citrus.managers.RankManager;
import net.minecraft.client.network.*;
import net.minecraft.client.util.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;

import java.io.IOException;

@Mixin(AbstractClientPlayerEntity.class)
public class AbstractClientPlayerEntityMixin {

    @Shadow
    private PlayerListEntry playerListEntry;

    @ModifyReturnValue(method = "getSkinTextures", at = @At("RETURN"))
    public SkinTextures handleCapes(SkinTextures original) throws IOException {
        AbstractClientPlayerEntity player = (AbstractClientPlayerEntity) (Object) this;
        RankManager.getRankIcon(player.getUuid());

        if (playerListEntry == null) {
            return DefaultSkinHelper.getSkinTextures(((AbstractClientPlayerEntity) (Object) this).getUuid());
        } else {
            return CapeHandler.getCapes(original, (AbstractClientPlayerEntity) (Object) this);
        }
    }
}