Add in a mechanism to get the modcontainer for a mod - so things can be programmatically changed

This commit is contained in:
Christian 2012-06-26 16:24:50 -04:00
parent a7caad10ba
commit 5a5ff97f39
6 changed files with 159 additions and 137 deletions

View File

@ -581,7 +581,7 @@ public class ModLoader
*/
public static void registerPacketChannel(BaseMod mod, String channel)
{
FMLCommonHandler.instance().registerChannel(ModLoaderModContainer.findContainerFor(mod), channel);
FMLCommonHandler.instance().registerChannel(FMLCommonHandler.instance().findContainerFor(mod), channel);
}
/**

View File

@ -150,7 +150,22 @@ public class FMLCommonHandler
{
return INSTANCE;
}
/**
* Find the container that associates with the supplied mod object
* @param mod
* @return
*/
public ModContainer findContainerFor(Object mod)
{
for (ModContainer mc : Loader.getModList())
{
if (mc.matches(mod))
{
return mc;
}
}
return null;
}
/**
* Lookup the mod for a channel
* @param channel

View File

@ -163,11 +163,11 @@ public class Loader
if (stream != null) {
try {
properties.load(stream);
major = properties.getProperty("fmlbuild.major.number");
minor = properties.getProperty("fmlbuild.minor.number");
rev = properties.getProperty("fmlbuild.revision.number");
build = properties.getProperty("fmlbuild.build.number");
mcversion = properties.getProperty("fmlbuild.mcversion");
major = properties.getProperty("fmlbuild.major.number","none");
minor = properties.getProperty("fmlbuild.minor.number","none");
rev = properties.getProperty("fmlbuild.revision.number","none");
build = properties.getProperty("fmlbuild.build.number","none");
mcversion = properties.getProperty("fmlbuild.mcversion","none");
} catch (IOException ex) {
Loader.log.log(Level.SEVERE,"Could not get FML version information - corrupted installation detected!", ex);
throw new LoaderException(ex);
@ -545,9 +545,10 @@ public class Loader
extendClassLoader(modFile);
boolean foundAModClass = false;
ZipFile jar = null;
try
{
ZipFile jar = new ZipFile(modFile);
jar = new ZipFile(modFile);
for (ZipEntry ze : Collections.list(jar.entries()))
{
@ -571,6 +572,19 @@ public class Loader
state = State.ERRORED;
capturedError = e;
}
finally
{
if (jar != null)
{
try
{
jar.close();
}
catch (Exception e)
{
}
}
}
return foundAModClass;
}

View File

@ -72,7 +72,7 @@ public class ModLoaderHelper
*/
private static ModLoaderModContainer findOrBuildModContainer(BaseMod mod)
{
ModLoaderModContainer mlmc=(ModLoaderModContainer) ModLoaderModContainer.findContainerFor(mod);
ModLoaderModContainer mlmc=(ModLoaderModContainer) FMLCommonHandler.instance().findContainerFor(mod);
if (mlmc==null) {
mlmc=notModCallbacks.get(mod);
if (mlmc==null) {

View File

@ -363,17 +363,10 @@ public class ModLoaderModContainer implements ModContainer
return mod != null ? mod.getName() : modClazz.getSimpleName();
}
@Deprecated
public static ModContainer findContainerFor(BaseMod mod)
{
for (ModContainer mc : Loader.getModList())
{
if (mc.matches(mod))
{
return mc;
}
}
return null;
return FMLCommonHandler.instance().findContainerFor(mod);
}
@Override

View File

@ -565,7 +565,7 @@ public class ModLoader
*/
public static void registerPacketChannel(BaseMod mod, String channel)
{
FMLCommonHandler.instance().registerChannel(ModLoaderModContainer.findContainerFor(mod), channel);
FMLCommonHandler.instance().registerChannel(FMLCommonHandler.instance().findContainerFor(mod), channel);
}
/**