Commit 7e6adb61cdefcb0bcf6f8895744cda19938536c9

Authored by Mumfrey
1 parent 5403adcb

LiteLoader for Minecraft 1.5

java/com/mumfrey/liteloader/PluginChannelListener.java
@@ -16,12 +16,12 @@ public interface PluginChannelListener extends LoginListener @@ -16,12 +16,12 @@ public interface PluginChannelListener extends LoginListener
16 */ 16 */
17 public abstract List<String> getChannels(); 17 public abstract List<String> getChannels();
18 18
19 - /**  
20 - * Called when a custom payload packet arrives on a channel this mod has registered  
21 - *  
22 - * @param channel Channel on which the custom payload was received  
23 - * @param length Length of the custom payload data  
24 - * @param data Custom payload data  
25 - */  
26 - public abstract void onCustomPayload(String channel, int length, byte[] data); 19 + /**
  20 + * Called when a custom payload packet arrives on a channel this mod has registered
  21 + *
  22 + * @param channel Channel on which the custom payload was received
  23 + * @param length Length of the custom payload data
  24 + * @param data Custom payload data
  25 + */
  26 + public abstract void onCustomPayload(String channel, int length, byte[] data);
27 } 27 }
java/com/mumfrey/liteloader/core/HookChat.java
@@ -117,15 +117,15 @@ public class HookChat extends Packet3Chat @@ -117,15 +117,15 @@ public class HookChat extends Packet3Chat
117 { 117 {
118 if (proxyPacket != null) 118 if (proxyPacket != null)
119 return proxyPacket.getPacketSize(); 119 return proxyPacket.getPacketSize();
120 - else  
121 - return super.getPacketSize(); 120 +
  121 + return super.getPacketSize();
122 } 122 }
123 123
124 /** 124 /**
125 * Register the specified handler as the packet handler for this packet 125 * Register the specified handler as the packet handler for this packet
126 * @param handler 126 * @param handler
127 */ 127 */
128 - public static void RegisterPacketHandler(LiteLoader handler) 128 + public static void registerPacketHandler(LiteLoader handler)
129 { 129 {
130 packetHandler = handler; 130 packetHandler = handler;
131 } 131 }
@@ -133,9 +133,9 @@ public class HookChat extends Packet3Chat @@ -133,9 +133,9 @@ public class HookChat extends Packet3Chat
133 /** 133 /**
134 * Register this packet as the new packet for packet ID 3 134 * Register this packet as the new packet for packet ID 3
135 */ 135 */
136 - public static void Register() 136 + public static void register()
137 { 137 {
138 - Register(false); 138 + register(false);
139 } 139 }
140 140
141 /** 141 /**
@@ -144,8 +144,8 @@ public class HookChat extends Packet3Chat @@ -144,8 +144,8 @@ public class HookChat extends Packet3Chat
144 * 144 *
145 * @param force Force registration even if registration was already performed previously. 145 * @param force Force registration even if registration was already performed previously.
146 */ 146 */
147 - @SuppressWarnings("unchecked")  
148 - public static void Register(boolean force) 147 + @SuppressWarnings({ "unchecked", "rawtypes" })
  148 + public static void register(boolean force)
