Commit c4b6db986fc5843633653e90b42cdb837e38f7b8
1 parent
c92c91ea
Liteloader 1.4.4
Showing
10 changed files
with
324 additions
and
92 deletions
.classpath
| ... | ... | @@ -2,23 +2,12 @@ |
| 2 | 2 | <classpath> |
| 3 | 3 | <classpathentry kind="src" path="java"/> |
| 4 | 4 | <classpathentry kind="src" path="res"/> |
| 5 | + <classpathentry combineaccessrules="false" kind="src" path="/ClientMods"/> | |
| 5 | 6 | <classpathentry combineaccessrules="false" kind="src" path="/Client"/> |
| 6 | 7 | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre6"/> |
| 7 | - <classpathentry kind="lib" path="jars/bin/jinput.jar"> | |
| 8 | - <attributes> | |
| 9 | - <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="LiteLoader/jars/bin/natives"/> | |
| 10 | - </attributes> | |
| 11 | - </classpathentry> | |
| 12 | - <classpathentry kind="lib" path="jars/bin/lwjgl_util.jar"> | |
| 13 | - <attributes> | |
| 14 | - <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="LiteLoader/jars/bin/natives"/> | |
| 15 | - </attributes> | |
| 16 | - </classpathentry> | |
| 17 | - <classpathentry kind="lib" path="jars/bin/lwjgl.jar"> | |
| 18 | - <attributes> | |
| 19 | - <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="LiteLoader/jars/bin/natives"/> | |
| 20 | - </attributes> | |
| 21 | - </classpathentry> | |
| 22 | - <classpathentry kind="lib" path="jars/bin/minecraft.jar"/> | |
| 8 | + <classpathentry kind="lib" path="/Client/jars/bin/jinput.jar"/> | |
| 9 | + <classpathentry kind="lib" path="/Client/jars/bin/lwjgl_util.jar"/> | |
| 10 | + <classpathentry kind="lib" path="/Client/jars/bin/lwjgl.jar"/> | |
| 11 | + <classpathentry kind="lib" path="/Client/jars/bin/minecraft.jar"/> | |
| 23 | 12 | <classpathentry kind="output" path="bin"/> |
| 24 | 13 | </classpath> | ... | ... |
.project
| ... | ... | @@ -14,13 +14,6 @@ |
| 14 | 14 | <natures> |
| 15 | 15 | <nature>org.eclipse.jdt.core.javanature</nature> |
| 16 | 16 | </natures> |
| 17 | - <linkedResources> | |
| 18 | - <link> | |
| 19 | - <name>jars</name> | |
| 20 | - <type>2</type> | |
| 21 | - <locationURI>MCP_LOC/jars</locationURI> | |
| 22 | - </link> | |
| 23 | - </linkedResources> | |
| 24 | 17 | <variableList> |
| 25 | 18 | <variable> |
| 26 | 19 | <name>MCP_LOC</name> | ... | ... |
java/com/mumfrey/liteloader/PreLoginListener.java
0 → 100644
| 1 | +package com.mumfrey.liteloader; | |
| 2 | + | |
| 3 | +import net.minecraft.src.NetHandler; | |
| 4 | +import net.minecraft.src.Packet1Login; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Interface for mods which wish to be notified when the player connects to a server (or local game) | |
| 8 | + * | |
| 9 | + * @author Adam Mummery-Smith | |
| 10 | + */ | |
| 11 | +public interface PreLoginListener extends LiteMod | |
| 12 | +{ | |
| 13 | + /** | |
| 14 | + * Called on login | |
| 15 | + * | |
| 16 | + * @param netHandler Net handler | |
| 17 | + * @param loginPacket Login packet | |
| 18 | + */ | |
| 19 | + public abstract boolean onPreLogin(NetHandler netHandler, Packet1Login loginPacket); | |
| 20 | +} | ... | ... |
java/com/mumfrey/liteloader/RenderListener.java
0 → 100644
| 1 | +package com.mumfrey.liteloader; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Interface for objects which want a pre-render callback | |
| 5 | + * | |
| 6 | + * @author Adam Mummery-Smith | |
| 7 | + */ | |
| 8 | +public interface RenderListener extends LiteMod | |
| 9 | +{ | |
| 10 | + /** | |
| 11 | + * Callback when a frame is rendered | |
| 12 | + */ | |
| 13 | + public abstract void onRender(); | |
| 14 | + | |
| 15 | + public abstract void onRenderWorld(); | |
| 16 | +} | ... | ... |
java/com/mumfrey/liteloader/core/HookLogin.java
| ... | ... | @@ -25,8 +25,11 @@ public class HookLogin extends Packet1Login |
| 25 | 25 | @Override |
| 26 | 26 | public void processPacket(NetHandler par1NetHandler) |
| 27 | 27 | { |
| 28 | - super.processPacket(par1NetHandler); | |
| 29 | - | |
| 30 | - if (loader != null) loader.onConnectToServer(par1NetHandler, this); | |
| 28 | + if (loader == null || loader.onPreLogin(par1NetHandler, this)) | |
| 29 | + { | |
| 30 | + super.processPacket(par1NetHandler); | |
| 31 | + | |
| 32 | + if (loader != null) loader.onConnectToServer(par1NetHandler, this); | |
| 33 | + } | |
| 31 | 34 | } |
| 32 | 35 | } | ... | ... |
java/com/mumfrey/liteloader/core/LiteLoaderHook.java renamed to java/com/mumfrey/liteloader/core/HookProfiler.java
| ... | ... | @@ -14,7 +14,7 @@ import net.minecraft.src.Profiler; |
| 14 | 14 | * |
| 15 | 15 | * @author Adam Mummery-Smith |
| 16 | 16 | */ |
| 17 | -public class LiteLoaderHook extends Profiler | |
| 17 | +public class HookProfiler extends Profiler | |
| 18 | 18 | { |
| 19 | 19 | /** |
| 20 | 20 | * Logger instance |
| ... | ... | @@ -24,12 +24,12 @@ public class LiteLoaderHook extends Profiler |
| 24 | 24 | /** |
| 25 | 25 | * LiteLoader instance which will receive callbacks |
| 26 | 26 | */ |
| 27 | - private LiteLoader core; | |
| 27 | + private LiteLoader loader; | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Section list, used as a kind of stack to determine where we are in the profiler stack |
| 31 | 31 | */ |
| 32 | - private LinkedList<String> sections = new LinkedList<String>(); | |
| 32 | + private LinkedList<String> sectionStack = new LinkedList<String>(); | |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Initialisation done |
| ... | ... | @@ -57,9 +57,9 @@ public class LiteLoaderHook extends Profiler |
| 57 | 57 | * @param core LiteLoader object which will get callbacks |
| 58 | 58 | * @param logger Logger instance |
| 59 | 59 | */ |
| 60 | - public LiteLoaderHook(LiteLoader core, Logger logger) | |
| 60 | + public HookProfiler(LiteLoader core, Logger logger) | |
| 61 | 61 | { |
| 62 | - this.core = core; | |
| 62 | + this.loader = core; | |
| 63 | 63 | this.logger = logger; |
| 64 | 64 | |
| 65 | 65 | // Detect optifine (duh!) |
| ... | ... | @@ -128,13 +128,18 @@ public class LiteLoaderHook extends Profiler |
| 128 | 128 | if (!initDone) |
| 129 | 129 | { |
| 130 | 130 | initDone = true; |
| 131 | - core.onInit(); | |
| 131 | + loader.onInit(); | |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if (sectionName.equals("animateTick")) tick = true; | |
| 135 | - sections.add(sectionName); | |
| 134 | + if ("gameRenderer".equalsIgnoreCase(sectionName) && "root".equalsIgnoreCase(sectionStack.getLast())) | |
| 135 | + { | |
| 136 | + loader.onRender(); | |
| 137 | + } | |
| 138 | + | |
| 139 | + if ("animateTick".equals(sectionName)) tick = true; | |
| 140 | + sectionStack.add(sectionName); | |
| 136 | 141 | super.startSection(sectionName); |
| 137 | - | |
| 142 | + | |
| 138 | 143 | if (ofProfiler != null) |
| 139 | 144 | { |
| 140 | 145 | try |
| ... | ... | @@ -160,13 +165,13 @@ public class LiteLoaderHook extends Profiler |
| 160 | 165 | { |
| 161 | 166 | super.endSection(); |
| 162 | 167 | |
| 163 | - String endingSection = sections.removeLast(); | |
| 168 | + String endingSection = sectionStack.removeLast(); | |
| 164 | 169 | |
| 165 | - if (endingSection.equalsIgnoreCase("gameRenderer") && sections.getLast().equalsIgnoreCase("root")) | |
| 170 | + if ("gameRenderer".equalsIgnoreCase(endingSection) && "root".equalsIgnoreCase(sectionStack.getLast())) | |
| 166 | 171 | { |
| 167 | 172 | super.startSection("litetick"); |
| 168 | 173 | |
| 169 | - core.onTick(tick); | |
| 174 | + loader.onTick(this, tick); | |
| 170 | 175 | tick = false; |
| 171 | 176 | |
| 172 | 177 | super.endSection(); | ... | ... |
java/com/mumfrey/liteloader/core/LiteLoader.java
| ... | ... | @@ -28,26 +28,27 @@ import net.minecraft.src.Timer; |
| 28 | 28 | * LiteLoader is a simple loader which provides tick events to loaded mods |
| 29 | 29 | * |
| 30 | 30 | * @author Adam Mummery-Smith |
| 31 | - * @version 1.4.0 | |
| 31 | + * @version 1.4.4 | |
| 32 | 32 | */ |
| 33 | +@SuppressWarnings("rawtypes") | |
| 33 | 34 | public final class LiteLoader implements FilenameFilter |
| 34 | 35 | { |
| 35 | 36 | /** |
| 36 | 37 | * Liteloader version |
| 37 | 38 | */ |
| 38 | - private static final String LOADER_VERSION = "1.4.0"; | |
| 39 | + private static final String LOADER_VERSION = "1.4.4"; | |
| 39 | 40 | |
| 40 | 41 | /** |
| 41 | 42 | * Loader revision, can be used by mods to determine whether the loader is sufficiently up-to-date |
| 42 | 43 | */ |
| 43 | - private static final int LOADER_REVISION = 4; | |
| 44 | + private static final int LOADER_REVISION = 6; | |
| 44 | 45 | |
| 45 | 46 | /** |
| 46 | 47 | * Minecraft versions that we will load mods for, this will be compared |
| 47 | 48 | * against the version.txt value in mod files to prevent outdated mods being |
| 48 | 49 | * loaded!!! |
| 49 | 50 | */ |
| 50 | - private static final String[] SUPPORTED_VERSIONS = { "1.4.0", "1.4" }; | |
| 51 | + private static final String[] SUPPORTED_VERSIONS = { "1.4.4" }; | |
| 51 | 52 | |
| 52 | 53 | /** |
| 53 | 54 | * LiteLoader is a singleton, this is the singleton instance |
| ... | ... | @@ -96,6 +97,12 @@ public final class LiteLoader implements FilenameFilter |
| 96 | 97 | private LinkedList<InitCompleteListener> initListeners = new LinkedList<InitCompleteListener>(); |
| 97 | 98 | |
| 98 | 99 | /** |
| 100 | + * List of mods which implement RenderListener interface and will receive render events | |
| 101 | + * events | |
| 102 | + */ | |
| 103 | + private LinkedList<RenderListener> renderListeners = new LinkedList<RenderListener>(); | |
| 104 | + | |
| 105 | + /** | |
| 99 | 106 | * List of mods which implement ChatListener interface and will receive chat |
| 100 | 107 | * events |
| 101 | 108 | */ |
| ... | ... | @@ -113,6 +120,11 @@ public final class LiteLoader implements FilenameFilter |
| 113 | 120 | private LinkedList<LoginListener> loginListeners = new LinkedList<LoginListener>(); |
| 114 | 121 | |
| 115 | 122 | /** |
| 123 | + * List of mods which implement LoginListener interface and will receive client login events | |
| 124 | + */ | |
| 125 | + private LinkedList<PreLoginListener> preLoginListeners = new LinkedList<PreLoginListener>(); | |
| 126 | + | |
| 127 | + /** | |
| 116 | 128 | * List of mods which implement PluginChannelListener interface |
| 117 | 129 | */ |
| 118 | 130 | private LinkedList<PluginChannelListener> pluginChannelListeners = new LinkedList<PluginChannelListener>(); |
| ... | ... | @@ -127,7 +139,12 @@ public final class LiteLoader implements FilenameFilter |
| 127 | 139 | */ |
| 128 | 140 | private Method mAddUrl; |
| 129 | 141 | |
| 130 | - private boolean initDone = false; | |
| 142 | + /** | |
| 143 | + * Flag which keeps track of whether late initialisation has been done | |
| 144 | + */ | |
| 145 | + private boolean loaderStartupDone, loaderStartupComplete, lateInitDone; | |
| 146 | + | |
| 147 | + private boolean chatHooked, loginHooked, pluginChannelHooked, tickHooked; | |
| 131 | 148 | |
| 132 | 149 | /** |
| 133 | 150 | * Get the singleton instance of LiteLoader, initialises the loader if necessary |
| ... | ... | @@ -138,7 +155,10 @@ public final class LiteLoader implements FilenameFilter |
| 138 | 155 | { |
| 139 | 156 | if (instance == null) |
| 140 | 157 | { |
| 158 | + // Return immediately to stop calls to getInstance causing re-init if they arrive | |
| 159 | + // before init is completed | |
| 141 | 160 | instance = new LiteLoader(); |
| 161 | + instance.initLoader(); | |
| 142 | 162 | } |
| 143 | 163 | |
| 144 | 164 | return instance; |
| ... | ... | @@ -179,26 +199,37 @@ public final class LiteLoader implements FilenameFilter |
| 179 | 199 | */ |
| 180 | 200 | private LiteLoader() |
| 181 | 201 | { |
| 202 | + } | |
| 203 | + | |
| 204 | + private void initLoader() | |
| 205 | + { | |
| 206 | + if (loaderStartupDone) return; | |
| 207 | + loaderStartupDone = true; | |
| 208 | + | |
| 182 | 209 | // Set up base class overrides |
| 183 | 210 | prepareClassOverrides(); |
| 184 | 211 | |
| 185 | 212 | // Set up loader, initialises any reflection methods needed |
| 186 | - prepareLoader(); | |
| 187 | - | |
| 188 | - logger.info("Liteloader " + LOADER_VERSION + " starting up..."); | |
| 189 | - | |
| 190 | - // Examines the class path and mods folder and locates loadable mods | |
| 191 | - prepareMods(); | |
| 192 | - | |
| 193 | - // Initialises enumerated mods | |
| 194 | - initMods(); | |
| 195 | - | |
| 196 | - // Initialises the required hooks for loaded mods | |
| 197 | - initHooks(); | |
| 213 | + if (prepareLoader()) | |
| 214 | + { | |
| 215 | + logger.info("LiteLoader " + LOADER_VERSION + " starting up..."); | |
| 216 | + logger.info(String.format("Java reports OS=\"%s\"", System.getProperty("os.name").toLowerCase())); | |
| 217 | + | |
| 218 | + // Examines the class path and mods folder and locates loadable mods | |
| 219 | + prepareMods(); | |
| 220 | + | |
| 221 | + // Initialises enumerated mods | |
| 222 | + initMods(); | |
| 223 | + | |
| 224 | + // Initialises the required hooks for loaded mods | |
| 225 | + initHooks(); | |
| 226 | + | |
| 227 | + loaderStartupComplete = true; | |
| 228 | + } | |
| 198 | 229 | } |
| 199 | 230 | |
| 200 | 231 | /** |
| 201 | - * | |
| 232 | + * Do dirty non-base-clean overrides | |
| 202 | 233 | */ |
| 203 | 234 | private void prepareClassOverrides() |
| 204 | 235 | { |
| ... | ... | @@ -233,13 +264,18 @@ public final class LiteLoader implements FilenameFilter |
| 233 | 264 | |
| 234 | 265 | outputStream.close(); |
| 235 | 266 | resourceInputStream.close(); |
| 236 | - | |
| 267 | + | |
| 268 | + logger.info("Defining class override for " + binaryClassName); | |
| 237 | 269 | mDefineClass.invoke(Minecraft.class.getClassLoader(), binaryClassName, data, 0, data.length); |
| 238 | 270 | } |
| 271 | + else | |
| 272 | + { | |
| 273 | + logger.info("Error defining class override for " + binaryClassName + ", file not found"); | |
| 274 | + } | |
| 239 | 275 | } |
| 240 | 276 | catch (Throwable th) |
| 241 | 277 | { |
| 242 | - th.printStackTrace(); | |
| 278 | + logger.log(Level.WARNING, "Error defining class override for " + binaryClassName, th); | |
| 243 | 279 | } |
| 244 | 280 | } |
| 245 | 281 | |
| ... | ... | @@ -247,7 +283,7 @@ public final class LiteLoader implements FilenameFilter |
| 247 | 283 | * Set up reflection methods required by the loader |
| 248 | 284 | */ |
| 249 | 285 | @SuppressWarnings("unchecked") |
| 250 | - private void prepareLoader() | |
| 286 | + private boolean prepareLoader() | |
| 251 | 287 | { |
| 252 | 288 | try |
| 253 | 289 | { |
| ... | ... | @@ -279,12 +315,14 @@ public final class LiteLoader implements FilenameFilter |
| 279 | 315 | FileHandler logFileHandler = new FileHandler(new File(Minecraft.getMinecraftDir(), "LiteLoader.txt").getAbsolutePath()); |
| 280 | 316 | if (minecraftLogFormatter != null) logFileHandler.setFormatter(minecraftLogFormatter); |
| 281 | 317 | logger.addHandler(logFileHandler); |
| 282 | - | |
| 283 | 318 | } |
| 284 | - catch (Exception ex) | |
| 319 | + catch (Throwable th) | |
| 285 | 320 | { |
| 286 | - logger.log(Level.SEVERE, "Error initialising LiteLoader", ex); | |
| 321 | + logger.log(Level.SEVERE, "Error initialising LiteLoader", th); | |
| 322 | + return false; | |
| 287 | 323 | } |
| 324 | + | |
| 325 | + return true; | |
| 288 | 326 | } |
| 289 | 327 | |
| 290 | 328 | /** |
| ... | ... | @@ -341,16 +379,25 @@ public final class LiteLoader implements FilenameFilter |
| 341 | 379 | HashMap<String, Class> modsToLoad = null; |
| 342 | 380 | try |
| 343 | 381 | { |
| 344 | - logger.info("Loading mods from class path"); | |
| 345 | - | |
| 382 | + logger.info("Enumerating class path..."); | |
| 383 | + | |
| 384 | + String classPath = System.getProperty("java.class.path"); | |
| 346 | 385 | String classPathSeparator = System.getProperty("path.separator"); |
| 347 | - String[] classPathEntries = System.getProperty("java.class.path").split(classPathSeparator); | |
| 386 | + String[] classPathEntries = classPath.split(classPathSeparator); | |
| 387 | + | |
| 388 | + logger.info(String.format("Class path separator=\"%s\"", classPathSeparator)); | |
| 389 | + logger.info(String.format("Class path entries=(\n classpathEntry=%s\n)", classPath.replace(classPathSeparator, "\n classpathEntry="))); | |
| 390 | + | |
| 391 | + logger.info("Loading mods from class path..."); | |
| 392 | + | |
| 348 | 393 | modsToLoad = findModClasses(classPathEntries, modFiles); |
| 394 | + | |
| 395 | + logger.info("Mod class discovery completed"); | |
| 349 | 396 | } |
| 350 | - catch (Exception ex) | |
| 397 | + catch (Throwable th) | |
| 351 | 398 | { |
| 352 | - // TODO Auto-generated catch block | |
| 353 | - ex.printStackTrace(); | |
| 399 | + logger.log(Level.WARNING, "Mod class discovery failed", th); | |
| 400 | + return; | |
| 354 | 401 | } |
| 355 | 402 | |
| 356 | 403 | loadMods(modsToLoad); |
| ... | ... | @@ -421,14 +468,17 @@ public final class LiteLoader implements FilenameFilter |
| 421 | 468 | |
| 422 | 469 | try |
| 423 | 470 | { |
| 471 | + logger.info("Searching protection domain code source..."); | |
| 472 | + | |
| 424 | 473 | File packagePath = new File(LiteLoader.class.getProtectionDomain().getCodeSource().getLocation().toURI()); |
| 425 | - | |
| 426 | 474 | LinkedList<Class> modClasses = getSubclassesFor(packagePath, Minecraft.class.getClassLoader(), LiteMod.class, "LiteMod"); |
| 427 | 475 | |
| 428 | 476 | for (Class mod : modClasses) |
| 429 | 477 | { |
| 430 | 478 | modsToLoad.put(mod.getSimpleName(), mod); |
| 431 | 479 | } |
| 480 | + | |
| 481 | + if (modClasses.size() > 0) logger.info(String.format("Found %s potential matches", modClasses.size())); | |
| 432 | 482 | } |
| 433 | 483 | catch (Throwable th) |
| 434 | 484 | { |
| ... | ... | @@ -438,6 +488,8 @@ public final class LiteLoader implements FilenameFilter |
| 438 | 488 | // Search through the class path and find mod classes |
| 439 | 489 | for (String classPathPart : classPathEntries) |
| 440 | 490 | { |
| 491 | + logger.info(String.format("Searching %s...", classPathPart)); | |
| 492 | + | |
| 441 | 493 | File packagePath = new File(classPathPart); |
| 442 | 494 | LinkedList<Class> modClasses = getSubclassesFor(packagePath, Minecraft.class.getClassLoader(), LiteMod.class, "LiteMod"); |
| 443 | 495 | |
| ... | ... | @@ -445,17 +497,23 @@ public final class LiteLoader implements FilenameFilter |
| 445 | 497 | { |
| 446 | 498 | modsToLoad.put(mod.getSimpleName(), mod); |
| 447 | 499 | } |
| 500 | + | |
| 501 | + if (modClasses.size() > 0) logger.info(String.format("Found %s potential matches", modClasses.size())); | |
| 448 | 502 | } |
| 449 | 503 | |
| 450 | 504 | // Search through mod files and find mod classes |
| 451 | 505 | for (File modFile : modFiles) |
| 452 | 506 | { |
| 507 | + logger.info(String.format("Searching %s...", modFile.getAbsolutePath())); | |
| 508 | + | |
| 453 | 509 | LinkedList<Class> modClasses = getSubclassesFor(modFile, Minecraft.class.getClassLoader(), LiteMod.class, "LiteMod"); |
| 454 | 510 | |
| 455 | 511 | for (Class mod : modClasses) |
| 456 | 512 | { |
| 457 | 513 | modsToLoad.put(mod.getSimpleName(), mod); |
| 458 | 514 | } |
| 515 | + | |
| 516 | + if (modClasses.size() > 0) logger.info(String.format("Found %s potential matches", modClasses.size())); | |
| 459 | 517 | } |
| 460 | 518 | |
| 461 | 519 | return modsToLoad; |
| ... | ... | @@ -468,7 +526,11 @@ public final class LiteLoader implements FilenameFilter |
| 468 | 526 | */ |
| 469 | 527 | private void loadMods(HashMap<String, Class> modsToLoad) |
| 470 | 528 | { |
| 471 | - if (modsToLoad == null) return; | |
| 529 | + if (modsToLoad == null) | |
| 530 | + { | |
| 531 | + logger.info("Mod class discovery failed. Not loading any mods!"); | |
| 532 | + return; | |
| 533 | + } | |
| 472 | 534 | |
| 473 | 535 | logger.info("Discovered " + modsToLoad.size() + " total mod(s)"); |
| 474 | 536 | |
| ... | ... | @@ -511,32 +573,42 @@ public final class LiteLoader implements FilenameFilter |
| 511 | 573 | |
| 512 | 574 | if (mod instanceof Tickable) |
| 513 | 575 | { |
| 514 | - tickListeners.add((Tickable)mod); | |
| 576 | + addTickListener((Tickable)mod); | |
| 515 | 577 | } |
| 516 | 578 | |
| 517 | 579 | if (mod instanceof InitCompleteListener) |
| 518 | 580 | { |
| 519 | - initListeners.add((InitCompleteListener)mod); | |
| 581 | + addInitListener((InitCompleteListener)mod); | |
| 582 | + } | |
| 583 | + | |
| 584 | + if (mod instanceof RenderListener) | |
| 585 | + { | |
| 586 | + addRenderListener((RenderListener)mod); | |
| 520 | 587 | } |
| 521 | 588 | |
| 522 | 589 | if (mod instanceof ChatFilter) |
| 523 | 590 | { |
| 524 | - chatFilters.add((ChatFilter)mod); | |
| 591 | + addChatFilter((ChatFilter)mod); | |
| 525 | 592 | } |
| 526 | 593 | |
| 527 | 594 | if (mod instanceof ChatListener && !(mod instanceof ChatFilter)) |
| 528 | 595 | { |
| 529 | - chatListeners.add((ChatListener)mod); | |
| 596 | + addChatListener((ChatListener)mod); | |
| 597 | + } | |
| 598 | + | |
| 599 | + if (mod instanceof PreLoginListener) | |
| 600 | + { | |
| 601 | + addPreLoginListener((PreLoginListener)mod); | |
| 530 | 602 | } |
| 531 | 603 | |
| 532 | 604 | if (mod instanceof LoginListener) |
| 533 | 605 | { |
| 534 | - loginListeners.add((LoginListener)mod); | |
| 606 | + addLoginListener((LoginListener)mod); | |
| 535 | 607 | } |
| 536 | 608 | |
| 537 | 609 | if (mod instanceof PluginChannelListener) |
| 538 | 610 | { |
| 539 | - pluginChannelListeners.add((PluginChannelListener)mod); | |
| 611 | + addPluginChannelListener((PluginChannelListener)mod); | |
| 540 | 612 | } |
| 541 | 613 | |
| 542 | 614 | loadedModsList += String.format("\n - %s version %s", mod.getName(), mod.getVersion()); |
| ... | ... | @@ -551,7 +623,7 @@ public final class LiteLoader implements FilenameFilter |
| 551 | 623 | |
| 552 | 624 | loadedModsList = String.format("%s loaded mod(s)%s", loadedModsCount, loadedModsList); |
| 553 | 625 | } |
| 554 | - | |
| 626 | + | |
| 555 | 627 | /** |
| 556 | 628 | * Initialise mod hooks |
| 557 | 629 | */ |
| ... | ... | @@ -560,28 +632,35 @@ public final class LiteLoader implements FilenameFilter |
| 560 | 632 | try |
| 561 | 633 | { |
| 562 | 634 | // Chat hook |
| 563 | - if (chatListeners.size() > 0 || chatFilters.size() > 0) | |
| 635 | + if ((chatListeners.size() > 0 || chatFilters.size() > 0) && !chatHooked) | |
| 564 | 636 | { |
| 637 | + chatHooked = true; | |
| 565 | 638 | HookChat.Register(); |
| 566 | 639 | HookChat.RegisterPacketHandler(this); |
| 567 | 640 | } |
| 568 | 641 | |
| 569 | 642 | // Login hook |
| 570 | - if (loginListeners.size() > 0) | |
| 643 | + if ((preLoginListeners.size() > 0 || loginListeners.size() > 0) && !loginHooked) | |
| 571 | 644 | { |
| 645 | + loginHooked = true; | |
| 572 | 646 | ModUtilities.registerPacketOverride(1, HookLogin.class); |
| 573 | 647 | HookLogin.loader = this; |
| 574 | 648 | } |
| 575 | 649 | |
| 576 | 650 | // Plugin channels hook |
| 577 | - if (pluginChannelListeners.size() > 0) | |
| 651 | + if (pluginChannelListeners.size() > 0 && !pluginChannelHooked) | |
| 578 | 652 | { |
| 653 | + pluginChannelHooked = true; | |
| 579 | 654 | HookPluginChannels.Register(); |
| 580 | 655 | HookPluginChannels.RegisterPacketHandler(this); |
| 581 | 656 | } |
| 582 | 657 | |
| 583 | 658 | // Tick hook |
| 584 | - PrivateFields.minecraftProfiler.SetFinal(minecraft, new LiteLoaderHook(this, logger)); | |
| 659 | + if (!tickHooked) | |
| 660 | + { | |
| 661 | + tickHooked = true; | |
| 662 | + PrivateFields.minecraftProfiler.SetFinal(minecraft, new HookProfiler(this, logger)); | |
| 663 | + } | |
| 585 | 664 | } |
| 586 | 665 | catch (Exception ex) |
| 587 | 666 | { |
| ... | ... | @@ -591,6 +670,102 @@ public final class LiteLoader implements FilenameFilter |
| 591 | 670 | } |
| 592 | 671 | |
| 593 | 672 | /** |
| 673 | + * @param tickable | |
| 674 | + */ | |
| 675 | + public void addTickListener(Tickable tickable) | |
| 676 | + { | |
| 677 | + if (!tickListeners.contains(tickable)) | |
| 678 | + { | |
| 679 | + tickListeners.add(tickable); | |
| 680 | + if (loaderStartupComplete) initHooks(); | |
| 681 | + } | |
| 682 | + } | |
| 683 | + | |
| 684 | + /** | |
| 685 | + * @param initCompleteListener | |
| 686 | + */ | |
| 687 | + public void addInitListener(InitCompleteListener initCompleteListener) | |
| 688 | + { | |
| 689 | + if (!initListeners.contains(initCompleteListener)) | |
| 690 | + { | |
| 691 | + initListeners.add(initCompleteListener); | |
| 692 | + if (loaderStartupComplete) initHooks(); | |
| 693 | + } | |
| 694 | + } | |
| 695 | + | |
| 696 | + /** | |
| 697 | + * @param tickable | |
| 698 | + */ | |
| 699 | + public void addRenderListener(RenderListener tickable) | |
| 700 | + { | |
| 701 | + if (!renderListeners.contains(tickable)) | |
| 702 | + { | |
| 703 | + renderListeners.add(tickable); | |
| 704 | + if (loaderStartupComplete) initHooks(); | |
| 705 | + } | |
| 706 | + } | |
| 707 | + | |
| 708 | + /** | |
| 709 | + * @param chatFilter | |
| 710 | + */ | |
| 711 | + public void addChatFilter(ChatFilter chatFilter) | |
| 712 | + { | |
| 713 | + if (!chatFilters.contains(chatFilter)) | |
| 714 | + { | |
| 715 | + chatFilters.add(chatFilter); | |
| 716 | + if (loaderStartupComplete) initHooks(); | |
| 717 | + } | |
| 718 | + } | |
| 719 | + | |
| 720 | + /** | |
| 721 | + * @param chatListener | |
| 722 | + */ | |
| 723 | + public void addChatListener(ChatListener chatListener) | |
| 724 | + { | |
| 725 | + if (!chatListeners.contains(chatListener)) | |
| 726 | + { | |
| 727 | + chatListeners.add(chatListener); | |
| 728 | + if (loaderStartupComplete) initHooks(); | |
| 729 | + } | |
| 730 | + } | |
| 731 | + | |
| 732 | + /** | |
| 733 | + * @param loginListener | |
| 734 | + */ | |
| 735 | + public void addPreLoginListener(PreLoginListener loginListener) | |
| 736 | + { | |
| 737 | + if (!preLoginListeners.contains(loginListener)) | |
| 738 | + { | |
| 739 | + preLoginListeners.add(loginListener); | |
| 740 | + if (loaderStartupComplete) initHooks(); | |
| 741 | + } | |
| 742 | + } | |
| 743 | + | |
| 744 | + /** | |
| 745 | + * @param loginListener | |
| 746 | + */ | |
| 747 | + public void addLoginListener(LoginListener loginListener) | |
| 748 | + { | |
| 749 | + if (!loginListeners.contains(loginListener)) | |
| 750 | + { | |
| 751 | + loginListeners.add(loginListener); | |
| 752 | + if (loaderStartupComplete) initHooks(); | |
| 753 | + } | |
| 754 | + } | |
| 755 | + | |
| 756 | + /** | |
| 757 | + * @param pluginChannelListener | |
| 758 | + */ | |
| 759 | + public void addPluginChannelListener(PluginChannelListener pluginChannelListener) | |
| 760 | + { | |
| 761 | + if (!pluginChannelListeners.contains(pluginChannelListener)) | |
| 762 | + { | |
| 763 | + pluginChannelListeners.add(pluginChannelListener); | |
| 764 | + if (loaderStartupComplete) initHooks(); | |
| 765 | + } | |
| 766 | + } | |
| 767 | + | |
| 768 | + /** | |
| 594 | 769 | * Enumerate classes on the classpath which are subclasses of the specified |
| 595 | 770 | * class |
| 596 | 771 | * |
| ... | ... | @@ -762,9 +937,9 @@ public final class LiteLoader implements FilenameFilter |
| 762 | 937 | */ |
| 763 | 938 | public void onInit() |
| 764 | 939 | { |
| 765 | - if (!initDone) | |
| 940 | + if (!lateInitDone) | |
| 766 | 941 | { |
| 767 | - initDone = true; | |
| 942 | + lateInitDone = true; | |
| 768 | 943 | |
| 769 | 944 | for (InitCompleteListener initMod : initListeners) |
| 770 | 945 | { |
| ... | ... | @@ -780,13 +955,22 @@ public final class LiteLoader implements FilenameFilter |
| 780 | 955 | } |
| 781 | 956 | } |
| 782 | 957 | } |
| 958 | + | |
| 959 | + /** | |
| 960 | + * Callback from the tick hook, pre render | |
| 961 | + */ | |
| 962 | + public void onRender() | |
| 963 | + { | |
| 964 | + for (RenderListener renderListener : renderListeners) | |
| 965 | + renderListener.onRender(); | |
| 966 | + } | |
| 783 | 967 | |
| 784 | 968 | /** |
| 785 | 969 | * Callback from the tick hook, ticks all tickable mods |
| 786 | 970 | * |
| 787 | 971 | * @param tick True if this is a new tick (otherwise it's just a new frame) |
| 788 | 972 | */ |
| 789 | - public void onTick(boolean tick) | |
| 973 | + public void onTick(Profiler profiler, boolean tick) | |
| 790 | 974 | { |
| 791 | 975 | float partialTicks = 0.0F; |
| 792 | 976 | |
| ... | ... | @@ -809,7 +993,9 @@ public final class LiteLoader implements FilenameFilter |
| 809 | 993 | // Iterate tickable mods |
| 810 | 994 | for (Tickable tickable : tickListeners) |
| 811 | 995 | { |
| 996 | + profiler.startSection(tickable.getClass().getSimpleName()); | |
| 812 | 997 | tickable.onTick(minecraft, partialTicks, inGame, tick); |
| 998 | + profiler.endSection(); | |
| 813 | 999 | } |
| 814 | 1000 | } |
| 815 | 1001 | |
| ... | ... | @@ -832,6 +1018,25 @@ public final class LiteLoader implements FilenameFilter |
| 832 | 1018 | |
| 833 | 1019 | return true; |
| 834 | 1020 | } |
| 1021 | + | |
| 1022 | + /** | |
| 1023 | + * Pre-login callback from the login hook | |
| 1024 | + * | |
| 1025 | + * @param netHandler | |
| 1026 | + * @param hookLogin | |
| 1027 | + * @return | |
| 1028 | + */ | |
| 1029 | + public boolean onPreLogin(NetHandler netHandler, Packet1Login loginPacket) | |
| 1030 | + { | |
| 1031 | + boolean cancelled = false; | |
| 1032 | + | |
| 1033 | + for (PreLoginListener loginListener : preLoginListeners) | |
| 1034 | + { | |
| 1035 | + cancelled |= !loginListener.onPreLogin(netHandler, loginPacket); | |
| 1036 | + } | |
| 1037 | + | |
| 1038 | + return !cancelled; | |
| 1039 | + } | |
| 835 | 1040 | |
| 836 | 1041 | /** |
| 837 | 1042 | * Callback from the login hook | ... | ... |
java/com/mumfrey/liteloader/util/PrivateFields.java
| ... | ... | @@ -130,12 +130,12 @@ public class PrivateFields<P, T> |
| 130 | 130 | public T Get() { return Get(null); } |
| 131 | 131 | public void Set(T value) { Set(null, value); } |
| 132 | 132 | |
| 133 | - public static final StaticFields<Packet, Map> packetClassToIdMap = new StaticFields<Packet, Map> (Packet.class, "packetClassToIdMap", "a"); | |
| 134 | - public static final StaticFields<TileEntity, Map> tileEntityNameToClassMap = new StaticFields<TileEntity, Map> (TileEntity.class, "nameToClassMap", "a"); | |
| 133 | + 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 | 135 | } |
| 136 | 136 | |
| 137 | - public static final PrivateFields<Minecraft, Timer> minecraftTimer = new PrivateFields<Minecraft, Timer> (Minecraft.class, "timer", "T"); | |
| 138 | - public static final PrivateFields<RenderManager, Map> entityRenderMap = new PrivateFields<RenderManager, Map> (RenderManager.class, "entityRenderMap", "o"); | |
| 139 | - public static final PrivateFields<Minecraft, Profiler> minecraftProfiler = new PrivateFields<Minecraft, Profiler> (Minecraft.class, "mcProfiler", "I"); | |
| 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 | |
| 140 | 140 | } |
| 141 | 141 | ... | ... |
java/net/minecraft/src/CallableJVMFlags.java
| ... | ... | @@ -16,7 +16,7 @@ class CallableJVMFlags implements Callable |
| 16 | 16 | CallableJVMFlags(CrashReport par1CrashReport) |
| 17 | 17 | { |
| 18 | 18 | this.crashReportJVMFlags = par1CrashReport; |
| 19 | - par1CrashReport.addCrashSectionCallable("LiteLoader Mods", new CallableLiteLoaderMods(par1CrashReport)); | |
| 19 | + par1CrashReport.func_85056_g().addCrashSectionCallable("LiteLoader Mods", new CallableLiteLoaderMods(par1CrashReport)); | |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public String func_71487_a() | ... | ... |
java/net/minecraft/src/RenderLightningBolt.java
| 1 | 1 | package net.minecraft.src; |
| 2 | 2 | |
| 3 | 3 | import java.util.Random; |
| 4 | + | |
| 4 | 5 | import org.lwjgl.opengl.GL11; |
| 5 | 6 | |
| 6 | 7 | import com.mumfrey.liteloader.core.LiteLoader; |
| ... | ... | @@ -12,8 +13,8 @@ public class RenderLightningBolt extends Render |
| 12 | 13 | // LiteLoader init |
| 13 | 14 | LiteLoader.getInstance(); |
| 14 | 15 | } |
| 15 | - | |
| 16 | - /** | |
| 16 | + | |
| 17 | + /** | |
| 17 | 18 | * Actually renders the lightning bolt. This method is called through the doRender method. |
| 18 | 19 | */ |
| 19 | 20 | public void doRenderLightningBolt(EntityLightningBolt par1EntityLightningBolt, double par2, double par4, double par6, float par8, float par9) | ... | ... |