Advertisement
MyCrazyPi

Untitled

Oct 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.06 KB | None | 0 0
  1. package optifine;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.image.BufferedImage;
  5. import java.awt.image.ImageObserver;
  6. import java.io.File;
  7. import net.minecraft.client.Minecraft;
  8. import net.minecraft.client.entity.AbstractClientPlayer;
  9. import net.minecraft.client.renderer.IImageBuffer;
  10. import net.minecraft.client.renderer.ImageBufferDownload;
  11. import net.minecraft.client.renderer.ThreadDownloadImageData;
  12. import net.minecraft.client.renderer.texture.ITextureObject;
  13. import net.minecraft.client.renderer.texture.TextureManager;
  14. import net.minecraft.util.ResourceLocation;
  15. import org.apache.commons.io.FilenameUtils;
  16.  
  17. public class CapeUtils
  18. {
  19.     public static void downloadCape(final AbstractClientPlayer player)
  20.     {
  21.         String s = player.getNameClear();n
  22.  
  23.         if (s != null && !s.isEmpty())
  24.         {
  25.             String s1 = "http://s.optifine.net/capes/" + s + ".png";
  26.             String s2 = FilenameUtils.getBaseName(s1);
  27.             final ResourceLocation resourcelocation = new ResourceLocation("capeof/" + s2);
  28.             TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
  29.             ITextureObject itextureobject = texturemanager.getTexture(resourcelocation);
  30.  
  31.             if (itextureobject != null && itextureobject instanceof ThreadDownloadImageData)
  32.             {
  33.                 ThreadDownloadImageData threaddownloadimagedata = (ThreadDownloadImageData)itextureobject;
  34.  
  35.                 if (threaddownloadimagedata.imageFound != null)
  36.                 {
  37.                     if (threaddownloadimagedata.imageFound.booleanValue())
  38.                    
  39.                         player.setLocationOfCape(resourcelocation);
  40.                     }
  41.  
  42.                     return;
  43.                 }
  44.             }
  45.  
  46.             IImageBuffer iimagebuffer = new IImageBuffer()
  47.             {
  48.                 ImageBufferDownload ibd = new ImageBufferDownload();
  49.                 public BufferedImage parseUserSkin(BufferedImage image)
  50.                 {
  51.                     return CapeUtils.parseCape(image);
  52.                 }
  53.                 public void skinAvailable()
  54.                 {
  55.                     player.setLocationOfCape(resourcelocation);
  56.                 }
  57.             };
  58.             ThreadDownloadImageData threaddownloadimagedata1 = new ThreadDownloadImageData((File)null, s1, (ResourceLocation)null, iimagebuffer);
  59.             threaddownloadimagedata1.pipeline = true;
  60.             texturemanager.loadTexture(resourcelocation, threaddownloadimagedata1);
  61.         }
  62.     }
  63.  
  64.     public static BufferedImage parseCape(BufferedImage p_parseCape_0_)
  65.     {
  66.         int i = 64;
  67.         int j = 32;
  68.         int k = p_parseCape_0_.getWidth();
  69.  
  70.         for (int l = p_parseCape_0_.getHeight(); i < k || j < l; j *= 2)
  71.         {
  72.             i *= 2;
  73.         }
  74.  
  75.         BufferedImage bufferedimage = new BufferedImage(i, j, 2);
  76.         Graphics graphics = bufferedimage.getGraphics();
  77.         graphics.drawImage(p_parseCape_0_, 0, 0, (ImageObserver)null);
  78.         graphics.dispose();
  79.         return bufferedimage;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement