From 4fdbb24b3a3e58a956e65acf8b099fd20f301797 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 27 Jun 2014 22:50:23 +1000 Subject: [PATCH] Take 2 at backwards compatibility. Cross your fingers. --- build.properties | 4 +- .../api/BOPObfuscationHelper.java | 4 -- .../common/eventhandler/BOPEventHandlers.java | 4 +- .../eventhandler/misc/CapeEventHandler.java | 67 ++++++++++--------- .../misc/CapeEventHandlerOld.java | 26 ++----- 5 files changed, 47 insertions(+), 58 deletions(-) diff --git a/build.properties b/build.properties index d44c56883..8fe01ec1a 100644 --- a/build.properties +++ b/build.properties @@ -1,3 +1,3 @@ -minecraft_version=1.7.10 -forge_version=10.13.0.1152 +minecraft_version=1.7.2 +forge_version=10.12.2.1147 mod_version=2.0.2 diff --git a/src/main/java/biomesoplenty/api/BOPObfuscationHelper.java b/src/main/java/biomesoplenty/api/BOPObfuscationHelper.java index 5be82d133..5682b97e8 100644 --- a/src/main/java/biomesoplenty/api/BOPObfuscationHelper.java +++ b/src/main/java/biomesoplenty/api/BOPObfuscationHelper.java @@ -32,8 +32,4 @@ public class BOPObfuscationHelper public static final String[] river = new String[] { "river", "field_76781_i" }; public static final String[] roofedForest = new String[] { "roofedForest", "field_150585_R" }; public static final String[] hell = new String[] { "hell", "field_76778_j" }; - - //AbstractClientPlayer - @Deprecated - public static final String[] getTextureCape = new String[] { "getTextureCape", "func_110310_o" }; } diff --git a/src/main/java/biomesoplenty/common/eventhandler/BOPEventHandlers.java b/src/main/java/biomesoplenty/common/eventhandler/BOPEventHandlers.java index c8b0bdf32..66f6b21a1 100755 --- a/src/main/java/biomesoplenty/common/eventhandler/BOPEventHandlers.java +++ b/src/main/java/biomesoplenty/common/eventhandler/BOPEventHandlers.java @@ -9,6 +9,7 @@ import biomesoplenty.common.eventhandler.gui.StartupWarningEventHandler; import biomesoplenty.common.eventhandler.misc.BonemealEventHandler; import biomesoplenty.common.eventhandler.misc.BucketEventHandler; import biomesoplenty.common.eventhandler.misc.CapeEventHandler; +import biomesoplenty.common.eventhandler.misc.CapeEventHandlerOld; import biomesoplenty.common.eventhandler.network.ConnectionEventHandler; import biomesoplenty.common.eventhandler.potions.PotionParalysisEventHandler; import biomesoplenty.common.eventhandler.potions.PotionPossessionEventHandler; @@ -66,6 +67,7 @@ public class BOPEventHandlers { MinecraftForge.EVENT_BUS.register(new BonemealEventHandler()); MinecraftForge.EVENT_BUS.register(new BucketEventHandler()); - MinecraftForge.EVENT_BUS.register(new CapeEventHandler()); + if (MinecraftForge.MC_VERSION == "1.7.10") MinecraftForge.EVENT_BUS.register(new CapeEventHandler()); + else MinecraftForge.EVENT_BUS.register(new CapeEventHandlerOld()); } } diff --git a/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandler.java b/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandler.java index 3ae0b59d4..20eec13df 100644 --- a/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandler.java +++ b/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandler.java @@ -9,27 +9,24 @@ import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.HashMap; +import java.util.UUID; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; -import net.minecraft.client.resources.SkinManager; import net.minecraftforge.client.event.RenderPlayerEvent; import org.apache.logging.log4j.Level; import biomesoplenty.common.utils.BOPLogger; - -import com.mojang.authlib.minecraft.MinecraftProfileTexture; -import com.mojang.util.UUIDTypeAdapter; - import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.ReflectionHelper; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class CapeEventHandler { - private final String serverLocation = "https://raw.github.com/Glitchfiend/BiomesOPlenty/master/capes.txt"; + private final String serverLocation = "https://raw.githubusercontent.com/Glitchfiend/BiomesOPlenty/master/capes.txt"; private final int timeout = 1000; private HashMap cloaks = new HashMap(); @@ -59,18 +56,31 @@ public class CapeEventHandler { checkedPlayers.add(abstractClientPlayer); - // getSkinManager()? - SkinManager skinManager = Minecraft.getMinecraft().func_152342_ad(); - - String uuid = UUIDTypeAdapter.fromUUID(abstractClientPlayer.getUniqueID()); - - if (cloaks.containsKey(uuid)) + try { - MinecraftProfileTexture profileTexture = new MinecraftProfileTexture(cloaks.get(uuid)); + Class SkinManager = Class.forName("net.minecraft.client.resources.SkinManager"); + Class SkinAvailableCallback = Class.forName("net.minecraft.client.resources.SkinManager$SkinAvailableCallback"); + Class UUIDTypeAdapter = Class.forName("com.mojang.util.UUIDTypeAdapter"); - skinManager.func_152789_a(profileTexture, MinecraftProfileTexture.Type.CAPE, abstractClientPlayer); - - event.renderCape = true; + // getSkinManager()? + Object skinManager = ReflectionHelper.findMethod(Minecraft.class, Minecraft.getMinecraft(), new String[] { "func_152342_ad" }).invoke(Minecraft.getMinecraft()); + String uuid = (String)ReflectionHelper.findMethod(UUIDTypeAdapter, null, new String[] { "fromUUID" }, UUID.class).invoke(null, abstractClientPlayer.getUniqueID()); + + if (cloaks.containsKey(uuid)) + { + Class MinecraftProfileTexture = Class.forName("com.mojang.authlib.minecraft.MinecraftProfileTexture"); + Class Type = Class.forName("com.mojang.authlib.minecraft.MinecraftProfileTexture$Type"); + + Object profileTexture = MinecraftProfileTexture.getConstructor(String.class).newInstance(cloaks.get(uuid)); + + ReflectionHelper.findMethod(SkinManager, skinManager, new String[] { "func_152789_a" }, MinecraftProfileTexture, Type, SkinAvailableCallback).invoke(skinManager, profileTexture, Type.getField("CAPE").get(null), abstractClientPlayer); + + event.renderCape = true; + } + } + catch (Exception e) + { + e.printStackTrace(); } } } @@ -92,22 +102,19 @@ public class CapeEventHandler int linetracker = 1; while ((str = br.readLine()) != null) { - if (!str.startsWith("--") && !str.isEmpty()) + if ((!str.startsWith("--") || str.contains("--*--")) && !str.isEmpty()) { - if (str.startsWith("*%")) + str = str.replace("--*--", ""); + + if (str.contains(":")) { - str = str.replace("*%", ""); - - if (str.contains(":")) - { - String uuid = str.substring(0, str.indexOf(":")); - String link = str.substring(str.indexOf(":") + 1); - cloaks.put(uuid, link); - } - else - { - BOPLogger.log(Level.WARN, "[capes.txt] Syntax error on line " + linetracker + ": " + str); - } + String uuid = str.substring(0, str.indexOf(":")); + String link = str.substring(str.indexOf(":") + 1); + cloaks.put(uuid, link); + } + else + { + BOPLogger.log(Level.WARN, "[capes.txt] Syntax error on line " + linetracker + ": " + str); } } linetracker++; diff --git a/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandlerOld.java b/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandlerOld.java index 7123da92e..08b71eb9a 100644 --- a/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandlerOld.java +++ b/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandlerOld.java @@ -29,7 +29,7 @@ import cpw.mods.fml.relauncher.SideOnly; /**This class is not to be altered in any way, shape or form unless it contains a severe bug. The only reason it remains is for 1.7.2 compatibility.**/ public class CapeEventHandlerOld { - private final String serverLocation = "https://raw.github.com/Glitchfiend/BiomesOPlenty/master/capes.txt"; + private final String serverLocation = "https://raw.githubusercontent.com/Glitchfiend/BiomesOPlenty/master/capes.txt"; private final int timeout = 1000; private static final Graphics TEST_GRAPHICS = new BufferedImage(128, 128, @@ -68,15 +68,7 @@ public class CapeEventHandlerOld capePlayers.add(abstractClientPlayer); - try - { - ThreadDownloadImageData threadDownloadImageData = (ThreadDownloadImageData)ReflectionHelper.findMethod(AbstractClientPlayer.class, abstractClientPlayer, BOPObfuscationHelper.getTextureCape).invoke(abstractClientPlayer); - ReflectionHelper.setPrivateValue(ThreadDownloadImageData.class, threadDownloadImageData, false, new String[]{"textureUploaded", "field_110559_g"}); - } - catch (Exception e) - { - e.printStackTrace(); - } + ReflectionHelper.setPrivateValue(ThreadDownloadImageData.class, abstractClientPlayer.getTextureCape(), false, new String[]{"textureUploaded", "field_110559_g"}); new Thread(new CloakThread(abstractClientPlayer, cloakURL)).start(); event.renderCape = true; @@ -107,7 +99,7 @@ public class CapeEventHandlerOld String nick = str.substring(0, str.indexOf(":")); String link = str.substring(str.indexOf(":") + 1); new Thread(new CloakPreload(link)).start(); - cloaks.put(nick, link); + cloaks.put(nick, link); } else { @@ -150,19 +142,11 @@ public class CapeEventHandlerOld cape.getHeight(null), BufferedImage.TYPE_INT_ARGB); bo.getGraphics().drawImage(cape, 0, 0, null); - try - { - ThreadDownloadImageData threadDownloadImageData = (ThreadDownloadImageData)ReflectionHelper.findMethod(AbstractClientPlayer.class, abstractClientPlayer, BOPObfuscationHelper.getTextureCape).invoke(abstractClientPlayer); - ReflectionHelper.setPrivateValue(ThreadDownloadImageData.class, threadDownloadImageData, bo, new String[]{"bufferedImage", "field_110560_d"}); - } - catch (Exception e) - { - e.printStackTrace(); - } + ReflectionHelper.setPrivateValue(ThreadDownloadImageData.class, abstractClientPlayer.getTextureCape(), bo, new String[]{"bufferedImage", "field_110560_d"}); } catch (MalformedURLException e) { - e.printStackTrace(); + e.printStackTrace(); } } }