Files
MinecraftForge/src/fml/ml/ModLoaderModContainer.java
T

90 lines
2.2 KiB
Java
Raw Normal View History

2012-03-30 10:11:13 -04:00
/*
* The FML Forge ModLoader suite.
* Copyright (C) 2012 cpw
*
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package fml.ml;
2012-03-30 10:11:13 -04:00
import fml.Loader;
import fml.LoaderException;
import fml.ModContainer;
import fml.obf.FMLHandler;
2012-03-30 01:12:59 -04:00
import net.minecraft.src.BaseMod;
public class ModLoaderModContainer implements ModContainer {
2012-03-30 01:12:59 -04:00
private Class<? extends BaseMod> modClazz;
private BaseMod mod;
private boolean isTicking;
public ModLoaderModContainer(Class<? extends BaseMod> modClazz) {
this.modClazz=modClazz;
}
public boolean wantsPreInit() {
2012-03-30 01:12:59 -04:00
return true;
}
public boolean wantsPostInit() {
2012-03-30 01:12:59 -04:00
return true;
}
@Override
public void preInit() {
2012-03-30 01:12:59 -04:00
try {
mod=modClazz.newInstance();
} catch (Exception e) {
throw new LoaderException(e);
}
}
@Override
public void init() {
2012-03-30 01:12:59 -04:00
mod.load();
}
@Override
public void postInit() {
2012-03-30 01:12:59 -04:00
mod.modsLoaded();
}
@Override
2012-03-30 10:11:13 -04:00
public void tickStart() {
2012-03-30 01:12:59 -04:00
if (isTicking) {
2012-03-30 10:11:13 -04:00
isTicking=mod.onTickInGame(FMLHandler.INSTANCE.getServer());
2012-03-30 01:12:59 -04:00
}
}
@Override
2012-03-30 10:11:13 -04:00
public void tickEnd() {
2012-03-30 01:12:59 -04:00
// NOOP for modloader
}
@Override
public String getName() {
return mod!=null?mod.getName():null;
}
2012-03-30 01:12:59 -04:00
public static ModContainer findContainerFor(BaseMod mod) {
for (ModContainer mc :Loader.getModList()) {
if (mc.matches(mod)) {
return mc;
}
}
return null;
}
2012-03-30 01:12:59 -04:00
@Override
public boolean matches(Object mod) {
return modClazz.isInstance(mod);
}
public void setTicking(boolean enable) {
isTicking=enable;
}
}