Split loadmods into loadmods and preinitmods, to allow resource loading to occur *always* between the two phases. This should fix

mods not being able to access resources during preinit.

PS: I'm still not modding.
This commit is contained in:
Christian 2014-05-08 10:22:02 -04:00
parent 0b795b8bab
commit b286cb6a57
6 changed files with 30 additions and 25 deletions

View File

@ -229,7 +229,25 @@ public class FMLClientHandler implements IFMLSidedHandler
haltGame("There was a severe problem during mod loading that has caused the game to fail", le); haltGame("There was a severe problem during mod loading that has caused the game to fail", le);
return; return;
} }
finally
{
client.refreshResources();
}
try
{
Loader.instance().preinitializeMods();
}
catch (CustomModLoadingErrorDisplayException custom)
{
FMLLog.log(Level.ERROR, custom, "A custom exception was thrown by a mod, the game will now halt");
customError = custom;
}
catch (LoaderException le)
{
haltGame("There was a severe problem during mod loading that has caused the game to fail", le);
return;
}
Map<String,Map<String,String>> sharedModList = (Map<String, Map<String, String>>) Launch.blackboard.get("modList"); Map<String,Map<String,String>> sharedModList = (Map<String, Map<String, String>>) Launch.blackboard.get("modList");
if (sharedModList == null) if (sharedModList == null)
{ {
@ -566,12 +584,6 @@ public class FMLClientHandler implements IFMLSidedHandler
} }
} }
@Override
public void updateResourcePackList()
{
client.refreshResources();
}
public IResourcePack getResourcePackFor(String modId) public IResourcePack getResourcePackFor(String modId)
{ {
return resourcePackMap.get(modId); return resourcePackMap.get(modId);
@ -813,7 +825,7 @@ public class FMLClientHandler implements IFMLSidedHandler
public void setPlayClient(NetHandlerPlayClient netHandlerPlayClient) public void setPlayClient(NetHandlerPlayClient netHandlerPlayClient)
{ {
playClientBlock.countDown(); playClientBlock.countDown();
this.currentPlayClient = new WeakReference(netHandlerPlayClient); this.currentPlayClient = new WeakReference<NetHandlerPlayClient>(netHandlerPlayClient);
} }
@Override @Override

View File

@ -514,11 +514,6 @@ public class FMLCommonHandler
sidedDelegate.addModAsResource(container); sidedDelegate.addModAsResource(container);
} }
public void updateResourcePackList()
{
sidedDelegate.updateResourcePackList();
}
public String getCurrentLanguage() public String getCurrentLanguage()
{ {

View File

@ -46,8 +46,6 @@ public interface IFMLSidedHandler
void addModAsResource(ModContainer container); void addModAsResource(ModContainer container);
void updateResourcePackList();
String getCurrentLanguage(); String getCurrentLanguage();
void serverStopped(); void serverStopped();

View File

@ -109,7 +109,6 @@ public class LoadController
} }
eventChannels = eventBus.build(); eventChannels = eventBus.build();
FMLCommonHandler.instance().updateResourcePackList();
} }
public void distributeStateMessage(LoaderState state, Object... eventData) public void distributeStateMessage(LoaderState state, Object... eventData)

View File

@ -148,6 +148,7 @@ public class Loader
private static List<String> injectedContainers; private static List<String> injectedContainers;
private ImmutableMap<String, String> fmlBrandingProperties; private ImmutableMap<String, String> fmlBrandingProperties;
private File forcedModFile; private File forcedModFile;
private ModDiscoverer discoverer;
public static Loader instance() public static Loader instance()
{ {
@ -462,15 +463,15 @@ public class Loader
namedMods = Maps.newHashMap(); namedMods = Maps.newHashMap();
modController = new LoadController(this); modController = new LoadController(this);
modController.transition(LoaderState.LOADING, false); modController.transition(LoaderState.LOADING, false);
ModDiscoverer disc = identifyMods(); discoverer = identifyMods();
ModAPIManager.INSTANCE.manageAPI(modClassLoader, disc); ModAPIManager.INSTANCE.manageAPI(modClassLoader, discoverer);
disableRequestedMods(); disableRequestedMods();
modController.distributeStateMessage(FMLLoadEvent.class); modController.distributeStateMessage(FMLLoadEvent.class);
sortModList(); sortModList();
ModAPIManager.INSTANCE.cleanupAPIContainers(modController.getActiveModList()); ModAPIManager.INSTANCE.cleanupAPIContainers(modController.getActiveModList());
ModAPIManager.INSTANCE.cleanupAPIContainers(mods); ModAPIManager.INSTANCE.cleanupAPIContainers(mods);
mods = ImmutableList.copyOf(mods); mods = ImmutableList.copyOf(mods);
for (File nonMod : disc.getNonModLibs()) for (File nonMod : discoverer.getNonModLibs())
{ {
if (nonMod.isFile()) if (nonMod.isFile())
{ {
@ -486,7 +487,7 @@ public class Loader
} }
} }
modController.transition(LoaderState.CONSTRUCTING, false); modController.transition(LoaderState.CONSTRUCTING, false);
modController.distributeStateMessage(LoaderState.CONSTRUCTING, modClassLoader, disc.getASMTable(), reverseDependencies); modController.distributeStateMessage(LoaderState.CONSTRUCTING, modClassLoader, discoverer.getASMTable(), reverseDependencies);
FMLLog.fine("Mod signature data"); FMLLog.fine("Mod signature data");
for (ModContainer mod : getActiveModList()) for (ModContainer mod : getActiveModList())
{ {
@ -497,7 +498,11 @@ public class Loader
FMLLog.fine("No user mod signature data found"); FMLLog.fine("No user mod signature data found");
} }
modController.transition(LoaderState.PREINITIALIZATION, false); modController.transition(LoaderState.PREINITIALIZATION, false);
modController.distributeStateMessage(LoaderState.PREINITIALIZATION, disc.getASMTable(), canonicalConfigDir); }
public void preinitializeMods()
{
modController.distributeStateMessage(LoaderState.PREINITIALIZATION, discoverer.getASMTable(), canonicalConfigDir);
modController.transition(LoaderState.INITIALIZATION, false); modController.transition(LoaderState.INITIALIZATION, false);
} }

View File

@ -85,6 +85,7 @@ public class FMLServerHandler implements IFMLSidedHandler
{ {
server = minecraftServer; server = minecraftServer;
Loader.instance().loadMods(); Loader.instance().loadMods();
Loader.instance().preinitializeMods();
} }
/** /**
@ -220,11 +221,6 @@ public class FMLServerHandler implements IFMLSidedHandler
LanguageRegistry.instance().loadLanguagesFor(container, Side.SERVER); LanguageRegistry.instance().loadLanguagesFor(container, Side.SERVER);
} }
@Override
public void updateResourcePackList()
{
}
@Override @Override
public String getCurrentLanguage() public String getCurrentLanguage()
{ {