Fixed capes :)
This commit is contained in:
parent
15dc84bd5f
commit
15cba39b30
4 changed files with 140 additions and 130 deletions
|
@ -1,78 +1,74 @@
|
|||
package mekanism.client;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
|
||||
import mekanism.common.ObfuscatedNames;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.IImageBuffer;
|
||||
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)
|
||||
public class CapeBufferDownload implements IImageBuffer
|
||||
public class CapeBufferDownload extends Thread
|
||||
{
|
||||
private int[] imageData;
|
||||
private int imageWidth;
|
||||
private int imageHeight;
|
||||
|
||||
@Override
|
||||
public BufferedImage parseUserSkin(BufferedImage bufferedImage)
|
||||
{
|
||||
if(bufferedImage == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
imageWidth = bufferedImage.getWidth(null);
|
||||
imageHeight = bufferedImage.getHeight(null);
|
||||
|
||||
BufferedImage imageBuffer = new BufferedImage(imageWidth, imageHeight, 2);
|
||||
|
||||
Graphics graphics = imageBuffer.getGraphics();
|
||||
graphics.drawImage(bufferedImage, 0, 0, null);
|
||||
graphics.dispose();
|
||||
|
||||
imageData = ((DataBufferInt)imageBuffer.getRaster().getDataBuffer()).getData();
|
||||
|
||||
boolean flag = false;
|
||||
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
for(i = 32; i < 64; i++)
|
||||
{
|
||||
for(j = 0; j < 16; j++)
|
||||
{
|
||||
k = imageData[i + j * 64];
|
||||
|
||||
if((k >> 24 & 0xFF) >= 128)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!flag)
|
||||
{
|
||||
for(i = 32; i < 64; i++)
|
||||
{
|
||||
for(j = 0; j < 16; j++)
|
||||
{
|
||||
k = imageData[i + j * 64];
|
||||
|
||||
if((k >> 24 & 0xFF) >= 128)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imageBuffer;
|
||||
}
|
||||
public String username;
|
||||
|
||||
public String staticCapeUrl;
|
||||
|
||||
public ResourceLocation resourceLocation;
|
||||
|
||||
public ThreadDownloadImageData capeImage;
|
||||
|
||||
boolean downloaded = false;
|
||||
|
||||
public CapeBufferDownload(String name, String url)
|
||||
{
|
||||
username = name;
|
||||
staticCapeUrl = url;
|
||||
|
||||
setDaemon(true);
|
||||
setName("Cape Downlaod Thread");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try {
|
||||
download();
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
private void download()
|
||||
{
|
||||
try {
|
||||
resourceLocation = new ResourceLocation("mekanism/" + StringUtils.stripControlCodes(username));
|
||||
|
||||
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);
|
||||
|
||||
if(obj instanceof ThreadDownloadImageData)
|
||||
{
|
||||
capeImage = (ThreadDownloadImageData)obj;
|
||||
}
|
||||
} catch(Exception e) {}
|
||||
|
||||
downloaded = true;
|
||||
}
|
||||
|
||||
public ThreadDownloadImageData getImage()
|
||||
{
|
||||
return capeImage;
|
||||
}
|
||||
|
||||
public ResourceLocation getResourceLocation()
|
||||
{
|
||||
return resourceLocation;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,49 +39,9 @@ public class ClientTickHandler implements ITickHandler
|
|||
public static final String DONATE_CAPE = "https://dl.dropboxusercontent.com/u/90411166/donate.png";
|
||||
public static final String AIDAN_CAPE = "https://dl.dropboxusercontent.com/u/90411166/aidan.png";
|
||||
|
||||
private Map<String, ThreadDownloadImageData> mikeDownload = new HashMap<String, ThreadDownloadImageData>();
|
||||
private Map<String, ThreadDownloadImageData> donateDownload = new HashMap<String, ThreadDownloadImageData>();
|
||||
private Map<String, ThreadDownloadImageData> aidanDownload = new HashMap<String, ThreadDownloadImageData>();
|
||||
|
||||
private void updateCape(EntityPlayer player, ThreadDownloadImageData newCape)
|
||||
{
|
||||
if(player.getHideCape())
|
||||
{
|
||||
try {
|
||||
Method m = EntityPlayer.class.getDeclaredMethod("setHideCape", Integer.class, Boolean.class);
|
||||
m.invoke(player, 1, false);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
if(MekanismUtils.getPrivateValue(player, AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_downloadImageCape) != newCape)
|
||||
{
|
||||
MekanismUtils.setPrivateValue(player, newCape, AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_downloadImageCape);
|
||||
}
|
||||
}
|
||||
|
||||
private ResourceLocation getCapeResource(EntityPlayer player)
|
||||
{
|
||||
if(player instanceof AbstractClientPlayer)
|
||||
{
|
||||
return (ResourceLocation)MekanismUtils.getPrivateValue(player, AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_locationCape);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ThreadDownloadImageData getCape(EntityPlayer player, String cape)
|
||||
{
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
Object object = texturemanager.getTexture(getCapeResource(player));
|
||||
|
||||
if(object == null)
|
||||
{
|
||||
object = new ThreadDownloadImageData(cape, getCapeResource(player), new CapeBufferDownload());
|
||||
texturemanager.loadTexture(getCapeResource(player), (TextureObject)object);
|
||||
}
|
||||
|
||||
return (ThreadDownloadImageData)object;
|
||||
}
|
||||
private Map<String, CapeBufferDownload> mikeDownload = new HashMap<String, CapeBufferDownload>();
|
||||
private Map<String, CapeBufferDownload> donateDownload = new HashMap<String, CapeBufferDownload>();
|
||||
private Map<String, CapeBufferDownload> aidanDownload = new HashMap<String, CapeBufferDownload>();
|
||||
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||
|
@ -104,30 +64,66 @@ public class ClientTickHandler implements ITickHandler
|
|||
{
|
||||
if(StringUtils.stripControlCodes(player.username).equals("mikeacttck"))
|
||||
{
|
||||
if(mikeDownload.get(player.username) == null)
|
||||
{
|
||||
mikeDownload.put(player.username, getCape(player, MIKE_CAPE));
|
||||
}
|
||||
CapeBufferDownload download = mikeDownload.get(player.username);
|
||||
|
||||
updateCape(player, mikeDownload.get(player.username));
|
||||
if(download == null)
|
||||
{
|
||||
download = new CapeBufferDownload(player.username, MIKE_CAPE);
|
||||
mikeDownload.put(player.username, download);
|
||||
|
||||
download.start();
|
||||
}
|
||||
else {
|
||||
if(!download.downloaded)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
MekanismUtils.setPrivateValue(player, download.getImage(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_downloadImageCape);
|
||||
MekanismUtils.setPrivateValue(player, download.getResourceLocation(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_locationCape);
|
||||
}
|
||||
}
|
||||
else if(StringUtils.stripControlCodes(player.username).equals("aidancbrady"))
|
||||
{
|
||||
if(aidanDownload.get(player.username) == null)
|
||||
{
|
||||
aidanDownload.put(player.username, getCape(player, AIDAN_CAPE));
|
||||
}
|
||||
CapeBufferDownload download = aidanDownload.get(player.username);
|
||||
|
||||
updateCape(player, aidanDownload.get(player.username));
|
||||
if(download == null)
|
||||
{
|
||||
download = new CapeBufferDownload(player.username, AIDAN_CAPE);
|
||||
aidanDownload.put(player.username, download);
|
||||
|
||||
download.start();
|
||||
}
|
||||
else {
|
||||
if(!download.downloaded)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
MekanismUtils.setPrivateValue(player, download.getImage(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_downloadImageCape);
|
||||
MekanismUtils.setPrivateValue(player, download.getResourceLocation(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_locationCape);
|
||||
}
|
||||
}
|
||||
else if(Mekanism.donators.contains(StringUtils.stripControlCodes(player.username)) || player.username.contains("Player"))
|
||||
{
|
||||
if(donateDownload.get(player.username) == null)
|
||||
{
|
||||
donateDownload.put(player.username, getCape(player, DONATE_CAPE));
|
||||
}
|
||||
CapeBufferDownload download = donateDownload.get(player.username);
|
||||
|
||||
updateCape(player, donateDownload.get(player.username));
|
||||
if(download == null)
|
||||
{
|
||||
download = new CapeBufferDownload(player.username, DONATE_CAPE);
|
||||
donateDownload.put(player.username, download);
|
||||
|
||||
download.start();
|
||||
}
|
||||
else {
|
||||
if(!download.downloaded)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
MekanismUtils.setPrivateValue(player, download.getImage(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_downloadImageCape);
|
||||
MekanismUtils.setPrivateValue(player, download.getResourceLocation(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_locationCape);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,5 @@ public final class ObfuscatedNames
|
|||
public static String[] Minecraft_timer = new String[] {"timer", "field_71428_T", "S"};
|
||||
public static String[] AbstractClientPlayer_downloadImageCape = new String[] {"downloadImageCape", "field_110315_c", "c"};
|
||||
public static String[] AbstractClientPlayer_locationCape = new String[] {"locationCape", "field_110313_e", "e"};
|
||||
public static String[] AbstractClientPlayer_getDownloadImage = new String[] {"getDownloadImage", "func_110301_a", "a"};
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
@ -17,17 +18,17 @@ import mekanism.api.Object3D;
|
|||
import mekanism.common.DynamicTankCache;
|
||||
import mekanism.common.IActiveState;
|
||||
import mekanism.common.IFactory;
|
||||
import mekanism.common.IFactory.RecipeType;
|
||||
import mekanism.common.IModule;
|
||||
import mekanism.common.IRedstoneControl;
|
||||
import mekanism.common.IRedstoneControl.RedstoneControl;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.Teleporter;
|
||||
import mekanism.common.Version;
|
||||
import mekanism.common.IFactory.RecipeType;
|
||||
import mekanism.common.IRedstoneControl.RedstoneControl;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.Teleporter;
|
||||
import mekanism.common.Tier.EnergyCubeTier;
|
||||
import mekanism.common.Tier.FactoryTier;
|
||||
import mekanism.common.Version;
|
||||
import mekanism.common.inventory.container.ContainerElectricChest;
|
||||
import mekanism.common.item.ItemBlockEnergyCube;
|
||||
import mekanism.common.network.PacketElectricChest;
|
||||
|
@ -903,6 +904,22 @@ public final class MekanismUtils
|
|||
}
|
||||
}
|
||||
|
||||
public static Method getPrivateMethod(Class c, String[] methods, Class... params)
|
||||
{
|
||||
for(String method : methods)
|
||||
{
|
||||
try {
|
||||
Method m = c.getDeclaredMethod(method, params);
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
} catch(Exception e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a ResourceLocation with a defined resource type and name.
|
||||
* @param type - type of resource to retrieve
|
||||
|
|
Loading…
Reference in a new issue