类net.minecraftforge.fml.common.discovery.ASMDataTable源码实例Demo

下面列出了怎么用net.minecraftforge.fml.common.discovery.ASMDataTable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: customstuff4   文件: PluginHelper.java
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;
}
 
源代码2 项目: NotEnoughItems   文件: NEIInitialization.java
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();

}
 
源代码3 项目: AgriCraft   文件: PluginHandler.java
/**
 * 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;
}
 
源代码4 项目: OpenModsLib   文件: TypeVariableHolderHandler.java
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);
}
 
源代码5 项目: OpenModsLib   文件: ApiFactory.java
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);
}
 
源代码6 项目: OpenModsLib   文件: ApiFactory.java
public <A> ApiProviderRegistry<A> createApi(Class<? extends Annotation> fieldMarker, Class<A> interfaceMarker, ASMDataTable table, ApiProviderSetup<A> registrySetup) {
	Preconditions.checkState(apis.add(fieldMarker), "Duplicate API registration on %s", fieldMarker);

	final ApiProviderRegistry<A> registry = new ApiProviderRegistry<>(interfaceMarker);
	registrySetup.setup(registry);
	registry.freeze();

	fillTargetFields(registry, table, fieldMarker, interfaceMarker);

	return registry;
}
 
源代码7 项目: customstuff4   文件: CustomStuff4.java
private void initPlugins(ASMDataTable asmDataTable)
{
    plugins = PluginHelper.getPluginInstances(asmDataTable);
    plugins.forEach(plugin -> plugin.registerContent(contentRegistry));
}
 
源代码8 项目: OpenModsLib   文件: ApiFactory.java
public <A> void createApi(Class<? extends Annotation> fieldMarker, Class<A> interfaceMarker, ASMDataTable table, ApiProviderRegistry<A> registry) {
	Preconditions.checkState(apis.add(fieldMarker), "Duplicate API registration on %s", fieldMarker);

	Preconditions.checkState(registry.isFrozen(), "Registry must be frozen");
	fillTargetFields(registry, table, fieldMarker, interfaceMarker);
}
 
源代码9 项目: OpenModsLib   文件: ClassSourceCollector.java
public ClassSourceCollector(ASMDataTable table) {
	this.table = table;
}
 
 类方法
 同包方法