Mekanism-tilera-Edition/common/mekanism/client/CapeBufferDownload.java

75 lines
1.7 KiB
Java
Raw Normal View History

package mekanism.client;
2013-10-14 21:54:10 +02:00
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.URL;
2013-10-14 21:54:10 +02:00
import mekanism.common.ObfuscatedNames;
import mekanism.common.util.MekanismUtils;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.IImageBuffer;
2013-10-14 21:54:10 +02:00
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
2013-10-14 21:54:10 +02:00
public class CapeBufferDownload extends Thread
{
2013-10-14 21:54:10 +02:00
public String username;
public String staticCapeUrl;
2013-10-14 21:54:10 +02:00
public ResourceLocation resourceLocation;
2013-10-14 21:54:10 +02:00
public ThreadDownloadImageData capeImage;
boolean downloaded = false;
public CapeBufferDownload(String name, String url)
2013-10-14 21:54:10 +02:00
{
username = name;
staticCapeUrl = url;
2013-10-14 21:54:10 +02:00
setDaemon(true);
setName("Cape Downlaod Thread");
}
@Override
public void run()
2013-10-14 21:54:10 +02:00
{
try {
download();
} catch(Exception e) {}
}
private void download()
2013-10-14 21:54:10 +02:00
{
try {
resourceLocation = new ResourceLocation("mekanism/" + StringUtils.stripControlCodes(username));
2013-10-14 21:54:10 +02:00
Method method = MekanismUtils.getPrivateMethod(AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_getDownloadImage, ResourceLocation.class, String.class, ResourceLocation.class, IImageBuffer.class);
Object obj = method.invoke(null, resourceLocation, staticCapeUrl, null, null);
2013-10-14 21:54:10 +02:00
if(obj instanceof ThreadDownloadImageData)
{
capeImage = (ThreadDownloadImageData)obj;
}
} catch(Exception e) {}
downloaded = true;
}
public ThreadDownloadImageData getImage()
{
return capeImage;
}
public ResourceLocation getResourceLocation()
{
return resourceLocation;
}
}