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);
}
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;
}
Aggregations