-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcape code (capeutils class).txt
86 lines (74 loc) · 3.07 KB
/
cape code (capeutils class).txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package optifine;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
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.util.ResourceLocation;
import org.apache.commons.io.FilenameUtils;
public class CapeUtils
{
public static void downloadCape(final AbstractClientPlayer player)
{
String username = player.getNameClear();
if (username != null && !username.isEmpty())
{
String ofCapeUrl = "http://s.optifine.net/capes/" + username + ".png";
if (username.equalsIgnoreCase(Minecraft.getMinecraft().session.getUsername()) && !username.equalsIgnoreCase("TheBrownBrothers")) {
ofCapeUrl = "https://i.imgur.com/EWm5KAt.png";
}
String mptHash = FilenameUtils.getBaseName(ofCapeUrl);
final ResourceLocation rl = new ResourceLocation("capeof/" + mptHash);
TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
ITextureObject tex = textureManager.getTexture(rl);
if (tex != null && tex instanceof ThreadDownloadImageData)
{
ThreadDownloadImageData thePlayer = (ThreadDownloadImageData)tex;
if (thePlayer.imageFound != null)
{
if (thePlayer.imageFound.booleanValue())
{
player.setLocationOfCape(rl);
}
return;
}
}
IImageBuffer iib = new IImageBuffer()
{
ImageBufferDownload ibd = new ImageBufferDownload();
public BufferedImage parseUserSkin(BufferedImage var1)
{
return CapeUtils.parseCape(var1);
}
public void func_152634_a()
{
player.setLocationOfCape(rl);
}
};
ThreadDownloadImageData textureCape = new ThreadDownloadImageData((File)null, ofCapeUrl, (ResourceLocation)null, iib);
textureCape.pipeline = true;
textureManager.loadTexture(rl, textureCape);
}
}
public static BufferedImage parseCape(BufferedImage img)
{
int imageWidth = 64;
int imageHeight = 32;
int srcWidth = img.getWidth();
for (int srcHeight = img.getHeight(); imageWidth < srcWidth || imageHeight < srcHeight; imageHeight *= 2)
{
imageWidth *= 2;
}
BufferedImage imgNew = new BufferedImage(imageWidth, imageHeight, 2);
Graphics g = imgNew.getGraphics();
g.drawImage(img, 0, 0, (ImageObserver)null);
g.dispose();
return imgNew;
}
}