From bfe54ef7e7cfa0e30010cdf3963165fa8d71ab5f Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 7 Jun 2012 19:25:49 -0400 Subject: [PATCH] Attempt early initialization of Minecraft Forge --- .../cpw/mods/fml/client/FMLClientHandler.java | 31 +---------- .../cpw/mods/fml/common/FMLCommonHandler.java | 54 +++++++++++++++---- .../cpw/mods/fml/server/FMLServerHandler.java | 2 +- 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/client/cpw/mods/fml/client/FMLClientHandler.java b/client/cpw/mods/fml/client/FMLClientHandler.java index 81210f3012..49c1c0f8dc 100644 --- a/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/client/cpw/mods/fml/client/FMLClientHandler.java @@ -161,37 +161,9 @@ public class FMLClientHandler implements IFMLSidedHandler public void onPreLoad(Minecraft minecraft) { -/* try - { - Class.forName("BaseModMp", false, getClass().getClassLoader()); - Minecraft.field_6301_A.severe("" - + "Forge Mod Loader has detected that this server has an ModLoaderMP installed alongside Forge Mod Loader.\n" - + "This will cause a serious problem with compatibility. To protect your worlds, this minecraft server will now shutdown.\n" - + "You should follow the installation instructions of either Minecraft Forge of Forge Mod Loader and NOT install ModLoaderMP \n" - + "into the minecraft_server.jar file " - + "before this server will be allowed to start up.\n\nFailure to do so will simply result in more startup failures.\n\n" - + "The authors of Minecraft Forge and Forge Mod Loader strongly suggest you talk to your mod's authors and get them to\nupdate their " - + "requirements. ModLoaderMP is not compatible with Minecraft Forge on the server and they will need to update their mod\n" - + "for Minecraft Forge and other server compatibility, unless they are Minecraft Forge mods, in which case they already\n" - + "don't need ModLoaderMP and the mod author simply has failed to update his requirements and should be informed appropriately.\n\n" - + "The authors of Forge Mod Loader would like to be compatible with ModLoaderMP but it is closed source and owned by SDK.\n" - + "SDK, the author of ModLoaderMP, has a standing invitation to submit compatibility patches \n" - + "to the open source community project that is Forge Mod Loader so that this incompatibility doesn't last. \n" - + "Users who wish to enjoy mods of both types are " - + "encouraged to request of SDK that he submit a\ncompatibility patch to the Forge Mod Loader project at \n" - + "http://github.com/cpw/FML.\nPosting on the minecraft forums at\nhttp://www.minecraftforum.net/topic/86765- (the MLMP thread)\n" - + "may encourage him in this effort. However, I ask that your requests be polite.\n" - + "Now, the server has to shutdown so you can reinstall your minecraft_server.jar\nproperly, until such time as we can work together."); - throw new RuntimeException( - "This FML based server has detected an installation of ModLoaderMP alongside. This will cause serious compatibility issues, so the server will now shut down."); - } - catch (ClassNotFoundException e) - { - // We're safe. continue - }*/ client = minecraft; ReflectionHelper.detectObfuscation(World.class); - FMLCommonHandler.instance().registerSidedDelegate(this); + FMLCommonHandler.instance().beginLoading(this); FMLRegistry.registerRegistry(new ClientRegistry()); try { @@ -227,7 +199,6 @@ public class FMLClientHandler implements IFMLSidedHandler */ public void onLoadComplete() { - client.field_6315_n.func_1065_b(); Loader.instance().initializeMods(); for (ModContainer mod : Loader.getModList()) { mod.gatherRenderers(RenderManager.field_1233_a.getRendererList()); diff --git a/common/cpw/mods/fml/common/FMLCommonHandler.java b/common/cpw/mods/fml/common/FMLCommonHandler.java index 24352b9890..d22cfcd6cb 100644 --- a/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -85,9 +86,12 @@ public class FMLCommonHandler * We register our delegate here * @param handler */ - public void registerSidedDelegate(IFMLSidedHandler handler) + public void beginLoading(IFMLSidedHandler handler) { sidedDelegate = handler; + getFMLLogger().info("Attempting early MinecraftForge initialization"); + callForgeMethod("initialize"); + getFMLLogger().info("Completed early MinecraftForge initialization"); } public void tickStart(EnumSet ticks, Object ... data) @@ -399,6 +403,42 @@ public class FMLCommonHandler throw new RuntimeException(exception); } + + private Class forge; + private boolean noForge; + + private Class findMinecraftForge() + { + if (forge==null && !noForge) + { + try { + forge = Class.forName("forge.MinecraftForge"); + } catch (Exception ex) { + try { + forge = Class.forName("net.minecraft.src.forge.MinecraftForge"); + } catch (Exception ex2) { + // Ignore- forge isn't loaded + noForge = true; + } + } + } + return forge; + } + + private Object callForgeMethod(String method) + { + if (noForge) + return null; + try + { + return findMinecraftForge().getMethod(method).invoke(null); + } + catch (Exception e) + { + // No Forge installation + return null; + } + } /** * @param string * @return @@ -408,14 +448,10 @@ public class FMLCommonHandler ArrayList brandings=new ArrayList(); brandings.add(mcVersion); brandings.add(Loader.instance().getFMLVersionString()); - try { - brandings.add((String)Class.forName("forge.MinecraftForge").getMethod("getVersionString").invoke(null)); - } catch (Exception ex) { - try { - brandings.add((String)Class.forName("net.minecraft.src.forge.MinecraftForge").getMethod("getVersionString").invoke(null)); - } catch (Exception ex2) { - // Ignore- forge isn't loaded - } + String forgeVersion = (String)callForgeMethod("getVersionString"); + if (forgeVersion != null) + { + brandings.add(forgeVersion); } brandings.addAll(sidedDelegate.getAdditionalBrandingInformation()); try { diff --git a/server/cpw/mods/fml/server/FMLServerHandler.java b/server/cpw/mods/fml/server/FMLServerHandler.java index b23789473b..7e894cd35b 100644 --- a/server/cpw/mods/fml/server/FMLServerHandler.java +++ b/server/cpw/mods/fml/server/FMLServerHandler.java @@ -134,7 +134,7 @@ public class FMLServerHandler implements IFMLSidedHandler } server = minecraftServer; ReflectionHelper.detectObfuscation(World.class); - FMLCommonHandler.instance().registerSidedDelegate(this); + FMLCommonHandler.instance().beginLoading(this); FMLRegistry.registerRegistry(new ServerRegistry()); Loader.instance().loadMods(); }