Jump to content

[1.7.10] - Player Skin As BufferedImage


Agravaine

Recommended Posts

@SideOnly(Side.CLIENT)
public static BufferedImage getPlayerSkinAsBufferedImage(AbstractClientPlayer player){
	Minecraft mc = Minecraft.getMinecraft();
	String playerName = player.getCommandSenderName();
	Map<Type, MinecraftProfileTexture> map = mc.func_152342_ad().func_152788_a(player.getGameProfile());

	BufferedImage image = null;
	InputStream stream = null;
	ITextureObject skin;

	try{
		if(map.containsKey(MinecraftProfileTexture.Type.SKIN)){
			ResourceLocation loc = mc.func_152342_ad().func_152792_a(map.get(Type.SKIN), Type.SKIN);
			skin = mc.getTextureManager().getTexture(loc);
		}else{
			skin = mc.getTextureManager().getTexture(player.getLocationSkin());
		}

		if(skin instanceof ThreadDownloadImageData){
			ThreadDownloadImageData imageData = (ThreadDownloadImageData)skin;
			image = ObfuscationReflectionHelper.getPrivateValue(ThreadDownloadImageData.class, imageData, "field_110560_d", "bufferedImage");
			System.out.println("1");
		}else if(skin instanceof DynamicTexture){
			DynamicTexture imageData = (DynamicTexture)skin;
			int width = ObfuscationReflectionHelper.getPrivateValue(DynamicTexture.class, imageData, "field_94233_j", "width");
			int height = ObfuscationReflectionHelper.getPrivateValue(DynamicTexture.class, imageData, "field_94234_k", "height");
			image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
			image.setRGB(0, 0, width, height, imageData.getTextureData(), 0, width);
			System.out.println("2");
		}else{
			stream = mc.getResourceManager().getResource(AbstractClientPlayer.locationStevePng).getInputStream();
			image = ImageIO.read(stream);
			System.out.println("3");
		}
	}catch(IOException e){
		e.printStackTrace();
	}finally{
		IOUtils.closeQuietly(stream);
	}

	return image;
}

I took the skin and made me change. As it is now loaded back?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.