Search in sources :

Example 11 with ASMData

use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.

the class ASMDataTable method getAnnotationsFor.

public SetMultimap<String, ASMData> getAnnotationsFor(ModContainer container) {
    if (containerAnnotationData == null) {
        ImmutableMap.Builder<ModContainer, SetMultimap<String, ASMData>> mapBuilder = ImmutableMap.builder();
        for (ModContainer cont : containers) {
            Multimap<String, ASMData> values = Multimaps.filterValues(globalAnnotationData, new ModContainerPredicate(cont));
            mapBuilder.put(cont, ImmutableSetMultimap.copyOf(values));
        }
        containerAnnotationData = mapBuilder.build();
    }
    return containerAnnotationData.get(container);
}
Also used : SetMultimap(com.google.common.collect.SetMultimap) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) ModContainer(net.minecraftforge.fml.common.ModContainer) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 12 with ASMData

use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project Bookshelf by Darkhax-Minecraft.

the class AnnotationUtils method getAnnotations.

/**
     * Finds all classes annotated with the annotation class. These classes are then
     * instantiated, added to a list, and given to you.
     *
     * @param table The ASMDataTable created by Forge. You can get this from most of the main
     *        mod loading stage events.
     * @param annotation The class of the annotation you're using to search for.
     * @param instance The class of the thing you're trying to construct. This should be a
     *        shared interface, or parent class.
     * @return A list of all classes annotated with the annotation, as instances.
     */
public static <T, A extends Annotation> Map<T, A> getAnnotations(ASMDataTable table, Class<A> annotation, Class<T> instance) {
    final Map<T, A> map = new HashMap<>();
    for (final ASMDataTable.ASMData asmData : getData(table, annotation)) {
        try {
            final Class<?> asmClass = Class.forName(asmData.getClassName());
            final Class<? extends T> asmInstanceClass = asmClass.asSubclass(instance);
            map.put(asmInstanceClass.newInstance(), asmInstanceClass.getAnnotation(annotation));
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            Constants.LOG.warn("Could not load " + asmData.getClassName(), e);
        }
    }
    return map;
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) HashMap(java.util.HashMap)

Aggregations

ASMData (net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData)12 Field (java.lang.reflect.Field)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 ASMDataTable (net.minecraftforge.fml.common.discovery.ASMDataTable)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 Subscribe (com.google.common.eventbus.Subscribe)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LoaderException (net.minecraftforge.fml.common.LoaderException)1 ModContainer (net.minecraftforge.fml.common.ModContainer)1 ModCandidate (net.minecraftforge.fml.common.discovery.ModCandidate)1 ModAnnotation (net.minecraftforge.fml.common.discovery.asm.ModAnnotation)1 EnumHolder (net.minecraftforge.fml.common.discovery.asm.ModAnnotation.EnumHolder)1 ModIdFunction (net.minecraftforge.fml.common.functions.ModIdFunction)1