package net.minecraft.client.entity;

import com.mojang.authlib.GameProfile;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IImageBuffer;
import net.minecraft.client.renderer.ImageBufferDownload;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraft.world.World;

@SideOnly(Side.CLIENT)
public abstract class AbstractClientPlayer extends EntityPlayer
{
	public static final ResourceLocation locationStevePng = new ResourceLocation("textures/entity/steve.png");
	private ThreadDownloadImageData downloadImageSkin;
	private ThreadDownloadImageData downloadImageCape;
	private ResourceLocation locationSkin;
	private ResourceLocation locationCape;
	private static final String __OBFID = "CL_00000935";

	public AbstractClientPlayer(World p_i45074_1_, GameProfile p_i45074_2_)
	{
		super(p_i45074_1_, p_i45074_2_);
		this.setupCustomSkin();
	}

	protected void setupCustomSkin()
	{
		String s = this.getCommandSenderName();

		if (!s.isEmpty())
		{
			this.locationSkin = getLocationSkin(s);
			this.locationCape = getLocationCape(s);
			this.downloadImageSkin = getDownloadImageSkin(this.locationSkin, s);
			this.downloadImageCape = getDownloadImageCape(this.locationCape, s);
		}
	}

	public ThreadDownloadImageData getTextureSkin()
	{
		return this.downloadImageSkin;
	}

	public ThreadDownloadImageData getTextureCape()
	{
		return this.downloadImageCape;
	}

	public ResourceLocation getLocationSkin()
	{
		return this.locationSkin;
	}

	public ResourceLocation getLocationCape()
	{
		return this.locationCape;
	}

	public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation par0ResourceLocation, String par1Str)
	{
		return getDownloadImage(par0ResourceLocation, getSkinUrl(par1Str), locationStevePng, new ImageBufferDownload());
	}

	public static ThreadDownloadImageData getDownloadImageCape(ResourceLocation par0ResourceLocation, String par1Str)
	{
		return getDownloadImage(par0ResourceLocation, getCapeUrl(par1Str), (ResourceLocation)null, (IImageBuffer)null);
	}

	private static ThreadDownloadImageData getDownloadImage(ResourceLocation par0ResourceLocation, String par1Str, ResourceLocation par2ResourceLocation, IImageBuffer par3IImageBuffer)
	{
		TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
		Object object = texturemanager.getTexture(par0ResourceLocation);

		if (object == null)
		{
			object = new ThreadDownloadImageData(par1Str, par2ResourceLocation, par3IImageBuffer);
			texturemanager.loadTexture(par0ResourceLocation, (ITextureObject)object);
		}

		return (ThreadDownloadImageData)object;
	}

	public static String getSkinUrl(String par0Str)
	{
		return String.format("http://skins.minecraft.net/MinecraftSkins/%s.png", new Object[] {StringUtils.stripControlCodes(par0Str)});
	}

	public static String getCapeUrl(String par0Str)
	{
		return String.format("http://skins.minecraft.net/MinecraftCloaks/%s.png", new Object[] {StringUtils.stripControlCodes(par0Str)});
	}

	public static ResourceLocation getLocationSkin(String par0Str)
	{
		return new ResourceLocation("skins/" + StringUtils.stripControlCodes(par0Str));
	}

	public static ResourceLocation getLocationCape(String par0Str)
	{
		return new ResourceLocation("cloaks/" + StringUtils.stripControlCodes(par0Str));
	}

	public static ResourceLocation getLocationSkull(String par0Str)
	{
		return new ResourceLocation("skull/" + StringUtils.stripControlCodes(par0Str));
	}
}