bspkrs

Example Mod for FML MLProps issue

Aug 21st, 2012
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.96 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.net.URL;
  6. import java.util.ArrayList;
  7. import java.util.Collection;
  8. import java.util.Iterator;
  9. import java.util.Scanner;
  10. import java.util.logging.Level;
  11.  
  12. import org.lwjgl.opengl.GL11;
  13.  
  14. import net.minecraft.client.Minecraft;
  15.  
  16. public class mod_StatusEffectHUD extends BaseMod
  17. {
  18.     protected float zLevel = 0.0F;
  19.     private ScaledResolution scaledResolution;
  20.     @MLProp(info="Valid alignment strings are topleft, topcenter, topright, middleleft, middlecenter, middleright, bottomleft, bottomcenter (not recommended), bottomright")
  21.     public static String alignMode = "topleft";
  22.     @MLProp(info="Set to true to see the effect background box, false to disable")
  23.     public static boolean enableBackground = true;
  24.     @MLProp(info="Set to true to show effect names, false to disable\n\n**ONLY EDIT WHAT IS BELOW THIS**")
  25.     public static boolean enableEffectName = true;
  26.     private boolean checkUpdate;
  27.    
  28.     public mod_StatusEffectHUD()
  29.     {
  30.         ModLoader.setInGameHook(this, true, false);
  31.         checkUpdate = true;
  32.     }
  33.  
  34.     @Override
  35.     public String getVersion()
  36.     {
  37.         return "v1.3 (1.3.2)";
  38.     }
  39.  
  40.     @Override
  41.     public void load()
  42.     {
  43.         if(!isCurrentVersion(ModLoader.getMinecraftInstance()))
  44.             ModLoader.getLogger().log(Level.INFO, "Your version of StatusEffectHUD is out of date! Visit http://www.minecraftforum.net/topic/1114612- for the latest version.");
  45.     }
  46.  
  47.     public boolean onTickInGame(float f, Minecraft mc)
  48.     {
  49.         if(mc.inGameHasFocus && !mc.gameSettings.showDebugInfo)
  50.         {
  51.             scaledResolution = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
  52.             displayStatusEffects(mc);
  53.         }
  54.        
  55.         if(checkUpdate)
  56.         {
  57.             if(!isCurrentVersion(mc) && mc.inGameHasFocus)
  58.             {
  59.                 mc.thePlayer.addChatMessage("&cYour version of StatusEffectHUD is out of date!");
  60.                 mc.thePlayer.addChatMessage("&cVisit http://www.minecraftforum.net/topic/1114612- for the latest version.");
  61.             }
  62.             checkUpdate = false;
  63.         }
  64.         return true;
  65.     }
  66.    
  67.     private boolean isCurrentVersion(Minecraft minecraft)
  68.     {
  69.         try
  70.         {
  71.             String[] version = loadTextFromURL(new URL("https://dl.dropbox.com/u/20748481/Minecraft/1.3.1/statusEffectHUD.version"));
  72.             return version[0].equalsIgnoreCase(getVersion());
  73.         }
  74.         catch(Exception e)
  75.         {
  76.             ModLoader.getLogger().log(Level.WARNING, "Error getting current version info: " + e.getStackTrace());
  77.             return true;
  78.         }
  79.     }
  80.  
  81.     private String[] loadTextFromURL(URL url)
  82.     {
  83.         ArrayList arraylist = new ArrayList();
  84.         Scanner scanner = null;
  85.         try
  86.         {
  87.             scanner = new Scanner(url.openStream(), "UTF-8");
  88.         }
  89.         catch(FileNotFoundException filenotfoundexception) { } catch (IOException e) {
  90.             ModLoader.getLogger().log(Level.WARNING, "Error getting current version info: " + e.getStackTrace());
  91.         }
  92.         while(scanner.hasNextLine())
  93.         {
  94.             arraylist.add(scanner.nextLine());
  95.         }
  96.         scanner.close();
  97.         return (String[])arraylist.toArray(new String[arraylist.size()]);
  98.     }
  99.  
  100.     private int getX(int width)
  101.     {
  102.         if(alignMode.equalsIgnoreCase("topcenter") || alignMode.equalsIgnoreCase("middlecenter") || alignMode.equalsIgnoreCase("bottomcenter"))
  103.             return scaledResolution.getScaledWidth() / 2 - width / 2;
  104.         else if(alignMode.equalsIgnoreCase("topright") || alignMode.equalsIgnoreCase("middleright")|| alignMode.equalsIgnoreCase("bottomright"))
  105.             return scaledResolution.getScaledWidth() - width - 2;
  106.         else
  107.             return 2;
  108.     }
  109.  
  110.     private int getY(int rowCount, int yOffset)
  111.     {
  112.         if(alignMode.equalsIgnoreCase("middleleft") || alignMode.equalsIgnoreCase("middlecenter") || alignMode.equalsIgnoreCase("middleright"))
  113.             return (scaledResolution.getScaledHeight()/2) - ((rowCount * yOffset)/2);
  114.         else if(alignMode.equalsIgnoreCase("bottomleft") || alignMode.equalsIgnoreCase("bottomcenter") || alignMode.equalsIgnoreCase("bottomright"))
  115.             return scaledResolution.getScaledHeight() - (rowCount * yOffset) - 2;
  116.         else
  117.             return 2;
  118.     }
  119.    
  120.     private void displayStatusEffects(Minecraft mc)
  121.     {                                      
  122.         Collection activeEffects = mc.thePlayer.getActivePotionEffects();
  123.         int guiTexture = mc.renderEngine.getTexture("/gui/inventory.png");
  124.  
  125.         if (!activeEffects.isEmpty())
  126.         {
  127.             int yOffset = enableBackground ? 33 : enableEffectName ? 20 : 18;
  128.             if (activeEffects.size() > 5 && enableBackground)
  129.                 yOffset = 132 / (activeEffects.size() - 1);
  130.  
  131.             int yBase = getY(activeEffects.size(),yOffset);
  132.  
  133.             for (Iterator iteratorPotionEffect = activeEffects.iterator(); iteratorPotionEffect.hasNext(); yBase += yOffset)
  134.             {
  135.                 PotionEffect potionEffect = (PotionEffect)iteratorPotionEffect.next();
  136.                 Potion potion = Potion.potionTypes[potionEffect.getPotionID()];
  137.                 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  138.                 mc.renderEngine.bindTexture(guiTexture);
  139.                 int xBase = getX(enableBackground ? 120 : 18 + 4 + mc.fontRenderer.getStringWidth("0:00"));
  140.                 String potionName = "";
  141.                
  142.                 if(enableEffectName)
  143.                 {
  144.                     potionName = StatCollector.translateToLocal(potion.getName());
  145.    
  146.                     if (potionEffect.getAmplifier() == 1)
  147.                     {
  148.                         potionName = potionName + " II";
  149.                     }
  150.                     else if (potionEffect.getAmplifier() == 2)
  151.                     {
  152.                         potionName = potionName + " III";
  153.                     }
  154.                     else if (potionEffect.getAmplifier() == 3)
  155.                     {
  156.                         potionName = potionName + " IV";
  157.                     }
  158.                    
  159.                     xBase = getX(enableBackground ? 120 : 18 + 4 + mc.fontRenderer.getStringWidth(potionName));
  160.                 }
  161.                 if(enableBackground)
  162.                     this.drawTexturedModalRect(xBase, yBase, 0, 166, 140, 32);
  163.  
  164.                 if (potion.hasStatusIcon())
  165.                 {
  166.                     int potionStatusIcon = potion.getStatusIconIndex();
  167.                     drawTexturedModalRect(xBase + (enableBackground ? 6 : 0), yBase + (enableBackground ? 7 : 0), 0 + potionStatusIcon % 8 * 18, 166 + 32 + potionStatusIcon / 8 * 18, 18, 18);
  168.                 }
  169.                 mc.fontRenderer.drawStringWithShadow(potionName, xBase + (enableBackground ? 10 : 4) + 18, yBase + (enableBackground ? 6 : 0), 0xffffff);
  170.                 String effectDuration = Potion.getDurationString(potionEffect);
  171.                 mc.fontRenderer.drawStringWithShadow(effectDuration, xBase + (enableBackground ? 10 : 4) + 18, yBase + (enableBackground ? 6 : 0) + (enableEffectName ? 10: 5), 0xffffff);
  172.             }
  173.         }
  174.     }
  175.    
  176.     public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height)
  177.     {
  178.         float var7 = 0.00390625F;
  179.         float var8 = 0.00390625F;
  180.         Tessellator tessellator = Tessellator.instance;
  181.         tessellator.startDrawingQuads();
  182.         tessellator.addVertexWithUV((double)(x + 0), (double)(y + height), (double)this.zLevel, (double)((float)(u + 0) * var7), (double)((float)(v + height) * var8));
  183.         tessellator.addVertexWithUV((double)(x + width), (double)(y + height), (double)this.zLevel, (double)((float)(u + width) * var7), (double)((float)(v + height) * var8));
  184.         tessellator.addVertexWithUV((double)(x + width), (double)(y + 0), (double)this.zLevel, (double)((float)(u + width) * var7), (double)((float)(v + 0) * var8));
  185.         tessellator.addVertexWithUV((double)(x + 0), (double)(y + 0), (double)this.zLevel, (double)((float)(u + 0) * var7), (double)((float)(v + 0) * var8));
  186.         tessellator.draw();
  187.     }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment