diff --git a/tconstruct/TConstruct.java b/tconstruct/TConstruct.java index e194514d..fa004465 100644 --- a/tconstruct/TConstruct.java +++ b/tconstruct/TConstruct.java @@ -1,6 +1,8 @@ package tconstruct; import net.minecraftforge.common.MinecraftForge; + +import tconstruct.client.event.EventCloakRender; import tconstruct.client.tabs.InventoryTabArmorExtended; import tconstruct.client.tabs.InventoryTabKnapsack; import tconstruct.client.tabs.InventoryTabVanilla; @@ -35,6 +37,7 @@ import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.VillagerRegistry; +import cpw.mods.fml.relauncher.Side; /** TConstruct, the tool mod. * Craft your tools with style, then modify until the original is gone! @@ -120,6 +123,10 @@ public class TConstruct @EventHandler public void init (FMLInitializationEvent event) { + if(event.getSide() == Side.CLIENT){ + MinecraftForge.EVENT_BUS.register(new EventCloakRender()); + } + content.intermodCommunication(); GameRegistry.registerWorldGenerator(new SlimeIslandGen(TContent.slimePool.blockID, 0)); diff --git a/tconstruct/client/TProxyClient.java b/tconstruct/client/TProxyClient.java index 49a6766c..91a90adc 100644 --- a/tconstruct/client/TProxyClient.java +++ b/tconstruct/client/TProxyClient.java @@ -61,10 +61,6 @@ public class TProxyClient extends TProxyCommon { public static ArmorExtended armorExtended = new ArmorExtended(); public static KnapsackInventory knapsack = new KnapsackInventory(); - - public TProxyClient(){ -// MinecraftForge.EVENT_BUS.register(new EventCloakRender()); - } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { diff --git a/tconstruct/client/event/EventCloakRender.java b/tconstruct/client/event/EventCloakRender.java index 7c30db58..d9d5e482 100644 --- a/tconstruct/client/event/EventCloakRender.java +++ b/tconstruct/client/event/EventCloakRender.java @@ -1,7 +1,9 @@ package tconstruct.client.event; import java.awt.image.BufferedImage; +import java.io.*; import java.net.*; +import java.util.HashMap; import javax.swing.ImageIcon; @@ -11,19 +13,65 @@ import net.minecraftforge.event.ForgeSubscribe; public class EventCloakRender { + private final String serverLocation = "https://raw.github.com/mDiyo/TinkersConstruct/16working/capes.txt"; + private final int timeout = 1000; + + private HashMap cloaks = new HashMap(); + + public EventCloakRender(){ + buildCloakURLDatabase(); + } + @ForgeSubscribe public void onPreRenderSpecials(RenderPlayerEvent.Specials.Pre event){ if(event.entityPlayer instanceof AbstractClientPlayer){ AbstractClientPlayer abstractClientPlayer = (AbstractClientPlayer)event.entityPlayer; - abstractClientPlayer.func_110310_o().field_110559_g = false; - abstractClientPlayer.func_110310_o().field_110560_d = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB); - try { - abstractClientPlayer.func_110310_o().field_110560_d.getGraphics().drawImage(new ImageIcon(new URL("https://dl.dropboxusercontent.com/u/48633261/cape.png")).getImage(), 0, 0, null); - } catch (MalformedURLException e) { - e.printStackTrace(); + + if (abstractClientPlayer.func_110310_o().field_110560_d == null) { + String cloakURL = cloaks.get(event.entityPlayer.username); + + if(cloakURL == null){ + return; + } + + abstractClientPlayer.func_110310_o().field_110560_d = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB); + abstractClientPlayer.func_110310_o().field_110559_g = false; + try { + abstractClientPlayer.func_110310_o().field_110560_d.getGraphics().drawImage(new ImageIcon(new URL(cloakURL)).getImage(), 0, 0, null); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + 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; + while((str = br.readLine()) != null){ + if(str.contains(":")){ + String nick = str.substring(0, str.indexOf(":")); + String link = str.substring(str.indexOf(":") + 1); + System.out.println(nick + " " + link); + cloaks.put(nick, link); + } } - event.renderCape = true; + br.close(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); } }