package net.minecraft.client.player;

import net.minecraft.world.item.Items;
import net.minecraft.world.entity.ai.attributes.Attributes;
import com.google.common.hash.Hashing;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import java.io.File;
import net.minecraft.util.StringUtil;
import net.minecraft.client.renderer.texture.HttpTexture;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.resources.ResourceLocation;
import javax.annotation.Nullable;
import net.minecraft.world.level.GameType;
import net.minecraft.client.Minecraft;
import net.minecraft.world.level.Level;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.world.entity.player.Player;

public abstract class AbstractClientPlayer extends Player {
    private PlayerInfo playerInfo;
    public float elytraRotX;
    public float elytraRotY;
    public float elytraRotZ;
    public final ClientLevel clientLevel;
    
    public AbstractClientPlayer(final ClientLevel dym, final GameProfile gameProfile) {
        super(dym, dym.getSharedSpawnPos(), gameProfile);
        this.clientLevel = dym;
    }
    
    @Override
    public boolean isSpectator() {
        final PlayerInfo dyq2 = Minecraft.getInstance().getConnection().getPlayerInfo(this.getGameProfile().getId());
        return dyq2 != null && dyq2.getGameMode() == GameType.SPECTATOR;
    }
    
    @Override
    public boolean isCreative() {
        final PlayerInfo dyq2 = Minecraft.getInstance().getConnection().getPlayerInfo(this.getGameProfile().getId());
        return dyq2 != null && dyq2.getGameMode() == GameType.CREATIVE;
    }
    
    public boolean isCapeLoaded() {
        return this.getPlayerInfo() != null;
    }
    
    @Nullable
    protected PlayerInfo getPlayerInfo() {
        if (this.playerInfo == null) {
            this.playerInfo = Minecraft.getInstance().getConnection().getPlayerInfo(this.getUUID());
        }
        return this.playerInfo;
    }
    
    public boolean isSkinLoaded() {
        final PlayerInfo dyq2 = this.getPlayerInfo();
        return dyq2 != null && dyq2.isSkinLoaded();
    }
    
    public ResourceLocation getSkinTextureLocation() {
        final PlayerInfo dyq2 = this.getPlayerInfo();
        return (dyq2 == null) ? DefaultPlayerSkin.getDefaultSkin(this.getUUID()) : dyq2.getSkinLocation();
    }
    
    @Nullable
    public ResourceLocation getCloakTextureLocation() {
        final PlayerInfo dyq2 = this.getPlayerInfo();
        return (dyq2 == null) ? null : dyq2.getCapeLocation();
    }
    
    public boolean isElytraLoaded() {
        return this.getPlayerInfo() != null;
    }
    
    @Nullable
    public ResourceLocation getElytraTextureLocation() {
        final PlayerInfo dyq2 = this.getPlayerInfo();
        return (dyq2 == null) ? null : dyq2.getElytraLocation();
    }
    
    public static HttpTexture registerSkinTexture(final ResourceLocation uh, final String string) {
        final TextureManager elw3 = Minecraft.getInstance().getTextureManager();
        AbstractTexture elj4 = elw3.getTexture(uh);
        if (elj4 == null) {
            elj4 = new HttpTexture(null, String.format("http://skins.minecraft.net/MinecraftSkins/%s.png", StringUtil.stripColor(string)), DefaultPlayerSkin.getDefaultSkin(Player.createPlayerUUID(string)), true, null);
            elw3.register(uh, elj4);
        }
        return (HttpTexture)elj4;
    }
    
    public static ResourceLocation getSkinLocation(final String string) {
        return new ResourceLocation("skins/" + Hashing.sha1().hashUnencodedChars(StringUtil.stripColor(string)));
    }
    
    public String getModelName() {
        final PlayerInfo dyq2 = this.getPlayerInfo();
        return (dyq2 == null) ? DefaultPlayerSkin.getSkinModelName(this.getUUID()) : dyq2.getModelName();
    }
    
    public float getFieldOfViewModifier() {
        float float2 = 1.0f;
        if (this.abilities.flying) {
            float2 *= 1.1f;
        }
        float2 *= (float)((this.getAttributeValue(Attributes.MOVEMENT_SPEED) / this.abilities.getWalkingSpeed() + 1.0) / 2.0);
        if (this.abilities.getWalkingSpeed() == 0.0f || Float.isNaN(float2) || Float.isInfinite(float2)) {
            float2 = 1.0f;
        }
        if (this.isUsingItem() && this.getUseItem().getItem() == Items.BOW) {
            final int integer3 = this.getTicksUsingItem();
            float float3 = integer3 / 20.0f;
            if (float3 > 1.0f) {
                float3 = 1.0f;
            }
            else {
                float3 *= float3;
            }
            float2 *= 1.0f - float3 * 0.15f;
        }
        return float2;
    }
}
