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 5682b97e8..5be82d133 100644 --- a/src/main/java/biomesoplenty/api/BOPObfuscationHelper.java +++ b/src/main/java/biomesoplenty/api/BOPObfuscationHelper.java @@ -32,4 +32,8 @@ 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/misc/CapeEventHandlerOld.java b/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandlerOld.java new file mode 100644 index 000000000..7123da92e --- /dev/null +++ b/src/main/java/biomesoplenty/common/eventhandler/misc/CapeEventHandlerOld.java @@ -0,0 +1,201 @@ +package biomesoplenty.common.eventhandler.misc; + +import java.awt.Graphics; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.HashMap; + +import javax.swing.ImageIcon; + +import biomesoplenty.api.BOPObfuscationHelper; +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.renderer.ThreadDownloadImageData; +import net.minecraftforge.client.event.RenderPlayerEvent; +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; + +@Deprecated +/**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 int timeout = 1000; + + private static final Graphics TEST_GRAPHICS = new BufferedImage(128, 128, + BufferedImage.TYPE_INT_RGB).getGraphics(); + private HashMap cloaks = new HashMap(); + private ArrayList capePlayers = new ArrayList(); + + public static CapeEventHandlerOld instance; + + public CapeEventHandlerOld() + { + buildCloakURLDatabase(); + instance = this; + } + + @SubscribeEvent + @SideOnly(Side.CLIENT) + public void onPreRenderSpecials(RenderPlayerEvent.Specials.Pre event) + { + if (Loader.isModLoaded("shadersmod")) + { + return; + } + if (event.entityPlayer instanceof AbstractClientPlayer) + { + AbstractClientPlayer abstractClientPlayer = (AbstractClientPlayer) event.entityPlayer; + + if (!capePlayers.contains(abstractClientPlayer)) + { + String cloakURL = cloaks.get(event.entityPlayer.getDisplayName()); + + if (cloakURL == null) + { + return; + } + + 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(); + } + + new Thread(new CloakThread(abstractClientPlayer, cloakURL)).start(); + event.renderCape = true; + } + } + } + + public void buildCloakURLDatabase() + { + URL url; + try + { + url = new URL(serverLocation); + URLConnection con = url.openConnection(); + con.setConnectTimeout(timeout); + con.setReadTimeout(timeout); + InputStream io = con.getInputStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(io)); + + String str; + int linetracker = 1; + while ((str = br.readLine()) != null) + { + if (!str.startsWith("--") && !str.isEmpty()) + { + if (str.contains(":")) + { + String nick = str.substring(0, str.indexOf(":")); + String link = str.substring(str.indexOf(":") + 1); + new Thread(new CloakPreload(link)).start(); + cloaks.put(nick, link); + } + else + { + System.err.println("[BiomesOPlenty] [capes.txt] Syntax error on line " + linetracker + ": " + str); + } + } + linetracker++; + } + + br.close(); + } + catch (MalformedURLException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + private class CloakThread implements Runnable + { + AbstractClientPlayer abstractClientPlayer; + String cloakURL; + + public CloakThread(AbstractClientPlayer player, String cloak) + { + abstractClientPlayer = player; + cloakURL = cloak; + } + + @Override + public void run() + { + try + { + Image cape = new ImageIcon(new URL(cloakURL)).getImage(); + BufferedImage bo = new BufferedImage(cape.getWidth(null), + 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(); + } + } + catch (MalformedURLException e) + { + e.printStackTrace(); + } + } + } + + private class CloakPreload implements Runnable + { + String cloakURL; + + public CloakPreload(String link) + { + cloakURL = link; + } + + @Override + public void run() + { + try + { + TEST_GRAPHICS + .drawImage(new ImageIcon(new URL(cloakURL)).getImage(), + 0, 0, null); + } + catch (MalformedURLException e) + { + e.printStackTrace(); + } + } + } + + public void refreshCapes() + { + cloaks.clear(); + capePlayers.clear(); + buildCloakURLDatabase(); + } +} \ No newline at end of file