149 { 149 {
150 if (!registered || force) 150 if (!registered || force)
151 { 151 {
@@ -162,7 +162,7 @@ public class HookChat extends Packet3Chat @@ -162,7 +162,7 @@ public class HookChat extends Packet3Chat
162 packetIdToClassMap.removeObject(3); 162 packetIdToClassMap.removeObject(3);
163 packetIdToClassMap.addKey(3, HookChat.class); 163 packetIdToClassMap.addKey(3, HookChat.class);
164 164
165 - Map packetClassToIdMap = PrivateFields.StaticFields.packetClassToIdMap.Get(); 165 + Map packetClassToIdMap = PrivateFields.StaticFields.packetClassToIdMap.get();
166 packetClassToIdMap.put(HookChat.class, Integer.valueOf(3)); 166 packetClassToIdMap.put(HookChat.class, Integer.valueOf(3));
167 167
168 registered = true; 168 registered = true;
java/com/mumfrey/liteloader/core/HookPluginChannels.java
@@ -109,15 +109,15 @@ public class HookPluginChannels extends Packet250CustomPayload @@ -109,15 +109,15 @@ public class HookPluginChannels extends Packet250CustomPayload
109 { 109 {
110 if (proxyPacket != null) 110 if (proxyPacket != null)
111 return proxyPacket.getPacketSize(); 111 return proxyPacket.getPacketSize();
112 - else  
113 - return super.getPacketSize(); 112 +
  113 + return super.getPacketSize();
114 } 114 }
115 115
116 /** 116 /**
117 * Register the specified handler as the packet handler for this packet 117 * Register the specified handler as the packet handler for this packet
118 * @param handler 118 * @param handler
119 */ 119 */
120 - public static void RegisterPacketHandler(LiteLoader handler) 120 + public static void registerPacketHandler(LiteLoader handler)
121 { 121 {
122 packetHandler = handler; 122 packetHandler = handler;
123 } 123 }
@@ -125,9 +125,9 @@ public class HookPluginChannels extends Packet250CustomPayload @@ -125,9 +125,9 @@ public class HookPluginChannels extends Packet250CustomPayload
125 /** 125 /**
126 * Register this packet as the new packet for packet ID 250 126 * Register this packet as the new packet for packet ID 250
127 */ 127 */
128 - public static void Register() 128 + public static void register()
129 { 129 {
130 - Register(false); 130 + register(false);
131 } 131 }
132 132
133 /** 133 /**
@@ -136,8 +136,8 @@ public class HookPluginChannels extends Packet250CustomPayload @@ -136,8 +136,8 @@ public class HookPluginChannels extends Packet250CustomPayload
136 * 136 *
137 * @param force Force registration even if registration was already performed previously. 137 * @param force Force registration even if registration was already performed previously.
138 */ 138 */
139 - @SuppressWarnings("unchecked")  
140 - public static void Register(boolean force) 139 + @SuppressWarnings({ "unchecked", "rawtypes" })
  140 + public static void register(boolean force)
141 { 141 {
142 if (!registered || force) 142 if (!registered || force)
143 { 143 {
@@ -154,7 +154,7 @@ public class HookPluginChannels extends Packet250CustomPayload @@ -154,7 +154,7 @@ public class HookPluginChannels extends Packet250CustomPayload
154 packetIdToClassMap.removeObject(250); 154 packetIdToClassMap.removeObject(250);
155 packetIdToClassMap.addKey(250, HookPluginChannels.class); 155 packetIdToClassMap.addKey(250, HookPluginChannels.class);
156 156
157 - Map packetClassToIdMap = PrivateFields.StaticFields.packetClassToIdMap.Get(); 157 + Map packetClassToIdMap = PrivateFields.StaticFields.packetClassToIdMap.get();
158 packetClassToIdMap.put(HookPluginChannels.class, Integer.valueOf(250)); 158 packetClassToIdMap.put(HookPluginChannels.class, Integer.valueOf(250));
159 159
160 registered = true; 160 registered = true;
java/com/mumfrey/liteloader/core/HookProfiler.java
@@ -5,10 +5,7 @@ import java.lang.reflect.Method; @@ -5,10 +5,7 @@ import java.lang.reflect.Method;
5 import java.util.LinkedList; 5 import java.util.LinkedList;
6 import java.util.logging.Logger; 6 import java.util.logging.Logger;
7 7
8 -import com.mumfrey.liteloader.util.ModUtilities;  
9 -  
10 import net.minecraft.client.Minecraft; 8 import net.minecraft.client.Minecraft;
11 -import net.minecraft.src.EntityPlayerSP;  
12 import net.minecraft.src.GameSettings; 9 import net.minecraft.src.GameSettings;
13 import net.minecraft.src.Profiler; 10 import net.minecraft.src.Profiler;
14 11
@@ -68,7 +65,7 @@ public class HookProfiler extends Profiler @@ -68,7 +65,7 @@ public class HookProfiler extends Profiler
68 this.logger = logger; 65 this.logger = logger;
69 66
70 // Detect optifine (duh!) 67 // Detect optifine (duh!)
71 - DetectOptifine(); 68 + detectOptifine();
72 } 69 }
73 70
74 /** 71 /**
@@ -76,7 +73,7 @@ public class HookProfiler extends Profiler @@ -76,7 +73,7 @@ public class HookProfiler extends Profiler
76 * 73 *
77 * @param logger 74 * @param logger
78 */ 75 */
79 - private void DetectOptifine() 76 + private void detectOptifine()
80 { 77 {
81 try 78 try
82 { 79 {
@@ -91,7 +88,7 @@ public class HookProfiler extends Profiler @@ -91,7 +88,7 @@ public class HookProfiler extends Profiler
91 { 88 {
92 if (ofProfiler != null) 89 if (ofProfiler != null)
93 { 90 {
94 - logger.info(String.format("Optifine version %s detected, enabling compatibility check", GetOptifineVersion())); 91 + logger.info(String.format("Optifine version %s detected, enabling compatibility check", getOptifineVersion()));
95 } 92 }
96 } 93 }
97 } 94 }
@@ -101,15 +98,14 @@ public class HookProfiler extends Profiler @@ -101,15 +98,14 @@ public class HookProfiler extends Profiler
101 * 98 *
102 * @return 99 * @return
103 */ 100 */
104 - private String GetOptifineVersion() 101 + private String getOptifineVersion()
105 { 102 {
106 try 103 try
107 { 104 {
108 - Class config = Class.forName("Config"); 105 + Class<?> config = Class.forName("Config");
109 106
110 if (config != null) 107 if (config != null)
111 { 108 {
112 - @SuppressWarnings("unchecked")  
113 Method getVersion = config.getDeclaredMethod("getVersion"); 109 Method getVersion = config.getDeclaredMethod("getVersion");
114 110
115 if (getVersion != null) 111 if (getVersion != null)
java/com/mumfrey/liteloader/core/LiteLoader.java
@@ -11,7 +11,6 @@ import java.io.IOException; @@ -11,7 +11,6 @@ import java.io.IOException;
11 import java.io.InputStream; 11 import java.io.InputStream;
12 import java.io.InputStreamReader; 12 import java.io.InputStreamReader;
13 import java.io.PrintStream; 13 import java.io.PrintStream;
14 -import java.lang.reflect.Constructor;  
15 import java.lang.reflect.Method; 14 import java.lang.reflect.Method;
16 import java.net.URL; 15 import java.net.URL;
17 import java.net.URLClassLoader; 16 import java.net.URLClassLoader;
@@ -32,8 +31,9 @@ import java.util.zip.ZipEntry; @@ -32,8 +31,9 @@ import java.util.zip.ZipEntry;
32 import java.util.zip.ZipFile; 31 import java.util.zip.ZipFile;
33 import java.util.zip.ZipInputStream; 32 import java.util.zip.ZipInputStream;
34 33
  34 +import javax.activity.InvalidActivityException;
  35 +
35 import net.minecraft.client.Minecraft; 36 import net.minecraft.client.Minecraft;
36 -import net.minecraft.src.ConsoleLogManager;  
37 import net.minecraft.src.NetHandler; 37 import net.minecraft.src.NetHandler;
38 import net.minecraft.src.Packet1Login; 38 import net.minecraft.src.Packet1Login;
39 import net.minecraft.src.Packet3Chat; 39 import net.minecraft.src.Packet3Chat;
@@ -57,7 +57,7 @@ import com.mumfrey.liteloader.util.PrivateFields; @@ -57,7 +57,7 @@ import com.mumfrey.liteloader.util.PrivateFields;
57 * LiteLoader is a simple loader which provides tick events to loaded mods 57 * LiteLoader is a simple loader which provides tick events to loaded mods
58 * 58 *
59 * @author Adam Mummery-Smith 59 * @author Adam Mummery-Smith
60 - * @version 1.4.7 60 + * @version 1.5
61 */ 61 */
62 @SuppressWarnings("rawtypes") 62 @SuppressWarnings("rawtypes")
63 public final class LiteLoader implements FilenameFilter 63 public final class LiteLoader implements FilenameFilter
@@ -65,19 +65,19 @@ public final class LiteLoader implements FilenameFilter @@ -65,19 +65,19 @@ public final class LiteLoader implements FilenameFilter
65 /** 65 /**
66 * Liteloader version 66 * Liteloader version
67 */ 67 */
68 - private static final String LOADER_VERSION = "1.4.7"; 68 + private static final String LOADER_VERSION = "1.5";
69 69
70 /** 70 /**
71 * Loader revision, can be used by mods to determine whether the loader is sufficiently up-to-date 71 * Loader revision, can be used by mods to determine whether the loader is sufficiently up-to-date
72 */ 72 */
73 - private static final int LOADER_REVISION = 7; 73 + private static final int LOADER_REVISION = 8;
74 74
75 /** 75 /**
76 * Minecraft versions that we will load mods for, this will be compared 76 * Minecraft versions that we will load mods for, this will be compared
77 * against the version.txt value in mod files to prevent outdated mods being 77 * against the version.txt value in mod files to prevent outdated mods being
78 * loaded!!! 78 * loaded!!!
79 */ 79 */
80 - private static final String[] SUPPORTED_VERSIONS = { "1.4.6", "1.4.7" }; 80 + private static final String[] SUPPORTED_VERSIONS = { "1.5", "1.5.r1" };
81 81
82 /** 82 /**
83 * Maximum recursion depth for mod discovery 83 * Maximum recursion depth for mod discovery
@@ -241,6 +241,11 @@ public final class LiteLoader implements FilenameFilter @@ -241,6 +241,11 @@ public final class LiteLoader implements FilenameFilter
241 return logger; 241 return logger;
242 } 242 }
243 243
  244 + /**
  245 + * Get the output stream which we are using for console output
  246 + *
  247 + * @return
  248 + */
244 public static final PrintStream getConsoleStream() 249 public static final PrintStream getConsoleStream()
245 { 250 {
246 return useStdOut ? System.out : System.err; 251 return useStdOut ? System.out : System.err;
@@ -331,7 +336,7 @@ public final class LiteLoader implements FilenameFilter @@ -331,7 +336,7 @@ public final class LiteLoader implements FilenameFilter
331 */ 336 */
332 private void prepareClassOverrides() 337 private void prepareClassOverrides()
333 { 338 {
334 - this.registerBaseClassOverride(ModUtilities.getObfuscatedFieldName("net.minecraft.src.CallableJVMFlags", "g"), "g"); 339 + this.registerBaseClassOverride(ModUtilities.getObfuscatedFieldName("net.minecraft.src.CallableJVMFlags", "h"), "h");
335 } 340 }
336 341
337 /** 342 /**
@@ -355,25 +360,25 @@ public final class LiteLoader implements FilenameFilter @@ -355,25 +360,25 @@ public final class LiteLoader implements FilenameFilter
355 360
356 for (int readBytes = resourceInputStream.read(); readBytes >= 0; readBytes = resourceInputStream.read()) 361 for (int readBytes = resourceInputStream.read(); readBytes >= 0; readBytes = resourceInputStream.read())
357 { 362 {
358 - outputStream.write(readBytes); 363 + outputStream.write(readBytes);
359 } 364 }
360 - 365 +
361 byte[] data = outputStream.toByteArray(); 366 byte[] data = outputStream.toByteArray();
362 367
363 outputStream.close(); 368 outputStream.close();
364 - resourceInputStream.close(); 369 + resourceInputStream.close();
365 370
366 - logger.info("Defining class override for " + binaryClassName);  
367 - mDefineClass.invoke(Minecraft.class.getClassLoader(), binaryClassName, data, 0, data.length); 371 + logger.info("Defining class override for " + binaryClassName);
  372 + mDefineClass.invoke(Minecraft.class.getClassLoader(), binaryClassName, data, 0, data.length);
368 } 373 }
369 else 374 else
370 { 375 {
371 - logger.info("Error defining class override for " + binaryClassName + ", file not found"); 376 + logger.info("Error defining class override for " + binaryClassName + ", file not found");
372 } 377 }
373 } 378 }
374 catch (Throwable th) 379 catch (Throwable th)
375 { 380 {
376 - logger.log(Level.WARNING, "Error defining class override for " + binaryClassName, th); 381 + logger.log(Level.WARNING, "Error defining class override for " + binaryClassName, th);
377 } 382 }
378 } 383 }
379 384
@@ -417,34 +422,19 @@ public final class LiteLoader implements FilenameFilter @@ -417,34 +422,19 @@ public final class LiteLoader implements FilenameFilter
417 * @throws SecurityException 422 * @throws SecurityException
418 * @throws IOException 423 * @throws IOException
419 */ 424 */
420 - @SuppressWarnings("unchecked")  
421 private void prepareLogger() throws SecurityException, IOException 425 private void prepareLogger() throws SecurityException, IOException
422 { 426 {
423 - Formatter minecraftLogFormatter = null;  
424 -  
425 - try  
426 - {  
427 - Class<? extends Formatter> formatterClass = (Class<? extends Formatter>)Minecraft.class.getClassLoader().loadClass(ModUtilities.getObfuscatedFieldName("net.minecraft.src.ConsoleLogFormatter", "em"));  
428 - Constructor<? extends Formatter> defaultConstructor = formatterClass.getDeclaredConstructor();  
429 - defaultConstructor.setAccessible(true);  
430 - minecraftLogFormatter = defaultConstructor.newInstance();  
431 - }  
432 - catch (Exception ex)  
433 - {  
434 - ConsoleLogManager.init();  
435 - minecraftLogFormatter = ConsoleLogManager.loggerLogManager.getHandlers()[0].getFormatter();  
436 - } 427 + Formatter logFormatter = new LiteLoaderLogFormatter();
437 428
438 logger.setUseParentHandlers(false); 429 logger.setUseParentHandlers(false);
439 -  
440 this.useStdOut = System.getProperty("liteloader.log", "stderr").equalsIgnoreCase("stdout") || this.localProperties.getProperty("log", "stderr").equalsIgnoreCase("stdout"); 430 this.useStdOut = System.getProperty("liteloader.log", "stderr").equalsIgnoreCase("stdout") || this.localProperties.getProperty("log", "stderr").equalsIgnoreCase("stdout");
441 431
442 StreamHandler consoleHandler = useStdOut ? new com.mumfrey.liteloader.util.log.ConsoleHandler() : new java.util.logging.ConsoleHandler(); 432 StreamHandler consoleHandler = useStdOut ? new com.mumfrey.liteloader.util.log.ConsoleHandler() : new java.util.logging.ConsoleHandler();
443 - if (minecraftLogFormatter != null) consoleHandler.setFormatter(minecraftLogFormatter); 433 + consoleHandler.setFormatter(logFormatter);
444 logger.addHandler(consoleHandler); 434 logger.addHandler(consoleHandler);
445 435
446 FileHandler logFileHandler = new FileHandler(new File(Minecraft.getMinecraftDir(), "LiteLoader.txt").getAbsolutePath()); 436 FileHandler logFileHandler = new FileHandler(new File(Minecraft.getMinecraftDir(), "LiteLoader.txt").getAbsolutePath());
447 - if (minecraftLogFormatter != null) logFileHandler.setFormatter(minecraftLogFormatter); 437 + logFileHandler.setFormatter(logFormatter);
448 logger.addHandler(logFileHandler); 438 logger.addHandler(logFileHandler);
449 } 439 }
450 440
@@ -470,6 +460,7 @@ public final class LiteLoader implements FilenameFilter @@ -470,6 +460,7 @@ public final class LiteLoader implements FilenameFilter
470 460
471 try 461 try
472 { 462 {
  463 + this.localProperties = new Properties(this.internalProperties);
473 InputStream localPropertiesStream = this.getLocalPropertiesStream(); 464 InputStream localPropertiesStream = this.getLocalPropertiesStream();
474 465
475 if (localPropertiesStream != null) 466 if (localPropertiesStream != null)
@@ -480,7 +471,7 @@ public final class LiteLoader implements FilenameFilter @@ -480,7 +471,7 @@ public final class LiteLoader implements FilenameFilter
480 } 471 }
481 catch (Throwable th) 472 catch (Throwable th)
482 { 473 {
483 - this.localProperties = new Properties(); 474 + this.localProperties = new Properties(this.internalProperties);
484 } 475 }
485 } 476 }
486 477
@@ -560,6 +551,34 @@ public final class LiteLoader implements FilenameFilter @@ -560,6 +551,34 @@ public final class LiteLoader implements FilenameFilter
560 } 551 }
561 552
562 /** 553 /**
  554 + * Get a reference to a loaded mod, if the mod exists
  555 + *
  556 + * @param modName Mod's name or class name
  557 + * @return
  558 + * @throws InvalidActivityException
  559 + */
  560 + @SuppressWarnings("unchecked")
  561 + public <T extends LiteMod> T getMod(String modName) throws InvalidActivityException, IllegalArgumentException
  562 + {
  563 + if (!this.loaderStartupComplete)
  564 + {
  565 + throw new InvalidActivityException("Attempted to get a reference to a mod before loader startup is complete");
  566 + }
  567 +
  568 + if (modName == null)
  569 + {
  570 + throw new IllegalArgumentException("Attempted to get a reference to a mod without specifying a mod name");
  571 + }
  572 +
  573 + for (LiteMod mod : this.mods)
  574 + {
  575 + if (modName.equalsIgnoreCase(mod.getName()) || modName.equalsIgnoreCase(mod.getClass().getSimpleName())) return (T)mod;
  576 + }
  577 +
  578 + return null;
  579 + }
  580 +
  581 + /**
563 * Enumerate the java class path and "mods" folder to find mod classes, then load the classes 582 * Enumerate the java class path and "mods" folder to find mod classes, then load the classes
564 */ 583 */
565 private void prepareMods(boolean searchMods, boolean searchProtectionDomain, boolean searchClassPath) 584 private void prepareMods(boolean searchMods, boolean searchProtectionDomain, boolean searchClassPath)
@@ -637,6 +656,10 @@ public final class LiteLoader implements FilenameFilter @@ -637,6 +656,10 @@ public final class LiteLoader implements FilenameFilter
637 { 656 {
638 modFiles.add(modFile); 657 modFiles.add(modFile);
639 } 658 }
  659 + else
  660 + {
  661 + logger.info("Not adding invalid or outdated mod file: " + modFile.getAbsolutePath());
  662 + }
640 } 663 }
641 664
642 modZip.close(); 665 modZip.close();
@@ -705,6 +728,11 @@ public final class LiteLoader implements FilenameFilter @@ -705,6 +728,11 @@ public final class LiteLoader implements FilenameFilter
705 728
706 for (Class mod : modClasses) 729 for (Class mod : modClasses)
707 { 730 {
  731 + if (modsToLoad.containsKey(mod.getSimpleName()))
  732 + {
  733 + logger.warning("Mod name collision for mod with class '" + mod.getSimpleName() + "', maybe you have more than one copy?");
  734 + }
  735 +
708 modsToLoad.put(mod.getSimpleName(), mod); 736 modsToLoad.put(mod.getSimpleName(), mod);
709 } 737 }
710 738
@@ -729,6 +757,11 @@ public final class LiteLoader implements FilenameFilter @@ -729,6 +757,11 @@ public final class LiteLoader implements FilenameFilter
729 757
730 for (Class mod : modClasses) 758 for (Class mod : modClasses)
731 { 759 {
  760 + if (modsToLoad.containsKey(mod.getSimpleName()))
  761 + {
  762 + logger.warning("Mod name collision for mod with class '" + mod.getSimpleName() + "', maybe you have more than one copy?");
  763 + }
  764 +
732 modsToLoad.put(mod.getSimpleName(), mod); 765 modsToLoad.put(mod.getSimpleName(), mod);
733 } 766 }
734 767
@@ -745,6 +778,11 @@ public final class LiteLoader implements FilenameFilter @@ -745,6 +778,11 @@ public final class LiteLoader implements FilenameFilter
745 778
746 for (Class mod : modClasses) 779 for (Class mod : modClasses)
747 { 780 {
  781 + if (modsToLoad.containsKey(mod.getSimpleName()))
  782 + {
  783 + logger.warning("Mod name collision for mod with class '" + mod.getSimpleName() + "', maybe you have more than one copy?");
  784 + }
  785 +
748 modsToLoad.put(mod.getSimpleName(), mod); 786 modsToLoad.put(mod.getSimpleName(), mod);
749 } 787 }
750 788
@@ -831,9 +869,16 @@ public final class LiteLoader implements FilenameFilter @@ -831,9 +869,16 @@ public final class LiteLoader implements FilenameFilter
831 this.addChatFilter((ChatFilter)mod); 869 this.addChatFilter((ChatFilter)mod);
832 } 870 }
833 871
834 - if (mod instanceof ChatListener && !(mod instanceof ChatFilter)) 872 + if (mod instanceof ChatListener)
835 { 873 {
836 - this.addChatListener((ChatListener)mod); 874 + if (mod instanceof ChatFilter)
  875 + {
  876 + this.logger.warning(String.format("Interface error initialising mod '%1s'. A mod implementing ChatFilter and ChatListener is not supported! Remove one of these interfaces", mod.getName()));
  877 + }
  878 + else
  879 + {
  880 + this.addChatListener((ChatListener)mod);
  881 + }
837 } 882 }
838 883
839 if (mod instanceof PreLoginListener) 884 if (mod instanceof PreLoginListener)
@@ -875,8 +920,8 @@ public final class LiteLoader implements FilenameFilter @@ -875,8 +920,8 @@ public final class LiteLoader implements FilenameFilter
875 if ((this.chatListeners.size() > 0 || this.chatFilters.size() > 0) && !this.chatHooked) 920 if ((this.chatListeners.size() > 0 || this.chatFilters.size() > 0) && !this.chatHooked)
876 { 921 {
877 this.chatHooked = true; 922 this.chatHooked = true;
878 - HookChat.Register();  
879 - HookChat.RegisterPacketHandler(this); 923 + HookChat.register();
  924 + HookChat.registerPacketHandler(this);
880 } 925 }
881 926
882 // Login hook 927 // Login hook
@@ -891,15 +936,15 @@ public final class LiteLoader implements FilenameFilter @@ -891,15 +936,15 @@ public final class LiteLoader implements FilenameFilter
891 if (this.pluginChannelListeners.size() > 0 && !this.pluginChannelHooked) 936 if (this.pluginChannelListeners.size() > 0 && !this.pluginChannelHooked)
892 { 937 {
893 this.pluginChannelHooked = true; 938 this.pluginChannelHooked = true;
894 - HookPluginChannels.Register();  
895 - HookPluginChannels.RegisterPacketHandler(this); 939 + HookPluginChannels.register();
  940 + HookPluginChannels.registerPacketHandler(this);
896 } 941 }
897 942
898 // Tick hook 943 // Tick hook
899 if (!this.tickHooked) 944 if (!this.tickHooked)
900 { 945 {
901 this.tickHooked = true; 946 this.tickHooked = true;
902 - PrivateFields.minecraftProfiler.SetFinal(this.minecraft, new HookProfiler(this, logger)); 947 + PrivateFields.minecraftProfiler.setFinal(this.minecraft, new HookProfiler(this, logger));
903 } 948 }
904 } 949 }
905 catch (Exception ex) 950 catch (Exception ex)
@@ -1272,7 +1317,7 @@ public final class LiteLoader implements FilenameFilter @@ -1272,7 +1317,7 @@ public final class LiteLoader implements FilenameFilter
1272 // Try to get the minecraft timer object and determine the value of the partialTicks 1317 // Try to get the minecraft timer object and determine the value of the partialTicks
1273 if (tick || this.minecraftTimer == null) 1318 if (tick || this.minecraftTimer == null)
1274 { 1319 {
1275 - this.minecraftTimer = PrivateFields.minecraftTimer.Get(this.minecraft); 1320 + this.minecraftTimer = PrivateFields.minecraftTimer.get(this.minecraft);
1276 } 1321 }
1277 1322
1278 // Hooray, we got the timer reference 1323 // Hooray, we got the timer reference
@@ -1421,9 +1466,9 @@ public final class LiteLoader implements FilenameFilter @@ -1421,9 +1466,9 @@ public final class LiteLoader implements FilenameFilter
1421 separator = true; 1466 separator = true;
1422 } 1467 }
1423 1468
1424 - byte[] registrationData = channelList.toString().getBytes(Charset.forName("UTF8"));  
1425 -  
1426 - sendPluginChannelMessage("REGISTER", registrationData); 1469 + byte[] registrationData = channelList.toString().getBytes(Charset.forName("UTF8"));
  1470 +
  1471 + sendPluginChannelMessage("REGISTER", registrationData);
1427 } 1472 }
1428 } 1473 }
1429 } 1474 }
1430 \ No newline at end of file 1475 \ No newline at end of file
java/com/mumfrey/liteloader/core/LiteLoaderLogFormatter.java 0 โ†’ 100644
  1 +package com.mumfrey.liteloader.core;
  2 +
  3 +import java.io.PrintWriter;
  4 +import java.io.StringWriter;
  5 +import java.text.SimpleDateFormat;
  6 +import java.util.logging.Formatter;
  7 +import java.util.logging.Level;
  8 +import java.util.logging.LogRecord;
  9 +
  10 +final class LiteLoaderLogFormatter extends Formatter
  11 +{
  12 + private SimpleDateFormat simpleDateFormatLogFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  13 +
  14 + @Override
  15 + public String format(LogRecord logRecord)
  16 + {
  17 + StringBuilder sb = new StringBuilder();
  18 + sb.append(this.simpleDateFormatLogFormatter.format(Long.valueOf(logRecord.getMillis())));
  19 + Level var3 = logRecord.getLevel();
  20 +
  21 + if (var3 == Level.SEVERE)
  22 + sb.append(" [").append(var3.getLocalizedName()).append("] ");
  23 + else
  24 + sb.append(" [").append(var3.toString().toUpperCase()).append("] ");
  25 +
  26 + sb.append(logRecord.getMessage());
  27 + sb.append('\n');
  28 + Throwable th = logRecord.getThrown();
  29 +
  30 + if (th != null)
  31 + {
  32 + StringWriter var5 = new StringWriter();
  33 + th.printStackTrace(new PrintWriter(var5));
  34 + sb.append(var5.toString());
  35 + }
  36 +
  37 + return sb.toString();
  38 + }
  39 +}
