Java Code Examples for net.minecraftforge.fml.common.discovery.ASMDataTable#getAll()
The following examples show how to use
net.minecraftforge.fml.common.discovery.ASMDataTable#getAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginHelper.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
public static List<CustomStuffPlugin> getPluginInstances(ASMDataTable asmDataTable) { String annotationName = CS4Plugin.class.getCanonicalName(); Set<ASMDataTable.ASMData> asmDatas = asmDataTable.getAll(annotationName); List<CustomStuffPlugin> instances = Lists.newArrayList(); for (ASMDataTable.ASMData asmData : asmDatas) { try { Class<?> asmClass = Class.forName(asmData.getClassName()); if (CustomStuffPlugin.class.isAssignableFrom(asmClass)) { Class<? extends CustomStuffPlugin> instanceClass = asmClass.asSubclass(CustomStuffPlugin.class); CustomStuffPlugin instance = instanceClass.newInstance(); instances.add(instance); } } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { e.printStackTrace(); } } return instances; }
Example 2
Source File: NEIInitialization.java From NotEnoughItems with MIT License | 6 votes |
public static void scrapeData(ASMDataTable dataTable) { ImmutableList.Builder<IConfigureNEI> plugins = ImmutableList.builder(); for (ASMDataTable.ASMData data : dataTable.getAll(NEIPlugin.class.getName())) { try { Class<?> pluginClass = Class.forName(data.getClassName()); if (IConfigureNEI.class.isAssignableFrom(pluginClass)) { IConfigureNEI pluginInstance = (IConfigureNEI) pluginClass.newInstance(); plugins.add(pluginInstance); } else { LogHelper.error("Found class with annotation @NEIPlugin but class does not implement IConfigureNEI.. Class: " + data.getClassName()); } } catch (Exception e) { LogHelper.fatalError("Fatal exception occurred whilst loading a plugin! Class: %s", e, data.getClassName()); } } NEIInitialization.plugins = plugins.build(); }
Example 3
Source File: PluginHandler.java From AgriCraft with MIT License | 6 votes |
/** * Loads classes with a specific annotation from an asm data table. * * Borrowed from JEI's source code, which is licensed under the MIT license. * * @param <T> The type of class to load. * @param asm The asm data table to load classes from. * @param anno The annotation marking classes of interest. * @param type The class type to load, as to get around Type erasure. * @return A list of the loaded classes, instantiated. */ @Nonnull private static <T> List<T> getInstances(ASMDataTable asm, Class anno, Class<T> type) { final List<T> instances = new ArrayList<>(); for (ASMDataTable.ASMData asmData : asm.getAll(anno.getCanonicalName())) { try { T instance = Class.forName(asmData.getClassName()).asSubclass(type).newInstance(); instances.add(instance); } catch (ClassNotFoundException | NoClassDefFoundError | IllegalAccessException | InstantiationException e) { AgriCore.getLogger("agricraft-plugins").debug( "%nFailed to load AgriPlugin%n\tOf class: {0}!%n\tFor annotation: {1}!%n\tAs Instanceof: {2}!", asmData.getClassName(), anno.getCanonicalName(), type.getCanonicalName() ); } } return instances; }
Example 4
Source File: TypeVariableHolderHandler.java From OpenModsLib with MIT License | 5 votes |
public void fillAllHolders(ASMDataTable data) { final Map<Field, Class<?>> classTargetToSource = Maps.newHashMap(); final Map<Field, Class<?>> fieldTargetToSource = Maps.newHashMap(); for (ASMData target : data.getAll(TypeVariableHolder.class.getName())) findTargets(target, classTargetToSource, fieldTargetToSource); fillFields(classTargetToSource, fieldTargetToSource); }
Example 5
Source File: ApiFactory.java From OpenModsLib with MIT License | 5 votes |
private static <A> void fillTargetFields(final ApiProviderRegistry<A> registry, ASMDataTable table, Class<? extends Annotation> fieldMarker, Class<A> interfaceMarker) { final ClassInfoCache clsCache = new ClassInfoCache(); final Set<ASMData> targets = table.getAll(fieldMarker.getName()); for (ASMData data : targets) fillTargetField(clsCache, registry, data, interfaceMarker); }