bspkrs

Beginning of IngameInfo ML class

Nov 30th, 2012
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.37 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.io.*;
  4. import java.net.URL;
  5. import java.util.*;
  6. import java.util.logging.Level;
  7. import java.text.SimpleDateFormat;
  8. import net.minecraft.client.Minecraft;
  9.  
  10. public class mod_ingameInfo extends BaseMod
  11. {
  12.     private Minecraft minecraft;
  13.     private ScaledResolution scaledResolution;
  14.     private int alignMode;
  15.     int y[];
  16.     String text[];
  17.     String fileName;
  18.     private boolean checkUpdate;
  19.  
  20.     public mod_ingameInfo()
  21.     {
  22.         minecraft = ModLoader.getMinecraftInstance();
  23.         y = new int[3];
  24.         fileName = "ingameInfo";
  25.         text = loadText(new File(Minecraft.getMinecraftDir(), (new StringBuilder()).append("/mods/daftpvf/").append(fileName).toString()));
  26.         ModLoader.setInGameHook(this, true, false);
  27.         checkUpdate = true;
  28.     }
  29.  
  30.     public void load()
  31.     {
  32.         if(!isCurrentVersion(ModLoader.getMinecraftInstance()))
  33.             ModLoader.getLogger().log(Level.INFO, "Your version of IngameInfo is out of date! Visit http://www.minecraftforum.net/topic/1009577- for the latest version.");
  34.     }
  35.  
  36.     public String getVersion()
  37.     {
  38.         return "1.3.1.h modified by bspkrs";
  39.     }
  40.  
  41.     public boolean onTickInGame(float f, Minecraft mc)
  42.     {
  43.         if(mc.inGameHasFocus && !mc.gameSettings.showDebugInfo)
  44.         {
  45.             scaledResolution = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
  46.             y = (new int[] {
  47.                 0, 0, 0, 0, 0, 0, 0, 0, 0
  48.             });
  49.             String lines[] = text;
  50.             int i = lines.length;
  51.             for(int j = 0; j < i; j++)
  52.             {
  53.                 String s = lines[j];
  54.                 s = replaceAllTags(s);
  55.                 mc.fontRenderer.drawStringWithShadow(s, getX(mc.fontRenderer.getStringWidth(s)), getY(i, y[alignMode]), 0xffffff);
  56.                 y[alignMode]++;
  57.             }
  58.  
  59.         }
  60.        
  61.         if(checkUpdate)
  62.         {
  63.             if(!isCurrentVersion(mc) && mc.inGameHasFocus)
  64.             {
  65.                 minecraft.thePlayer.addChatMessage("&cYour version of IngameInfo is out of date!");
  66.                 minecraft.thePlayer.addChatMessage("&cVisit http://www.minecraftforum.net/topic/1009577- for the latest version.");
  67.             }
  68.             checkUpdate = false;
  69.         }
  70.         return true;
  71.     }
  72.    
  73.     private boolean isCurrentVersion(Minecraft minecraft)
  74.     {
  75.         try
  76.         {
  77.             String[] version = loadTextFromURL(new URL("https://dl.dropbox.com/u/20748481/Minecraft/1.3.1/ingameInfo.version"));
  78.             return version[0].equalsIgnoreCase(getVersion());
  79.         }
  80.         catch(Exception e)
  81.         {
  82.             ModLoader.getLogger().log(Level.WARNING, "Error getting current version info: " + e.getStackTrace());
  83.             return true;
  84.         }
  85.     }
  86.  
  87.     private String[] loadTextFromURL(URL url)
  88.     {
  89.         ArrayList arraylist = new ArrayList();
  90.         Scanner scanner = null;
  91.         try
  92.         {
  93.             scanner = new Scanner(url.openStream(), "UTF-8");
  94.         }
  95.         catch(FileNotFoundException filenotfoundexception) { } catch (IOException e) {
  96.             ModLoader.getLogger().log(Level.WARNING, "Error getting current version info: " + e.getStackTrace());
  97.         }
  98.         while(scanner.hasNextLine())
  99.         {
  100.             arraylist.add(scanner.nextLine());
  101.         }
  102.         scanner.close();
  103.         return (String[])arraylist.toArray(new String[arraylist.size()]);
  104.     }
Advertisement
Add Comment
Please, Sign In to add comment