diff --git a/fml/common/cpw/mods/fml/common/DummyModContainer.java b/fml/common/cpw/mods/fml/common/DummyModContainer.java index b68745abd..977159569 100644 --- a/fml/common/cpw/mods/fml/common/DummyModContainer.java +++ b/fml/common/cpw/mods/fml/common/DummyModContainer.java @@ -16,6 +16,7 @@ import java.io.File; import java.security.cert.Certificate; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import com.google.common.eventbus.EventBus; @@ -168,4 +169,10 @@ public class DummyModContainer implements ModContainer { return md != null ? getModId() : "Dummy Container ("+label+") @" + System.identityHashCode(this); } + + @Override + public Map getCustomModProperties() + { + return EMPTY_PROPERTIES; + } } diff --git a/fml/common/cpw/mods/fml/common/FMLModContainer.java b/fml/common/cpw/mods/fml/common/FMLModContainer.java index cfefbbee8..ee1d90b0e 100644 --- a/fml/common/cpw/mods/fml/common/FMLModContainer.java +++ b/fml/common/cpw/mods/fml/common/FMLModContainer.java @@ -38,6 +38,7 @@ import com.google.common.collect.BiMap; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterators; import com.google.common.collect.ListMultimap; @@ -48,6 +49,7 @@ import com.google.common.collect.Sets; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; +import cpw.mods.fml.common.Mod.CustomProperty; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.Metadata; import cpw.mods.fml.common.discovery.ASMDataTable; @@ -108,6 +110,7 @@ public class FMLModContainer implements ModContainer private String modLanguage; private ILanguageAdapter languageAdapter; private ListMultimap,Method> eventMethods; + private Map customModProperties; public FMLModContainer(String className, File modSource, Map modDescriptor) { @@ -489,6 +492,22 @@ public class FMLModContainer implements ModContainer } } + CustomProperty[] props = (CustomProperty[]) descriptor.get("customProperties"); + if (props!=null && props.length > 0) + { + com.google.common.collect.ImmutableMap.Builder builder = ImmutableMap.builder(); + for (CustomProperty p : props) + { + builder.put(p.k(),p.v()); + } + customModProperties = builder.build(); + } + else + { + customModProperties = EMPTY_PROPERTIES; + } + + Method factoryMethod = gatherAnnotations(clazz); isNetworkMod = FMLNetworkHandler.instance().registerNetworkMod(this, clazz, event.getASMHarvestedData()); modInstance = getLanguageAdapter().getNewInstance(this,clazz, modClassLoader, factoryMethod); @@ -570,4 +589,10 @@ public class FMLModContainer implements ModContainer { return "FMLMod:"+getModId()+"{"+getVersion()+"}"; } + + @Override + public Map getCustomModProperties() + { + return customModProperties; + } } diff --git a/fml/common/cpw/mods/fml/common/InjectedModContainer.java b/fml/common/cpw/mods/fml/common/InjectedModContainer.java index d622db008..fe6d02645 100644 --- a/fml/common/cpw/mods/fml/common/InjectedModContainer.java +++ b/fml/common/cpw/mods/fml/common/InjectedModContainer.java @@ -15,6 +15,7 @@ package cpw.mods.fml.common; import java.io.File; import java.security.cert.Certificate; import java.util.List; +import java.util.Map; import java.util.Set; import com.google.common.eventbus.EventBus; @@ -154,4 +155,10 @@ public class InjectedModContainer implements ModContainer { return "Wrapped{"+wrappedContainer.toString()+"}"; } + + @Override + public Map getCustomModProperties() + { + return wrappedContainer.getCustomModProperties(); + } } diff --git a/fml/common/cpw/mods/fml/common/Loader.java b/fml/common/cpw/mods/fml/common/Loader.java index 1d83d7afa..c1acbf3db 100644 --- a/fml/common/cpw/mods/fml/common/Loader.java +++ b/fml/common/cpw/mods/fml/common/Loader.java @@ -832,4 +832,10 @@ public class Loader } return fmlBrandingProperties; } + + + public Map getCustomModProperties(String modId) + { + return getIndexedModList().get(modId).getCustomModProperties(); + } } diff --git a/fml/common/cpw/mods/fml/common/Mod.java b/fml/common/cpw/mods/fml/common/Mod.java index 44a686569..bfaa87b13 100644 --- a/fml/common/cpw/mods/fml/common/Mod.java +++ b/fml/common/cpw/mods/fml/common/Mod.java @@ -178,6 +178,33 @@ public @interface Mod @Deprecated String asmHookClass() default ""; + /** + * A list of custom properties for this mod. Completely up to the mod author if/when they + * want to put anything in here. + * @return an optional list of custom properties + */ + CustomProperty[] customProperties() default {}; + + /** + * A custom key => value property pair for use with {@link Mod#customProperties()} + * @author cpw + * + */ + @Retention(RetentionPolicy.RUNTIME) + @Target({}) + public @interface CustomProperty + { + /** + * A key. Should be unique. + * @return A key + */ + String k(); + /** + * A value. Can be anything. + * @return A value + */ + String v(); + } /** * Marks the associated method as handling an FML lifecycle event. * The method must have a single parameter, one of the following types. This annotation diff --git a/fml/common/cpw/mods/fml/common/ModContainer.java b/fml/common/cpw/mods/fml/common/ModContainer.java index 0c05062fc..132914ead 100644 --- a/fml/common/cpw/mods/fml/common/ModContainer.java +++ b/fml/common/cpw/mods/fml/common/ModContainer.java @@ -5,7 +5,7 @@ * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * + * * Contributors: * cpw - implementation */ @@ -15,8 +15,10 @@ package cpw.mods.fml.common; import java.io.File; import java.security.cert.Certificate; import java.util.List; +import java.util.Map; import java.util.Set; +import com.google.common.collect.ImmutableMap; import com.google.common.eventbus.EventBus; import cpw.mods.fml.common.versioning.ArtifactVersion; @@ -131,4 +133,7 @@ public interface ModContainer VersionRange acceptableMinecraftVersionRange(); Certificate getSigningCertificate(); + + public static final Map EMPTY_PROPERTIES = ImmutableMap.of(); + Map getCustomModProperties(); } diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java index 568ffb2ae..ce1a0c114 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java @@ -615,4 +615,10 @@ public class ModLoaderModContainer implements ModContainer { return null; } + + @Override + public Map getCustomModProperties() + { + return EMPTY_PROPERTIES; + } }