Check in new fml mod work so far. Lots still to do.

This commit is contained in:
Christian committed 2012-07-14 13:58:46 -04:00
1 parent 5c1363150e
commit 276fccb170
26 files changed
+802 -349

No files matched your search

+18
View File
@@ -57,6 +57,8 @@
<property name="server.mcp.srcdir" location="${mcp.srcdir}/minecraft_server" />
<property name="clean.mcp.srcdir" location="${mcp.home}/src-base" />
<property name="patch.mcp.srcdir" location="${mcp.home}/src-work" />
<property name="tmp.mcp.srcdir" location="${mcp.home}/src-tmp" />
<property name="renamed.mcp.srcdir" location="${mcp.home}/src-renamed" />
<property name="common.src.dir" location="${basedir}/common" />
<property name="client.src.dir" location="${basedir}/client" />
<property name="server.src.dir" location="${basedir}/server" />
@@ -305,4 +307,20 @@
<arg value="${patch.src.dir}"/>
</exec>
</target>
<target name="makerenamedsource" depends="buildenvsetup,repatch,merge-client,merge-server,buildandreobfmcp">
<copy todir="${tmp.mcp.srcdir}">
<fileset dir="${mcp.srcdir}"/>
</copy>
<exec executable="${python.exe}" dir="${mcp.home}">
<arg value="${mcp.home}/runtime/updatenames.py" />
<arg value="-f" />
</exec>
<copy todir="${renamed.mcp.srcdir}">
<fileset dir="${mcp.srcdir}"/>
</copy>
<move todir="${mcp.srcdir}">
<fileset dir="${tmp.mcp.srcdir}"/>
</move>
</target>
</project>
@@ -52,18 +52,6 @@ public class FMLModContainer implements ModContainer
}
}
@Override
public boolean wantsPreInit()
{
return modDescriptor.wantsPreInit();
}
@Override
public boolean wantsPostInit()
{
return modDescriptor.wantsPostInit();
}
@Override
public void preInit()
{
@@ -94,17 +82,17 @@ public class FMLModContainer implements ModContainer
}
@Override
public ModState getModState()
public LoaderState.ModState getModState()
{
// TODO Auto-generated method stub
return null;
}
@Override
public void nextState()
{
// TODO Auto-generated method stub
}
@Override
public String getSortingRules()
@@ -132,7 +120,7 @@ public class FMLModContainer implements ModContainer
// TODO Auto-generated method stub
return null;
}
@Override
public int lookupFuelValue(int itemId, int itemDamage)
{
@@ -140,13 +128,6 @@ public class FMLModContainer implements ModContainer
return 0;
}
@Override
public boolean wantsPickupNotification()
{
// TODO Auto-generated method stub
return false;
}
@Override
public IPickupNotifier getPickupNotifier()
{
@@ -154,16 +135,6 @@ public class FMLModContainer implements ModContainer
return null;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsToDispense()
*/
@Override
public boolean wantsToDispense()
{
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getDispenseHandler()
*/
@@ -174,16 +145,6 @@ public class FMLModContainer implements ModContainer
return null;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification()
*/
@Override
public boolean wantsCraftingNotification()
{
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getCraftingHandler()
*/
@@ -233,16 +194,6 @@ public class FMLModContainer implements ModContainer
return getSource().getName();
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsNetworkPackets()
*/
@Override
public boolean wantsNetworkPackets()
{
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getNetworkHandler()
*/
@@ -263,16 +214,6 @@ public class FMLModContainer implements ModContainer
return false;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsConsoleCommands()
*/
@Override
public boolean wantsConsoleCommands()
{
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getConsoleHandler()
*/
@@ -283,16 +224,6 @@ public class FMLModContainer implements ModContainer
return null;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsPlayerTracking()
*/
@Override
public boolean wantsPlayerTracking()
{
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getPlayerTracker()
*/
@@ -327,7 +258,7 @@ public class FMLModContainer implements ModContainer
public void setSourceType(SourceType type)
{
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getMetadata()
@@ -352,7 +283,7 @@ public class FMLModContainer implements ModContainer
public void gatherRenderers(Map renderers)
{
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#requestAnimations()
@@ -361,7 +292,7 @@ public class FMLModContainer implements ModContainer
public void requestAnimations()
{
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getVersion()
@@ -387,6 +318,6 @@ public class FMLModContainer implements ModContainer
@Override
public void keyBindEvent(Object keyBinding)
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
}
}
@@ -0,0 +1,16 @@
package cpw.mods.fml.common;
import com.google.common.eventbus.Subscribe;
import cpw.mods.fml.common.event.FMLStateEvent;
public class LoadController
{
private static LoadController instance;
@Subscribe
public void loadController(FMLStateEvent event)
{
}
}
+90 -189
View File
@@ -14,7 +14,6 @@
package cpw.mods.fml.common;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -30,18 +29,16 @@ import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import cpw.mods.fml.common.ModContainer.SourceType;
import cpw.mods.fml.common.toposort.ModSorter;
import cpw.mods.fml.common.toposort.ModSortingException;
import cpw.mods.fml.common.toposort.TopologicalSort;
/**
* The loader class performs the actual loading of the mod code from disk.
*
* <p>There are several {@link State}s to mod loading, triggered in two different stages from the FML handler code's hooks into the
* <p>There are several {@link LoaderState}s to mod loading, triggered in two different stages from the FML handler code's hooks into the
* minecraft code.</p>
*
* <ol>
@@ -62,19 +59,6 @@ import cpw.mods.fml.common.toposort.TopologicalSort;
*/
public class Loader
{
private static Pattern zipJar = Pattern.compile("(.+).(zip|jar)$");
private static Pattern modClass = Pattern.compile("(.+/|)(mod\\_[^\\s$]+).class$");
/**
* The state enum used to help track state progression for the loader
* @author cpw
*
*/
private enum State
{
NOINIT, LOADING, PREINIT, INIT, POSTINIT, UP, ERRORED
};
/**
* The singleton instance
*/
@@ -96,9 +80,9 @@ public class Loader
private static String mcsversion;
/**
* The {@link State} of the loader
* The {@link LoaderState} of the loader
*/
private State state;
private LoaderState state;
/**
* The class loader we load the mods into.
*/
@@ -119,6 +103,9 @@ public class Loader
* The canonical minecraft directory
*/
private File canonicalMinecraftDir;
/**
* The captured error
*/
private Exception capturedError;
@@ -133,6 +120,34 @@ public class Loader
}
private Loader()
{
configureLogging();
InputStream stream = Loader.class.getClassLoader().getResourceAsStream("fmlversion.properties");
Properties properties = new Properties();
if (stream != null) {
try {
properties.load(stream);
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");
mccversion = properties.getProperty("fmlbuild.mcclientversion","none");
mcsversion = properties.getProperty("fmlbuild.mcserverversion","none");
} catch (IOException ex) {
Loader.log.log(Level.SEVERE,"Could not get FML version information - corrupted installation detected!", ex);
throw new LoaderException(ex);
}
}
log.info(String.format("Forge Mod Loader version %s.%s.%s.%s for Minecraft c:%s, s:%s loading", major, minor, rev, build, mccversion, mcsversion));
modClassLoader = new ModClassLoader(getClass().getClassLoader());
}
/**
* Configure the FML logger
*/
private static void configureLogging()
{
FMLLogFormatter formatter=new FMLLogFormatter();
if (FMLCommonHandler.instance().getMinecraftLogger()!=null) {
@@ -158,26 +173,6 @@ public class Loader
{
// Whatever - give up
}
InputStream stream = Loader.class.getClassLoader().getResourceAsStream("fmlversion.properties");
Properties properties = new Properties();
if (stream != null) {
try {
properties.load(stream);
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");
mccversion = properties.getProperty("fmlbuild.mcclientversion","none");
mcsversion = properties.getProperty("fmlbuild.mcserverversion","none");
} catch (IOException ex) {
Loader.log.log(Level.SEVERE,"Could not get FML version information - corrupted installation detected!", ex);
throw new LoaderException(ex);
}
}
log.info(String.format("Forge Mod Loader version %s.%s.%s.%s for Minecraft c:%s, s:%s loading", major, minor, rev, build, mccversion, mcsversion));
modClassLoader = new ModClassLoader(getClass().getClassLoader());
}
/**
@@ -187,64 +182,69 @@ public class Loader
private void sortModList()
{
log.fine("Verifying mod dependencies are satisfied");
for (ModContainer mod : mods)
{
if (!namedMods.keySet().containsAll(mod.getDependencies()))
{
log.severe(String.format("The mod %s requires mods %s to be available, one or more are not", mod.getName(), mod.getDependencies()));
LoaderException le = new LoaderException();
log.throwing("Loader", "sortModList", le);
throw new LoaderException();
}
}
log.fine("All dependencies are satisfied");
ModSorter sorter = new ModSorter(mods, namedMods);
try
{
log.fine("Sorting mods into an ordered list");
mods = sorter.sort();
log.fine("Sorted mod list:");
for (ModContainer mod : mods)
{
if (!namedMods.keySet().containsAll(mod.getDependencies()))
{
log.severe(String.format("The mod %s requires mods %s to be available, one or more are not", mod.getName(), mod.getDependencies()));
LoaderException le = new LoaderException();
log.throwing("Loader", "sortModList", le);
throw new LoaderException();
}
}
log.fine("All dependencies are satisfied");
ModSorter sorter = new ModSorter(mods, namedMods);
try
{
log.fine("Sorting mods into an ordered list");
mods = sorter.sort();
}
catch (ModSortingException sortException)
{
log.severe("A dependency cycle was detected in the input mod set so an ordering cannot be determined");
log.severe(String.format("The visited mod list is %s",sortException.getExceptionData().getVisitedNodes()));
log.severe(String.format("The first mod in the cycle is %s",sortException.getExceptionData().getFirstBadNode()));
log.throwing("Loader", "sortModList", sortException);
throw new LoaderException(sortException);
}
}
finally
{
log.fine("Mod sorting data:");
for (ModContainer mod : mods)
{
log.fine(String.format("\t%s: %s (%s)", mod.getName(), mod.getSource().getName(), mod.getSortingRules()));
}
}
catch (IllegalArgumentException iae)
{
log.severe("A dependency cycle was detected in the input mod set so they cannot be loaded in order");
log.throwing("Loader", "sortModList", iae);
throw new LoaderException(iae);
}
}
/**
* The first mod initialization stage, performed immediately after the jar files and mod classes are loaded,
* {@link State#PREINIT}. The mods are configured from their configuration data and instantiated (for BaseMod mods).
* {@link LoaderState#PREINIT}. The mods are configured from their configuration data and instantiated (for BaseMod mods).
*/
private void preModInit()
{
state = State.PREINIT;
state = state.transition(false);
log.fine("Beginning mod pre-initialization");
for (ModContainer mod : mods)
{
if (mod.wantsPreInit())
log.finer(String.format("Pre-initializing %s", mod.getSource()));
try
{
log.finer(String.format("Pre-initializing %s", mod.getSource()));
try
{
mod.preInit();
}
catch (Throwable t)
{
log.log(Level.SEVERE, String.format("The mod from file %s has failed to load. This is likely a mod installation error.", mod.getSource().getName()), t);
throw new LoaderException(t);
}
namedMods.put(mod.getName(), mod);
mod.preInit();
}
catch (Throwable t)
{
log.log(Level.SEVERE, String.format("The mod from file %s has failed to load. This is likely a mod installation error.", mod.getSource().getName()), t);
throw new LoaderException(t);
}
namedMods.put(mod.getName(), mod);
mod.nextState();
}
// Link up mod metadatas
@@ -264,7 +264,7 @@ public class Loader
*/
private void modInit()
{
state = State.INIT;
state = LoaderState.INIT;
log.fine("Beginning mod initialization");
for (ModContainer mod : mods)
@@ -279,17 +279,14 @@ public class Loader
private void postModInit()
{
state = State.POSTINIT;
state = LoaderState.POSTINIT;
log.fine("Beginning mod post-initialization");
for (ModContainer mod : mods)
{
if (mod.wantsPostInit())
{
log.finer(String.format("Post-initializing %s", mod.getName()));
mod.postInit();
mod.nextState();
}
log.finer(String.format("Post-initializing %s", mod.getName()));
mod.postInit();
mod.nextState();
}
log.fine("Mod post-initialization complete");
@@ -379,7 +376,7 @@ public class Loader
throw loaderException;
}
state = State.LOADING;
state = LoaderState.LOADING;
log.fine("Attempting to load mods contained in the minecraft jar file and associated classes");
File[] minecraftSources=modClassLoader.getParentSources();
if (minecraftSources.length==1 && minecraftSources[0].isFile()) {
@@ -421,7 +418,7 @@ public class Loader
}
else
{
Matcher matcher = zipJar.matcher(modFile.getName());
Matcher matcher = ModDiscoverer.zipJar.matcher(modFile.getName());
if (matcher.matches())
{
@@ -440,67 +437,20 @@ public class Loader
}
}
if (state == State.ERRORED)
if (state == LoaderState.ERRORED)
{
log.severe("A problem has occured during mod loading. Likely a corrupt jar is located in your mods directory");
throw new LoaderException(capturedError);
}
log.info(String.format("Forge Mod Loader has loaded %d mods", mods.size()));
}
private boolean attemptDirLoad(File modDir, String path, SourceType sourceType)
{
if (path.length()==0) {
extendClassLoader(modDir);
}
boolean foundAModClass = false;
File[] content = modDir.listFiles(new FileFilter()
{
@Override
public boolean accept(File file)
{
return (file.isFile() && modClass.matcher(file.getName()).find()) || file.isDirectory();
}
});
// Always sort our content
Arrays.sort(content);
for (File file : content)
{
if (file.isDirectory()) {
log.finest(String.format("Recursing into package %s", path+file.getName()));
foundAModClass|=attemptDirLoad(file,path+file.getName()+".", sourceType);
continue;
}
Matcher fname = modClass.matcher(file.getName());
if (!fname.find()) {
continue;
}
String clazzName=path+fname.group(2);
try
{
log.fine(String.format("Found a mod class %s in directory %s, attempting to load it", clazzName, modDir.getName()));
loadModClass(modDir, file.getName(), clazzName, sourceType);
log.fine(String.format("Successfully loaded mod class %s", file.getName()));
foundAModClass = true;
}
catch (Exception e)
{
log.severe(String.format("File %s failed to read properly", file.getName()));
log.throwing("fml.server.Loader", "attemptDirLoad", e);
state = State.ERRORED;
capturedError = e;
}
}
return foundAModClass;
log.info(String.format("Forge Mod Loader has identified %d mod%s to load", mods.size(), mods.size()!=0 ? "s": ""));
}
private void loadModClass(File classSource, String classFileName, String clazzName, SourceType sourceType)
{
try
{
ModHandler handler = modClassLoader.obtainClassHandlerFor(clazzName);
Class<?> clazz = Class.forName(clazzName, false, modClassLoader);
ModContainer mod=null;
@@ -550,55 +500,6 @@ public class Loader
}
}
private boolean attemptFileLoad(File modFile, SourceType sourceType)
{
extendClassLoader(modFile);
boolean foundAModClass = false;
ZipFile jar = null;
try
{
jar = new ZipFile(modFile);
for (ZipEntry ze : Collections.list(jar.entries()))
{
Matcher match = modClass.matcher(ze.getName());
if (match.matches())
{
String pkg = match.group(1).replace('/', '.');
String clazzName = pkg + match.group(2);
log.fine(String.format("Found a mod class %s in file %s, attempting to load it", clazzName, modFile.getName()));
loadModClass(modFile, ze.getName(), clazzName, sourceType);
log.fine(String.format("Mod class %s loaded successfully", clazzName, modFile.getName()));
foundAModClass = true;
}
}
}
catch (Exception e)
{
log.severe(String.format("Zip file %s failed to read properly", modFile.getName()));
log.throwing("fml.server.Loader", "attemptFileLoad", e);
state = State.ERRORED;
capturedError = e;
}
finally
{
if (jar != null)
{
try
{
jar.close();
}
catch (Exception e)
{
}
}
}
return foundAModClass;
}
public static List<ModContainer> getModList()
{
return instance().mods;
@@ -610,7 +511,7 @@ public class Loader
*/
public void loadMods()
{
state = State.NOINIT;
state = LoaderState.NOINIT;
mods = new ArrayList<ModContainer>();
namedMods = new HashMap<String, ModContainer>();
load();
@@ -630,7 +531,7 @@ public class Loader
for (ModContainer mod : getModList()) {
mod.nextState();
}
state = State.UP;
state = LoaderState.UP;
log.info(String.format("Forge Mod Loader load complete, %d mods loaded", mods.size()));
}
@@ -0,0 +1,63 @@
package cpw.mods.fml.common;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLStateEvent;
/**
* The state enum used to help track state progression for the loader
* @author cpw
*
*/
public enum LoaderState
{
NOINIT("Uninitialized",null),
LOADING("Loading",null),
CONSTRUCTING("Constructing mods",null),
PREINITIALIZATION("Pre-initializing mods", FMLPreInitializationEvent.class),
INITIALIZATION("Initializing mods", FMLInitializationEvent.class),
POSTINITIALIZATION("Post-initializing mods", FMLPostInitializationEvent.class),
LOADCOMPLETE("Mod loading complete", null),
ERRORED("Mod Loading errored",null);
private Class<? extends FMLStateEvent> eventClass;
private String name;
private LoaderState(String name, Class<? extends FMLStateEvent> event)
{
this.name = name;
this.eventClass = event;
}
public LoaderState transition(boolean errored)
{
if (errored)
{
return ERRORED;
}
return values()[ordinal() < values().length ? ordinal()+1 : ordinal()];
}
public enum ModState
{
UNLOADED("Unloaded"),
LOADED("Loaded"),
CONSTRUCTED("Constructed"),
PREINITIALIZED("Pre-initialized"),
INITIALIZED("Initialized"),
POSTINITIALIZED("Post-initialized"),
AVAILABLE("Available");
private String label;
private ModState(String label)
{
this.label = label;
}
public String toString()
{
return this.label;
}
}
}
+83 -9
View File
@@ -13,23 +13,97 @@
*/
package cpw.mods.fml.common;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* A possible future way to indicate mods to the system is to use an annotation style
*
* The new mod style in FML 1.3
*
* @author cpw
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Mod
{
String name() default "";
String version() default "";
boolean wantsPreInit() default false;
boolean wantsPostInit() default false;
public @interface PreInit {}
public @interface Init {}
public @interface PostInit {}
/**
* The unique mod identifier for this mod
* @return
*/
String modid();
/**
* A user friendly name for the mod
* @return
*/
String name() default "";
/**
* A version string for this mod
* @return
*/
String version() default "";
/**
* A simple dependency string for this mod
* @return
*/
String dependsOn() default "";
/**
* Whether to use the mcmod.info metadata by default for this mod.
* If true, settings in the mcmod.info file will override settings in these annotations.
* @return
*/
boolean useMetadata() default false;
/**
* Populate the annotated field with an instance of the Block as specified
* @author cpw
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Block {
/**
* The block's name
* @return
*/
String name();
/**
* The class (extending Block) that should be created.
* @return
*/
String typeClass();
/**
* The associated ItemBlock subtype for the item (can be null for an ItemBlock)
* @return
*/
String itemTypeClass() default "";
}
/**
* Populate the annotated field with an Item
* @author cpw
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Item {
/**
* The name of the item
* @return
*/
String name();
/**
* The type of the item
* @return
*/
String typeClass();
}
/**
* Populate the annotated field with the mod instance.
* @author cpw
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Instance {}
}
+62 -66
View File
@@ -21,9 +21,12 @@ import cpw.mods.fml.common.ModContainer.SourceType;
/**
* The container that wraps around mods in the system.
* <p>The philosophy is that individual mod implementation technologies should not impact the actual loading and management
* of mod code. This interface provides a mechanism by which we can wrap actual mod code so that the loader and other
* facilities can treat mods at arms length.</p>
* <p>
* The philosophy is that individual mod implementation technologies should not
* impact the actual loading and management of mod code. This interface provides
* a mechanism by which we can wrap actual mod code so that the loader and other
* facilities can treat mods at arms length.
* </p>
*
* @author cpw
*
@@ -31,183 +34,176 @@ import cpw.mods.fml.common.ModContainer.SourceType;
public interface ModContainer
{
public enum ModState {
UNLOADED("Unloaded"), LOADED("Loaded"), PREINITIALIZED("Pre-initialized"), INITIALIZED("Initialized"), POSTINITIALIZED("Post-initialized"), AVAILABLE("Available");
private String label;
private ModState(String label) {
this.label=label;
}
public String toString() {
return this.label;
}
}
public enum SourceType {
public enum SourceType
{
JAR, CLASSPATH, DIR;
}
/**
* The enclosed mod wants to be called during pre-initialization.
* @return
*/
boolean wantsPreInit();
/**
* The enclosed mod wants to be called during post-initialization.
* @return
*/
boolean wantsPostInit();
/**
* Called when pre-initialization occurs.
*/
void preInit();
/**
* Called when main initialization occurs.
*/
void init();
/**
* Called when post-initialization occurs.
*/
void postInit();
/**
* The name of the mod
*
* @return
*/
String getName();
/**
* The state of the mod
*
* @return
*/
ModState getModState();
LoaderState.ModState getModState();
/**
* Move to the next mod state
*/
void nextState();
/**
* Does this mod match the supplied mod?
*
* @param mod
* @return
*/
boolean matches(Object mod);
/**
* The source of this mod: the file on the file system
*
* @return
*/
File getSource();
/**
* Returns the sorting rules as a string for printing
*
* @return
*/
String getSortingRules();
/**
* The actual mod object itself
*
* @return
*/
Object getMod();
/**
* Lookup the fuel value for the supplied item/damage with this mod.
*
* @param itemId
* @param itemDamage
* @return
*/
int lookupFuelValue(int itemId, int itemDamage);
/**
* This mod wants to be notified when an object is picked up.
* @return
*/
boolean wantsPickupNotification();
/**
* The pickup notifier for this mod.
*
* @return
*/
IPickupNotifier getPickupNotifier();
/**
* This mod wants to have special dispenser handling.
* @return
*/
boolean wantsToDispense();
/**
* The dispensing handler.
*
* @return
*/
IDispenseHandler getDispenseHandler();
/**
* This mod wants notification of crafting and/or smelting events.
* @return
*/
boolean wantsCraftingNotification();
/**
* The crafting and smelting handler for this mod.
*
* @return
*/
ICraftingHandler getCraftingHandler();
/**
* The strong dependencies of this mod. If the named mods in this list are not present, the game will abort.
* The strong dependencies of this mod. If the named mods in this list are
* not present, the game will abort.
*
* @return
*/
List<String> getDependencies();
/**
* Get a list of mods to load before this one. The special value "*" indicates to load <i>after</i> all other mods (except other "*" mods).
* Get a list of mods to load before this one. The special value "*"
* indicates to load <i>after</i> all other mods (except other "*" mods).
*
* @return
*/
List<String> getPreDepends();
/**
* Get a list of mods to load after this one. The special value "*" indicates to load <i>before</i> all other mods (except other "*" mods).
* Get a list of mods to load after this one. The special value "*"
* indicates to load <i>before</i> all other mods (except other "*" mods).
*
* @return
*/
List<String> getPostDepends();
/**
* This mod wants packets from the client, and wants them handled by FML.
* @return
*/
boolean wantsNetworkPackets();
/**
* The network handler for this mod.
*
* @return
*/
INetworkHandler getNetworkHandler();
/**
* Does this mod own this channel?
*
* @param channel
* @return
*/
boolean ownsNetworkChannel(String channel);
/**
* Does this mod want commands from the console?
* @return
*/
boolean wantsConsoleCommands();
IConsoleHandler getConsoleHandler();
boolean wantsPlayerTracking();
IPlayerTracker getPlayerTracker();
List<IKeyHandler> getKeys();
SourceType getSourceType();
void setSourceType(SourceType type);
ModMetadata getMetadata();
void setMetadata(ModMetadata meta);
/**
*
*
*/
void gatherRenderers(Map renderers);
/**
*
*
*/
void requestAnimations();
/**
* @return
*/
String getVersion();
/**
* @return
*/
ProxyInjector findSidedProxy();
void keyBindEvent(Object keyBinding);
}
@@ -0,0 +1,220 @@
package cpw.mods.fml.common;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes;
import com.google.common.collect.Lists;
import cpw.mods.fml.common.ModContainer.SourceType;
public class ModDiscoverer
{
private class ClassFilter implements FileFilter
{
@Override
public boolean accept(File file)
{
return (file.isFile() && modClass.matcher(file.getName()).find()) || file.isDirectory();
}
}
private class ModCandidate
{
private File classPathRoot;
private File modContainer;
private String className;
private SourceType sourceType;
public ModCandidate(File classPathRoot, File modContainer, String className, SourceType sourceType)
{
this.classPathRoot = classPathRoot;
this.modContainer = modContainer;
this.className = className;
this.sourceType = sourceType;
}
}
private Logger log;
private File modsDir;
private static Pattern zipJar = Pattern.compile("(.+).(zip|jar)$");
private static Pattern classFile = Pattern.compile("([^\\s$]+).class$");
private static Pattern modClass = Pattern.compile("(.+/|)(mod\\_[^\\s$]+).class$");
private List<ModCandidate> candidates = Lists.newArrayList();
private void attemptDirLoad(File modDir, String path, SourceType sourceType, File dirRoot)
{
if (path.length() == 0)
{
dirRoot = modDir;
}
boolean foundAModClass = false;
File[] content = modDir.listFiles(new ClassFilter());
// Always sort our content
Arrays.sort(content);
for (File file : content)
{
if (file.isDirectory())
{
log.finest(String.format("Recursing into package %s", path + file.getName()));
attemptDirLoad(file, path + file.getName() + ".", sourceType, dirRoot);
continue;
}
Matcher fname = modClass.matcher(file.getName());
if (!fname.find())
{
continue;
}
String clazzName = path + fname.group(2);
log.fine(String.format("Candidate mod %s found in directory %s", clazzName, dirRoot.getName()));
candidates.add(new ModCandidate(dirRoot, dirRoot, clazzName, sourceType));
foundAModClass = true;
}
}
private void attemptFileLoad(File modFile, SourceType sourceType)
{
ZipFile jar = null;
try
{
jar = new ZipFile(modFile);
ZipEntry modInfo = jar.getEntry("mcmod.info");
if (modInfo != null)
{
}
for (ZipEntry ze : Collections.list(jar.entries()))
{
Matcher match = classFile.matcher(ze.getName());
if (match.matches())
{
AnnotationFinder finder = new AnnotationFinder(jar.getInputStream(ze));
}
match = modClass.matcher(ze.getName());
if (match.matches())
{
String pkg = match.group(1).replace('/', '.');
String clazzName = pkg + match.group(2);
log.fine(String.format("Candidate mod %s found in mod file %s", clazzName, modFile.getName()));
candidates.add(new ModCandidate(modFile, modFile, clazzName, sourceType));
}
}
}
catch (Exception e)
{
log.warning(String.format("Zip file %s failed to read properly, it will be ignored", modFile.getName()));
}
finally
{
if (jar != null)
{
try
{
jar.close();
}
catch (Exception e)
{
}
}
}
}
public static class AnnotationFinder extends ClassVisitor
{
public AnnotationFinder(InputStream stream) throws IOException
{
super(Opcodes.ASM4);
ClassReader reader = new ClassReader(stream);
reader.accept(this, ClassReader.SKIP_CODE);
}
@Override
public void visit(int arg0, int arg1, String arg2, String arg3, String arg4, String[] arg5)
{
System.out.printf("ClassVisit.visit %d %d %s %s %s %s\n", arg0, arg1, arg2, arg3, arg4, Arrays.asList(arg5));
super.visit(arg0, arg1, arg2, arg3, arg4, arg5);
}
@Override
public void visitOuterClass(String arg0, String arg1, String arg2)
{
System.out.printf("ClassVisit.visitOuterClass %s %s %s\n", arg0, arg1, arg2);
super.visitOuterClass(arg0, arg1, arg2);
}
@Override
public void visitAttribute(Attribute arg0)
{
System.out.printf("ClassVisit.visitAttribute %s\n", arg0);
super.visitAttribute(arg0);
}
@Override
public FieldVisitor visitField(int arg0, String arg1, String arg2, String arg3, Object arg4)
{
System.out.printf("ClassVisit.visitField %d %s %s %s %s\n", arg0, arg1, arg2, arg3, arg4);
return new FieldVisitor(Opcodes.ASM4)
{
@Override
public AnnotationVisitor visitAnnotation(String arg0, boolean arg1)
{
System.out.printf("FieldVisitor.visit %s %s\n", arg0, arg1);
return new AnnotationVisitor(Opcodes.ASM4)
{
@Override
public void visit(String arg0, Object arg1)
{
System.out.printf("FieldAnnotationVisitor.visit %s %s\n", arg0, arg1);
super.visit(arg0, arg1);
}
};
}
};
}
@Override
public AnnotationVisitor visitAnnotation(String arg0, boolean arg1)
{
System.out.printf("ClassVisit.visitAnnotation %s %b\n", arg0, arg1);
return new AnnotationVisitor(Opcodes.ASM4)
{
@Override
public void visit(String arg0, Object arg1)
{
System.out.printf("ClassAnnotationVisitor.visit %s %s\n", arg0, arg1);
super.visit(arg0, arg1);
}
};
}
}
}
@@ -0,0 +1,9 @@
package cpw.mods.fml.common.event;
public class FMLEvent
{
public final String getEventType()
{
return getClass().getSimpleName();
}
}
@@ -0,0 +1,6 @@
package cpw.mods.fml.common.event;
public class FMLInitializationEvent extends FMLStateEvent
{
}
@@ -0,0 +1,6 @@
package cpw.mods.fml.common.event;
public class FMLPostInitializationEvent extends FMLStateEvent
{
}
@@ -0,0 +1,8 @@
package cpw.mods.fml.common.event;
import com.google.common.eventbus.EventBus;
public class FMLPreInitializationEvent extends FMLStateEvent
{
}
@@ -0,0 +1,6 @@
package cpw.mods.fml.common.event;
public class FMLServerInitializationEvent extends FMLStateEvent
{
}
@@ -0,0 +1,6 @@
package cpw.mods.fml.common.event;
public class FMLStateEvent extends FMLEvent
{
}
@@ -0,0 +1,6 @@
package cpw.mods.fml.common.event;
public class FMLUninitializationEvent extends FMLStateEvent
{
}
@@ -43,8 +43,9 @@ import cpw.mods.fml.common.IPlayerTracker;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderException;
import cpw.mods.fml.common.LoaderState;
import cpw.mods.fml.common.LoaderState.ModState;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.ModContainer.ModState;
import cpw.mods.fml.common.ModContainer.SourceType;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.ProxyInjector;
@@ -60,7 +61,7 @@ public class ModLoaderModContainer implements ModContainer
private ArrayList<String> preDependencies;
private ArrayList<String> postDependencies;
private ArrayList<IKeyHandler> keyHandlers;
private ModState state;
private LoaderState.ModState state;
private SourceType sourceType;
private ModMetadata metadata;
private ProxyInjector sidedProxy;
@@ -121,7 +122,7 @@ public class ModLoaderModContainer implements ModContainer
}
@Override
public ModState getModState()
public LoaderState.ModState getModState()
{
return state;
}
@@ -130,11 +131,11 @@ public class ModLoaderModContainer implements ModContainer
public void nextState()
{
if (state==null) {
state=ModState.UNLOADED;
state=LoaderState.ModState.UNLOADED;
return;
}
if (state.ordinal()+1<ModState.values().length) {
state=ModState.values()[state.ordinal()+1];
if (state.ordinal()+1<LoaderState.ModState.values().length) {
state=LoaderState.ModState.values()[state.ordinal()+1];
}
}
/**
@@ -0,0 +1,43 @@
package cpw.mods.fml.common.toposort;
import java.util.Set;
import cpw.mods.fml.common.ModContainer;
public class ModSortingException extends RuntimeException
{
public class SortingExceptionData<T>
{
public SortingExceptionData(T node, Set<T> visitedNodes)
{
this.firstBadNode = node;
this.visitedNodes = visitedNodes;
}
private T firstBadNode;
private Set<T> visitedNodes;
public T getFirstBadNode()
{
return firstBadNode;
}
public Set<T> getVisitedNodes()
{
return visitedNodes;
}
}
private SortingExceptionData sortingExceptionData;
public <T> ModSortingException(String string, T node, Set<T> visitedNodes)
{
super(string);
this.sortingExceptionData = new SortingExceptionData(node, visitedNodes);
}
public <T> SortingExceptionData<T> getExceptionData()
{
return sortingExceptionData;
}
}
@@ -39,7 +39,7 @@ public class TopologicalSort
{
private final Map<T, SortedSet<T>> graph = new HashMap<T, SortedSet<T>>();
private List<T> orderedNodes = new ArrayList<T>();
public boolean addNode(T node)
{
// Ignore nodes already added
@@ -176,7 +176,7 @@ public class TopologicalSort
}
System.out.printf("%s: %s\n%s\n%s\n", node, sortedResult, visitedNodes, expandedNodes);
throw new IllegalArgumentException("There was a cycle detected in the input graph, sorting is not possible");
throw new ModSortingException("There was a cycle detected in the input graph, sorting is not possible", node, visitedNodes);
}
// Visit this node
+3
View File
@@ -0,0 +1,3 @@
java.io.FileInputStream fis = new java.io.FileInputStream(new java.io.File("/home/cpw/projects/FML/mcsnapshot/FML/eclipse/FML-MockMod/bin/cpw/mods/mockmod/MockMod.class"));
cpw.mods.fml.common.ModDiscoverer.AnnotationFinder ann = new cpw.mods.fml.common.ModDiscoverer.AnnotationFinder(fis);
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="src" path="/FML-Client"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>FML-MockMod</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,13 @@
package cpw.mods.mockmod;
import com.google.common.eventbus.Subscribe;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Block;
@Mod(modid="MockMod", name="Mock Mod",version="1.2.3", dependsOn="noone", useMetadata=true)
public class MockMod
{
@Block(typeClass="myclass",itemTypeClass="",name="MyBlock")
private Object myBlock;
}
+25
View File
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="minecraft"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry exported="true" kind="lib" path="jars/bin/jinput.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="MCP-Client/jars/bin/natives"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="jars/bin/lwjgl_util.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="MCP-Client/jars/bin/natives"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="jars/bin/lwjgl.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="MCP-Client/jars/bin/natives"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="jars/bin/minecraft.jar"/>
<classpathentry exported="true" kind="lib" path="lib/argo-2.25.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-all-4.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/guava-12.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+56
View File
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MCP-Client</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>jars</name>
<type>2</type>
<locationURI>MCP_LOC/jars</locationURI>
</link>
<link>
<name>lib</name>
<type>2</type>
<locationURI>MCP_LOC/lib</locationURI>
</link>
<link>
<name>minecraft</name>
<type>2</type>
<locationURI>MCP_LOC/src-renamed/minecraft</locationURI>
</link>
<link>
<name>minecraft/fmlversion.properties</name>
<type>1</type>
<locationURI>MCP_LOC/FML/fmlversion.properties</locationURI>
</link>
</linkedResources>
<filteredResources>
<filter>
<id>1341586110750</id>
<name>jars</name>
<type>13</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-bin</arguments>
</matcher>
</filter>
</filteredResources>
<variableList>
<variable>
<name>MCP_LOC</name>
<value>$%7BPARENT-2-WORKSPACE_LOC%7D</value>
</variable>
</variableList>
</projectDescription>
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6