From 276fccb1706557d2de55f8edf32966927265d692 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 14 Jul 2012 13:58:46 -0400 Subject: [PATCH] Check in new fml mod work so far. Lots still to do. --- build.xml | 18 ++ .../cpw/mods/fml/common/FMLModContainer.java | 85 +----- .../cpw/mods/fml/common/LoadController.java | 16 + common/cpw/mods/fml/common/Loader.java | 279 ++++++------------ common/cpw/mods/fml/common/LoaderState.java | 63 ++++ common/cpw/mods/fml/common/Mod.java | 92 +++++- common/cpw/mods/fml/common/ModContainer.java | 128 ++++---- common/cpw/mods/fml/common/ModDiscoverer.java | 220 ++++++++++++++ .../cpw/mods/fml/common/event/FMLEvent.java | 9 + .../common/event/FMLInitializationEvent.java | 6 + .../event/FMLPostInitializationEvent.java | 6 + .../event/FMLPreInitializationEvent.java | 8 + .../event/FMLServerInitializationEvent.java | 6 + .../mods/fml/common/event/FMLStateEvent.java | 6 + .../event/FMLUninitializationEvent.java | 6 + .../modloader/ModLoaderModContainer.java | 13 +- .../common/toposort/ModSortingException.java | 43 +++ .../fml/common/toposort/TopologicalSort.java | 4 +- eclipse/FML-Client/tstann.jpage | 3 + eclipse/FML-MockMod/.classpath | 7 + eclipse/FML-MockMod/.project | 17 ++ .../.settings/org.eclipse.jdt.core.prefs | 11 + .../src/cpw/mods/mockmod/MockMod.java | 13 + eclipse/MCP-Client/.classpath | 25 ++ eclipse/MCP-Client/.project | 56 ++++ .../.settings/org.eclipse.jdt.core.prefs | 11 + 26 files changed, 802 insertions(+), 349 deletions(-) create mode 100644 common/cpw/mods/fml/common/LoadController.java create mode 100644 common/cpw/mods/fml/common/LoaderState.java create mode 100644 common/cpw/mods/fml/common/ModDiscoverer.java create mode 100644 common/cpw/mods/fml/common/event/FMLEvent.java create mode 100644 common/cpw/mods/fml/common/event/FMLInitializationEvent.java create mode 100644 common/cpw/mods/fml/common/event/FMLPostInitializationEvent.java create mode 100644 common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java create mode 100644 common/cpw/mods/fml/common/event/FMLServerInitializationEvent.java create mode 100644 common/cpw/mods/fml/common/event/FMLStateEvent.java create mode 100644 common/cpw/mods/fml/common/event/FMLUninitializationEvent.java create mode 100644 common/cpw/mods/fml/common/toposort/ModSortingException.java create mode 100644 eclipse/FML-Client/tstann.jpage create mode 100644 eclipse/FML-MockMod/.classpath create mode 100644 eclipse/FML-MockMod/.project create mode 100644 eclipse/FML-MockMod/.settings/org.eclipse.jdt.core.prefs create mode 100644 eclipse/FML-MockMod/src/cpw/mods/mockmod/MockMod.java create mode 100644 eclipse/MCP-Client/.classpath create mode 100644 eclipse/MCP-Client/.project create mode 100644 eclipse/MCP-Client/.settings/org.eclipse.jdt.core.prefs diff --git a/build.xml b/build.xml index 3afc5bdbd1..2bd8d87a0d 100644 --- a/build.xml +++ b/build.xml @@ -57,6 +57,8 @@ + + @@ -305,4 +307,20 @@ + + + + + + + + + + + + + + + + diff --git a/common/cpw/mods/fml/common/FMLModContainer.java b/common/cpw/mods/fml/common/FMLModContainer.java index 5d501f6d74..2fe86dc644 100644 --- a/common/cpw/mods/fml/common/FMLModContainer.java +++ b/common/cpw/mods/fml/common/FMLModContainer.java @@ -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 } } diff --git a/common/cpw/mods/fml/common/LoadController.java b/common/cpw/mods/fml/common/LoadController.java new file mode 100644 index 0000000000..bf5af0d709 --- /dev/null +++ b/common/cpw/mods/fml/common/LoadController.java @@ -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) + { + + } +} diff --git a/common/cpw/mods/fml/common/Loader.java b/common/cpw/mods/fml/common/Loader.java index c223ea6dac..ce8b473930 100644 --- a/common/cpw/mods/fml/common/Loader.java +++ b/common/cpw/mods/fml/common/Loader.java @@ -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. * - *

There are several {@link State}s to mod loading, triggered in two different stages from the FML handler code's hooks into the + *

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.

