From 086dd83a5734ad532d3ea97f86f80b5c020d7b0d Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Wed, 11 Feb 2015 08:36:40 -0500 Subject: [PATCH] Fixed capes --- .../mekanism/client/CapeBufferDownload.java | 44 ++++++++++++++----- .../mekanism/client/ClientTickHandler.java | 21 +++++---- .../java/mekanism/common/ObfuscatedNames.java | 3 -- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/main/java/mekanism/client/CapeBufferDownload.java b/src/main/java/mekanism/client/CapeBufferDownload.java index adc61ac80..079d8b94d 100644 --- a/src/main/java/mekanism/client/CapeBufferDownload.java +++ b/src/main/java/mekanism/client/CapeBufferDownload.java @@ -1,13 +1,16 @@ package mekanism.client; +import java.io.File; import java.lang.reflect.Method; import mekanism.common.ObfuscatedNames; import mekanism.common.util.MekanismUtils; - +import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.IImageBuffer; 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 net.minecraft.util.StringUtils; import cpw.mods.fml.relauncher.Side; @@ -40,7 +43,9 @@ public class CapeBufferDownload extends Thread { try { download(); - } catch(Exception e) {} + } catch(Exception e) { + e.printStackTrace(); + } } private void download() @@ -48,14 +53,10 @@ public class CapeBufferDownload extends Thread 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) {} + capeImage = downloadCape(); + } catch(Exception e) { + e.printStackTrace(); + } downloaded = true; } @@ -69,4 +70,27 @@ public class CapeBufferDownload extends Thread { return resourceLocation; } + + public ThreadDownloadImageData downloadCape() + { + try { + File capeFile = new File(resourceLocation.getResourcePath() + ".png"); + + if(capeFile.exists()) + { + capeFile.delete(); + } + + TextureManager manager = Minecraft.getMinecraft().getTextureManager(); + ThreadDownloadImageData data = new ThreadDownloadImageData(capeFile, staticCapeUrl, null, null); + + manager.loadTexture(resourceLocation, data); + + return data; + } catch(Exception e) { + e.printStackTrace(); + } + + return null; + } } diff --git a/src/main/java/mekanism/client/ClientTickHandler.java b/src/main/java/mekanism/client/ClientTickHandler.java index 2ded76657..83cbd0e4e 100644 --- a/src/main/java/mekanism/client/ClientTickHandler.java +++ b/src/main/java/mekanism/client/ClientTickHandler.java @@ -1,5 +1,9 @@ package mekanism.client; +import static mekanism.client.sound.SoundHandler.Channel.FLAMETHROWER; +import static mekanism.client.sound.SoundHandler.Channel.GASMASK; +import static mekanism.client.sound.SoundHandler.Channel.JETPACK; + import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -26,12 +30,14 @@ import mekanism.common.network.PacketJetpackData.JetpackPacket; import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage; import mekanism.common.network.PacketScubaTankData.ScubaTankPacket; import mekanism.common.util.MekanismUtils; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.StringUtils; + +import com.mojang.authlib.minecraft.MinecraftProfileTexture; + import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; @@ -39,10 +45,6 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import static mekanism.client.sound.SoundHandler.Channel.FLAMETHROWER; -import static mekanism.client.sound.SoundHandler.Channel.GASMASK; -import static mekanism.client.sound.SoundHandler.Channel.JETPACK; - /** * Client-side tick handler for Mekanism. Used mainly for the update check upon startup. * @author AidanBrady @@ -150,8 +152,7 @@ public class ClientTickHandler continue; } - MekanismUtils.setPrivateValue(player, download.getImage(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_downloadImageCape); - MekanismUtils.setPrivateValue(player, download.getResourceLocation(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_locationCape); + player.func_152121_a(MinecraftProfileTexture.Type.CAPE, download.getResourceLocation()); } } else if(StringUtils.stripControlCodes(player.getCommandSenderName()).equals("aidancbrady")) @@ -171,8 +172,7 @@ public class ClientTickHandler continue; } - MekanismUtils.setPrivateValue(player, download.getImage(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_downloadImageCape); - MekanismUtils.setPrivateValue(player, download.getResourceLocation(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_locationCape); + player.func_152121_a(MinecraftProfileTexture.Type.CAPE, download.getResourceLocation()); } } else if(Mekanism.donators.contains(StringUtils.stripControlCodes(player.getCommandSenderName()))) @@ -192,8 +192,7 @@ public class ClientTickHandler continue; } - MekanismUtils.setPrivateValue(player, download.getImage(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_downloadImageCape); - MekanismUtils.setPrivateValue(player, download.getResourceLocation(), AbstractClientPlayer.class, ObfuscatedNames.AbstractClientPlayer_locationCape); + player.func_152121_a(MinecraftProfileTexture.Type.CAPE, download.getResourceLocation()); } } } diff --git a/src/main/java/mekanism/common/ObfuscatedNames.java b/src/main/java/mekanism/common/ObfuscatedNames.java index 649e0611e..9adbff7b0 100644 --- a/src/main/java/mekanism/common/ObfuscatedNames.java +++ b/src/main/java/mekanism/common/ObfuscatedNames.java @@ -4,9 +4,6 @@ public final class ObfuscatedNames { public static String[] TextureManager_listTickables = new String[] {"listTickables", "field_110583_b", "c"}; 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"}; public static String[] GuiContainer_xSize = new String[] {"xSize", "field_146999_f", "c"}; public static String[] GuiContainer_ySize = new String[] {"ySize", "field_147000_g", "d"}; public static String[] GuiContainer_guiLeft = new String[] {"guiLeft", "field_147003_i"};