java/com/mumfrey/liteloader/util/ModUtilities.java
1 package com.mumfrey.liteloader.util; 1 package com.mumfrey.liteloader.util;
2 2
3 import java.util.Arrays; 3 import java.util.Arrays;
  4 +import java.util.HashSet;
4 import java.util.LinkedList; 5 import java.util.LinkedList;
5 import java.util.Map; 6 import java.util.Map;
  7 +import java.util.Set;
6 8
7 import com.mumfrey.liteloader.core.LiteLoader; 9 import com.mumfrey.liteloader.core.LiteLoader;
8 10
@@ -11,48 +13,55 @@ import net.minecraft.src.*; @@ -11,48 +13,55 @@ import net.minecraft.src.*;
11 13
12 public abstract class ModUtilities 14 public abstract class ModUtilities
13 { 15 {
14 - /**  
15 - * Add a renderer map entry for the specified entity class  
16 - *  
17 - * @param entityClass  
18 - * @param renderer  
19 - */ 16 + private static Set<Integer> overriddenPackets = new HashSet<Integer>();
  17 +
  18 + /**
  19 + * Add a renderer map entry for the specified entity class
  20 + *
  21 + * @param entityClass
  22 + * @param renderer
  23 + */
20 @SuppressWarnings("unchecked") 24 @SuppressWarnings("unchecked")
21 public static void addRenderer(Class<? extends Entity> entityClass, Render renderer) 25 public static void addRenderer(Class<? extends Entity> entityClass, Render renderer)
22 { 26 {
23 - Map<Class<? extends Entity>, Render> entityRenderMap = PrivateFields.entityRenderMap.Get(RenderManager.instance); 27 + Map<Class<? extends Entity>, Render> entityRenderMap = PrivateFields.entityRenderMap.get(RenderManager.instance);
24 entityRenderMap.put(entityClass, renderer); 28 entityRenderMap.put(entityClass, renderer);
25 renderer.setRenderManager(RenderManager.instance); 29 renderer.setRenderManager(RenderManager.instance);
26 } 30 }
27 -  
28 - /**  
29 - * Register a packet override  
30 - *  
31 - * @param packetId  
32 - * @param newPacket  
33 - */  
34 - @SuppressWarnings("unchecked")  
35 - public static boolean registerPacketOverride(int packetId, Class<? extends Packet> newPacket)  
36 - {  
37 - try  
38 - {  
39 - IntHashMap packetIdToClassMap = Packet.packetIdToClassMap;  
40 - PrivateFields.StaticFields.packetClassToIdMap.Get();  
41 - Map<Class<? extends Packet>, Integer> packetClassToIdMap = PrivateFields.StaticFields.packetClassToIdMap.Get();  
42 -  
43 - packetIdToClassMap.removeObject(packetId);  
44 - packetIdToClassMap.addKey(packetId, newPacket);  
45 - packetClassToIdMap.put(newPacket, Integer.valueOf(packetId));  
46 -  
47 - return true;  
48 - }  
49 - catch (Exception ex)  
50 - {  
51 - LiteLoader.logger.warning("Error registering packet override for packet id " + packetId + ": " + ex.getMessage());  
52 - return false;  
53 - }  
54 - }  
55 - 31 +
  32 + /**
  33 + * Register a packet override
  34 + *
  35 + * @param packetId
  36 + * @param newPacket
  37 + */
  38 + @SuppressWarnings("unchecked")
  39 + public static boolean registerPacketOverride(int packetId, Class<? extends Packet> newPacket)
  40 + {
  41 + if (overriddenPackets.contains(Integer.valueOf(packetId)))
  42 + {
  43 + LiteLoader.getLogger().warning(String.format("Packet with ID %s was already overridden by another mod, one or mods may not function correctly", packetId));
  44 + }
  45 +
  46 + try
  47 + {
  48 + IntHashMap packetIdToClassMap = Packet.packetIdToClassMap;
  49 + PrivateFields.StaticFields.packetClassToIdMap.get();
  50 + Map<Class<? extends Packet>, Integer> packetClassToIdMap = PrivateFields.StaticFields.packetClassToIdMap.get();
  51 +
  52 + packetIdToClassMap.removeObject(packetId);
  53 + packetIdToClassMap.addKey(packetId, newPacket);
  54 + packetClassToIdMap.put(newPacket, Integer.valueOf(packetId));
  55 +
  56 + return true;
  57 + }
  58 + catch (Exception ex)
  59 + {
  60 + LiteLoader.logger.warning("Error registering packet override for packet id " + packetId + ": " + ex.getMessage());
  61 + return false;
  62 + }
  63 + }
  64 +
56 /** 65 /**
57 * Send a plugin channel (custom payload) packet to the server 66 * Send a plugin channel (custom payload) packet to the server
58 * 67 *
@@ -99,17 +108,17 @@ public abstract class ModUtilities @@ -99,17 +108,17 @@ public abstract class ModUtilities
99 108
100 if (mc == null || mc.gameSettings == null) return; 109 if (mc == null || mc.gameSettings == null) return;
101 110
102 - LinkedList<KeyBinding> keyBindings = new LinkedList<KeyBinding>();  
103 - keyBindings.addAll(Arrays.asList(mc.gameSettings.keyBindings));  
104 -  
105 - if (!keyBindings.contains(newBinding))  
106 - {  
107 - keyBindings.add(newBinding);  
108 - mc.gameSettings.keyBindings = keyBindings.toArray(new KeyBinding[0]);  
109 - mc.gameSettings.loadOptions();  
110 - } 111 + LinkedList<KeyBinding> keyBindings = new LinkedList<KeyBinding>();
  112 + keyBindings.addAll(Arrays.asList(mc.gameSettings.keyBindings));
  113 +
  114 + if (!keyBindings.contains(newBinding))
  115 + {
  116 + keyBindings.add(newBinding);
  117 + mc.gameSettings.keyBindings = keyBindings.toArray(new KeyBinding[0]);
  118 + mc.gameSettings.loadOptions();
  119 + }
111 } 120 }
112 - 121 +
113 /** 122 /**
114 * Unregisters a registered keybind with the game settings class, thus removing it from the "controls" screen 123 * Unregisters a registered keybind with the game settings class, thus removing it from the "controls" screen
115 * 124 *
@@ -120,14 +129,14 @@ public abstract class ModUtilities @@ -120,14 +129,14 @@ public abstract class ModUtilities
120 Minecraft mc = Minecraft.getMinecraft(); 129 Minecraft mc = Minecraft.getMinecraft();
121 130
122 if (mc == null || mc.gameSettings == null) return; 131 if (mc == null || mc.gameSettings == null) return;
123 - 132 +
124 LinkedList<KeyBinding> keyBindings = new LinkedList<KeyBinding>(); 133 LinkedList<KeyBinding> keyBindings = new LinkedList<KeyBinding>();
125 - keyBindings.addAll(Arrays.asList(mc.gameSettings.keyBindings));  
126 -  
127 - if (keyBindings.contains(removeBinding))  
128 - {  
129 - keyBindings.remove(removeBinding);  
130 - mc.gameSettings.keyBindings = keyBindings.toArray(new KeyBinding[0]);  
131 - } 134 + keyBindings.addAll(Arrays.asList(mc.gameSettings.keyBindings));
  135 +
  136 + if (keyBindings.contains(removeBinding))
  137 + {
  138 + keyBindings.remove(removeBinding);
  139 + mc.gameSettings.keyBindings = keyBindings.toArray(new KeyBinding[0]);
  140 + }
132 } 141 }
133 } 142 }
java/com/mumfrey/liteloader/util/PrivateFields.java
@@ -15,12 +15,13 @@ import net.minecraft.src.*; @@ -15,12 +15,13 @@ import net.minecraft.src.*;
15 * @param <P> Parent class type, the type of the class that owns the field 15 * @param <P> Parent class type, the type of the class that owns the field
16 * @param <T> Field type, the type of the field value 16 * @param <T> Field type, the type of the field value
17 */ 17 */
  18 +@SuppressWarnings("rawtypes")
18 public class PrivateFields<P, T> 19 public class PrivateFields<P, T>
19 { 20 {
20 /** 21 /**
21 * Class to which this field belongs 22 * Class to which this field belongs
22 */ 23 */
23 - public final Class parentClass; 24 + public final Class<P> parentClass;
24 25
25 /** 26 /**
26 * MCP name for this field 27 * MCP name for this field
@@ -44,7 +45,7 @@ public class PrivateFields&lt;P, T&gt; @@ -44,7 +45,7 @@ public class PrivateFields&lt;P, T&gt;
44 * @param mcpName 45 * @param mcpName
45 * @param name 46 * @param name
46 */ 47 */
47 - private PrivateFields(Class owner, String mcpName, String name) 48 + private PrivateFields(Class<P> owner, String mcpName, String name)
48 { 49 {
49 this.parentClass = owner; 50 this.parentClass = owner;
50 this.mcpName = mcpName; 51 this.mcpName = mcpName;
@@ -60,7 +61,7 @@ public class PrivateFields&lt;P, T&gt; @@ -60,7 +61,7 @@ public class PrivateFields&lt;P, T&gt;
60 * @return field value or null if errors occur 61 * @return field value or null if errors occur
61 */ 62 */
62 @SuppressWarnings("unchecked") 63 @SuppressWarnings("unchecked")
63 - public T Get(P instance) 64 + public T get(P instance)
64 { 65 {
65 try 66 try
66 { 67 {
@@ -81,7 +82,7 @@ public class PrivateFields&lt;P, T&gt; @@ -81,7 +82,7 @@ public class PrivateFields&lt;P, T&gt;
81 * @param value value to set 82 * @param value value to set
82 * @return value 83 * @return value
83 */ 84 */
84 - public T Set(P instance, T value) 85 + public T set(P instance, T value)
85 { 86 {
86 try 87 try
87 { 88 {
@@ -101,7 +102,7 @@ public class PrivateFields&lt;P, T&gt; @@ -101,7 +102,7 @@ public class PrivateFields&lt;P, T&gt;
101 * @param value value to set 102 * @param value value to set
102 * @return value 103 * @return value
103 */ 104 */
104 - public T SetFinal(P instance, T value) 105 + public T setFinal(P instance, T value)
105 { 106 {
106 try 107 try
107 { 108 {
@@ -126,16 +127,16 @@ public class PrivateFields&lt;P, T&gt; @@ -126,16 +127,16 @@ public class PrivateFields&lt;P, T&gt;
126 */ 127 */
127 public static final class StaticFields<P, T> extends PrivateFields<P, T> 128 public static final class StaticFields<P, T> extends PrivateFields<P, T>
128 { 129 {
129 - public StaticFields(Class owner, String mcpName, String name) { super(owner, mcpName, name); }  
130 - public T Get() { return Get(null); }  
131 - public void Set(T value) { Set(null, value); } 130 + public StaticFields(Class<P> owner, String mcpName, String name) { super(owner, mcpName, name); }
  131 + public T get() { return get(null); }
  132 + public void set(T value) { set(null, value); }
132 133
133 public static final StaticFields<Packet, Map> packetClassToIdMap = new StaticFields<Packet, Map> (Packet.class, "packetClassToIdMap", "a"); // Packet/packetClassToIdMap 134 public static final StaticFields<Packet, Map> packetClassToIdMap = new StaticFields<Packet, Map> (Packet.class, "packetClassToIdMap", "a"); // Packet/packetClassToIdMap
134 public static final StaticFields<TileEntity, Map> tileEntityNameToClassMap = new StaticFields<TileEntity, Map> (TileEntity.class, "nameToClassMap", "a"); // TileEntity/nameToClassMap 135 public static final StaticFields<TileEntity, Map> tileEntityNameToClassMap = new StaticFields<TileEntity, Map> (TileEntity.class, "nameToClassMap", "a"); // TileEntity/nameToClassMap
135 } 136 }
136 137
137 - public static final PrivateFields<Minecraft, Timer> minecraftTimer = new PrivateFields<Minecraft, Timer> (Minecraft.class, "timer", "T"); // Minecraft/timer  
138 - public static final PrivateFields<Minecraft, Profiler> minecraftProfiler = new PrivateFields<Minecraft, Profiler> (Minecraft.class, "mcProfiler", "I"); // Minecraft/mcProfiler  
139 - public static final PrivateFields<RenderManager, Map> entityRenderMap = new PrivateFields<RenderManager, Map> (RenderManager.class, "entityRenderMap", "p"); // RenderManager/entityRenderMap 138 + public static final PrivateFields<Minecraft, Timer> minecraftTimer = new PrivateFields<Minecraft, Timer> (Minecraft.class, "timer", "V"); // Minecraft/timer
  139 + public static final PrivateFields<Minecraft, Profiler> minecraftProfiler = new PrivateFields<Minecraft, Profiler> (Minecraft.class, "mcProfiler", "J"); // Minecraft/mcProfiler
  140 + public static final PrivateFields<RenderManager, Map> entityRenderMap = new PrivateFields<RenderManager, Map> (RenderManager.class, "entityRenderMap", "q"); // RenderManager/entityRenderMap
140 } 141 }
141 142
java/net/minecraft/src/CallableJVMFlags.java
@@ -9,14 +9,14 @@ import java.util.concurrent.Callable; @@ -9,14 +9,14 @@ import java.util.concurrent.Callable;
9 import com.mumfrey.liteloader.core.CallableLiteLoaderBrand; 9 import com.mumfrey.liteloader.core.CallableLiteLoaderBrand;
10 import com.mumfrey.liteloader.core.CallableLiteLoaderMods; 10 import com.mumfrey.liteloader.core.CallableLiteLoaderMods;
11 11
12 -class CallableJVMFlags implements Callable 12 +class CallableJVMFlags implements Callable<String>
13 { 13 {
14 - /** Gets additional Java Enviroment info for Crash Report. */  
15 - final CrashReport crashReportJVMFlags; 14 + /** Reference to the CrashReport object. */
  15 + final CrashReport theCrashReport;
16 16
17 CallableJVMFlags(CrashReport par1CrashReport) 17 CallableJVMFlags(CrashReport par1CrashReport)
18 { 18 {
19 - this.crashReportJVMFlags = par1CrashReport; 19 + this.theCrashReport = par1CrashReport;
20 par1CrashReport.func_85056_g().addCrashSectionCallable("Mod Pack", new CallableLiteLoaderBrand(par1CrashReport)); 20 par1CrashReport.func_85056_g().addCrashSectionCallable("Mod Pack", new CallableLiteLoaderBrand(par1CrashReport));
21 par1CrashReport.func_85056_g().addCrashSectionCallable("LiteLoader Mods", new CallableLiteLoaderMods(par1CrashReport)); 21 par1CrashReport.func_85056_g().addCrashSectionCallable("LiteLoader Mods", new CallableLiteLoaderMods(par1CrashReport));
22 } 22 }
@@ -27,14 +27,14 @@ class CallableJVMFlags implements Callable @@ -27,14 +27,14 @@ class CallableJVMFlags implements Callable
27 public String getJVMFlagsAsString() 27 public String getJVMFlagsAsString()
28 { 28 {
29 RuntimeMXBean var1 = ManagementFactory.getRuntimeMXBean(); 29 RuntimeMXBean var1 = ManagementFactory.getRuntimeMXBean();
30 - List var2 = var1.getInputArguments(); 30 + List<String> var2 = var1.getInputArguments();
31 int var3 = 0; 31 int var3 = 0;
32 StringBuilder var4 = new StringBuilder(); 32 StringBuilder var4 = new StringBuilder();
33 - Iterator var5 = var2.iterator(); 33 + Iterator<String> var5 = var2.iterator();
34 34
35 while (var5.hasNext()) 35 while (var5.hasNext())
36 { 36 {
37 - String var6 = (String)var5.next(); 37 + String var6 = var5.next();
38 38
39 if (var6.startsWith("-X")) 39 if (var6.startsWith("-X"))
40 { 40 {
@@ -51,7 +51,7 @@ class CallableJVMFlags implements Callable @@ -51,7 +51,7 @@ class CallableJVMFlags implements Callable
51 } 51 }
52 52
53 @Override 53 @Override
54 - public Object call() 54 + public String call()
55 { 55 {
56 return this.getJVMFlagsAsString(); 56 return this.getJVMFlagsAsString();
57 } 57 }
java/net/minecraft/src/RenderLightningBolt.java
1 package net.minecraft.src; 1 package net.minecraft.src;
2 2
3 import java.util.Random; 3 import java.util.Random;
4 -  
5 import org.lwjgl.opengl.GL11; 4 import org.lwjgl.opengl.GL11;
6 5
7 import com.mumfrey.liteloader.core.LiteLoader; 6 import com.mumfrey.liteloader.core.LiteLoader;
@@ -13,11 +12,12 @@ public class RenderLightningBolt extends Render @@ -13,11 +12,12 @@ public class RenderLightningBolt extends Render
13 // LiteLoader init 12 // LiteLoader init
14 LiteLoader.getInstance(); 13 LiteLoader.getInstance();
15 } 14 }
16 -  
17 - /** 15 +
  16 + /**
18 * Actually renders the lightning bolt. This method is called through the doRender method. 17 * Actually renders the lightning bolt. This method is called through the doRender method.
19 */ 18 */
20 - public void doRenderLightningBolt(EntityLightningBolt par1EntityLightningBolt, double par2, double par4, double par6, float par8, float par9) 19 + @SuppressWarnings("cast")
  20 + public void doRenderLightningBolt(EntityLightningBolt par1EntityLightningBolt, double par2, double par4, double par6, float par8, float par9)
21 { 21 {
22 Tessellator var10 = Tessellator.instance; 22 Tessellator var10 = Tessellator.instance;
23 GL11.glDisable(GL11.GL_TEXTURE_2D); 23 GL11.glDisable(GL11.GL_TEXTURE_2D);
res/liteloader.properties
@@ -2,5 +2,5 @@ search.mods=true @@ -2,5 +2,5 @@ search.mods=true
2 search.jar=true 2 search.jar=true
3 search.classpath=true 3 search.classpath=true
4 log=stderr 4 log=stderr
5 - 5 +brand=The Voxel Modpack
6 6