* *
    @@ -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 getModList() { return instance().mods; @@ -610,7 +511,7 @@ public class Loader */ public void loadMods() { - state = State.NOINIT; + state = LoaderState.NOINIT; mods = new ArrayList(); namedMods = new HashMap(); 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())); } diff --git a/common/cpw/mods/fml/common/LoaderState.java b/common/cpw/mods/fml/common/LoaderState.java new file mode 100644 index 0000000000..074f7b6328 --- /dev/null +++ b/common/cpw/mods/fml/common/LoaderState.java @@ -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 eventClass; + private String name; + + private LoaderState(String name, Class 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; + } + } +} \ No newline at end of file diff --git a/common/cpw/mods/fml/common/Mod.java b/common/cpw/mods/fml/common/Mod.java index ea6182a97c..f08bf86deb 100644 --- a/common/cpw/mods/fml/common/Mod.java +++ b/common/cpw/mods/fml/common/Mod.java @@ -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 {} } diff --git a/common/cpw/mods/fml/common/ModContainer.java b/common/cpw/mods/fml/common/ModContainer.java index 2139c051cd..e828e29bda 100644 --- a/common/cpw/mods/fml/common/ModContainer.java +++ b/common/cpw/mods/fml/common/ModContainer.java @@ -21,9 +21,12 @@ import cpw.mods.fml.common.ModContainer.SourceType; /** * The container that wraps around mods in the system. - *

    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.

    + *

    + * 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. + *

    * * @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 getDependencies(); + /** - * Get a list of mods to load before this one. The special value "*" indicates to load after all other mods (except other "*" mods). + * Get a list of mods to load before this one. The special value "*" + * indicates to load after all other mods (except other "*" mods). + * * @return */ List getPreDepends(); + /** - * Get a list of mods to load after this one. The special value "*" indicates to load before all other mods (except other "*" mods). + * Get a list of mods to load after this one. The special value "*" + * indicates to load before all other mods (except other "*" mods). + * * @return */ List 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 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); } diff --git a/common/cpw/mods/fml/common/ModDiscoverer.java b/common/cpw/mods/fml/common/ModDiscoverer.java new file mode 100644 index 0000000000..68180db208 --- /dev/null +++ b/common/cpw/mods/fml/common/ModDiscoverer.java @@ -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 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); + } + + }; + } + } +} diff --git a/common/cpw/mods/fml/common/event/FMLEvent.java b/common/cpw/mods/fml/common/event/FMLEvent.java new file mode 100644 index 0000000000..4014f7c7e3 --- /dev/null +++ b/common/cpw/mods/fml/common/event/FMLEvent.java @@ -0,0 +1,9 @@ +package cpw.mods.fml.common.event; + +public class FMLEvent +{ + public final String getEventType() + { + return getClass().getSimpleName(); + } +} diff --git a/common/cpw/mods/fml/common/event/FMLInitializationEvent.java b/common/cpw/mods/fml/common/event/FMLInitializationEvent.java new file mode 100644 index 0000000000..b136c3a4ff --- /dev/null +++ b/common/cpw/mods/fml/common/event/FMLInitializationEvent.java @@ -0,0 +1,6 @@ +package cpw.mods.fml.common.event; + +public class FMLInitializationEvent extends FMLStateEvent +{ + +} diff --git a/common/cpw/mods/fml/common/event/FMLPostInitializationEvent.java b/common/cpw/mods/fml/common/event/FMLPostInitializationEvent.java new file mode 100644 index 0000000000..55ea1bea34 --- /dev/null +++ b/common/cpw/mods/fml/common/event/FMLPostInitializationEvent.java @@ -0,0 +1,6 @@ +package cpw.mods.fml.common.event; + +public class FMLPostInitializationEvent extends FMLStateEvent +{ + +} diff --git a/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java b/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java new file mode 100644 index 0000000000..244352ac16 --- /dev/null +++ b/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java @@ -0,0 +1,8 @@ +package cpw.mods.fml.common.event; + +import com.google.common.eventbus.EventBus; + +public class FMLPreInitializationEvent extends FMLStateEvent +{ + +} diff --git a/common/cpw/mods/fml/common/event/FMLServerInitializationEvent.java b/common/cpw/mods/fml/common/event/FMLServerInitializationEvent.java new file mode 100644 index 0000000000..caf9f8cea3 --- /dev/null +++ b/common/cpw/mods/fml/common/event/FMLServerInitializationEvent.java @@ -0,0 +1,6 @@ +package cpw.mods.fml.common.event; + +public class FMLServerInitializationEvent extends FMLStateEvent +{ + +} diff --git a/common/cpw/mods/fml/common/event/FMLStateEvent.java b/common/cpw/mods/fml/common/event/FMLStateEvent.java new file mode 100644 index 0000000000..121b7dfe87 --- /dev/null +++ b/common/cpw/mods/fml/common/event/FMLStateEvent.java @@ -0,0 +1,6 @@ +package cpw.mods.fml.common.event; + +public class FMLStateEvent extends FMLEvent +{ + +} diff --git a/common/cpw/mods/fml/common/event/FMLUninitializationEvent.java b/common/cpw/mods/fml/common/event/FMLUninitializationEvent.java new file mode 100644 index 0000000000..a42704d607 --- /dev/null +++ b/common/cpw/mods/fml/common/event/FMLUninitializationEvent.java @@ -0,0 +1,6 @@ +package cpw.mods.fml.common.event; + +public class FMLUninitializationEvent extends FMLStateEvent +{ + +} diff --git a/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java b/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java index 06855ae5ed..e66d185e5d 100644 --- a/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java +++ b/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java @@ -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 preDependencies; private ArrayList postDependencies; private ArrayList 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 + { + public SortingExceptionData(T node, Set visitedNodes) + { + this.firstBadNode = node; + this.visitedNodes = visitedNodes; + } + + private T firstBadNode; + private Set visitedNodes; + + public T getFirstBadNode() + { + return firstBadNode; + } + public Set getVisitedNodes() + { + return visitedNodes; + } + } + + private SortingExceptionData sortingExceptionData; + + public ModSortingException(String string, T node, Set visitedNodes) + { + super(string); + this.sortingExceptionData = new SortingExceptionData(node, visitedNodes); + } + + public SortingExceptionData getExceptionData() + { + return sortingExceptionData; + } + +} diff --git a/common/cpw/mods/fml/common/toposort/TopologicalSort.java b/common/cpw/mods/fml/common/toposort/TopologicalSort.java index f3a03ae1d2..48a9bac688 100644 --- a/common/cpw/mods/fml/common/toposort/TopologicalSort.java +++ b/common/cpw/mods/fml/common/toposort/TopologicalSort.java @@ -39,7 +39,7 @@ public class TopologicalSort { private final Map> graph = new HashMap>(); private List orderedNodes = new ArrayList(); - + 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 diff --git a/eclipse/FML-Client/tstann.jpage b/eclipse/FML-Client/tstann.jpage new file mode 100644 index 0000000000..bdd5a53500 --- /dev/null +++ b/eclipse/FML-Client/tstann.jpage @@ -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); diff --git a/eclipse/FML-MockMod/.classpath b/eclipse/FML-MockMod/.classpath new file mode 100644 index 0000000000..9fae2ab383 --- /dev/null +++ b/eclipse/FML-MockMod/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/eclipse/FML-MockMod/.project b/eclipse/FML-MockMod/.project new file mode 100644 index 0000000000..cbfeeb52ee --- /dev/null +++ b/eclipse/FML-MockMod/.project @@ -0,0 +1,17 @@ + + + FML-MockMod + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/eclipse/FML-MockMod/.settings/org.eclipse.jdt.core.prefs b/eclipse/FML-MockMod/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..8000cd6ca6 --- /dev/null +++ b/eclipse/FML-MockMod/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/eclipse/FML-MockMod/src/cpw/mods/mockmod/MockMod.java b/eclipse/FML-MockMod/src/cpw/mods/mockmod/MockMod.java new file mode 100644 index 0000000000..c708357be9 --- /dev/null +++ b/eclipse/FML-MockMod/src/cpw/mods/mockmod/MockMod.java @@ -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; +} diff --git a/eclipse/MCP-Client/.classpath b/eclipse/MCP-Client/.classpath new file mode 100644 index 0000000000..5618678ff1 --- /dev/null +++ b/eclipse/MCP-Client/.classpath @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eclipse/MCP-Client/.project b/eclipse/MCP-Client/.project new file mode 100644 index 0000000000..1d77050e3f --- /dev/null +++ b/eclipse/MCP-Client/.project @@ -0,0 +1,56 @@ + + + MCP-Client + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + jars + 2 + MCP_LOC/jars + + + lib + 2 + MCP_LOC/lib + + + minecraft + 2 + MCP_LOC/src-renamed/minecraft + + + minecraft/fmlversion.properties + 1 + MCP_LOC/FML/fmlversion.properties + + + + + 1341586110750 + jars + 13 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-bin + + + + + + MCP_LOC + $%7BPARENT-2-WORKSPACE_LOC%7D + + + diff --git a/eclipse/MCP-Client/.settings/org.eclipse.jdt.core.prefs b/eclipse/MCP-Client/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..8000cd6ca6 --- /dev/null +++ b/eclipse/MCP-Client/.settings/org.eclipse.jdt.core.prefs @@ -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