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) 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; 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 * Lookup the mod for a channel
* @param channel * @param channel

View File

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

View File

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

View File

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

View File

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