本文整理汇总了Java中net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData方法的典型用法代码示例。如果您正苦于以下问题:Java ASMDataTable.ASMData方法的具体用法?Java ASMDataTable.ASMData怎么用?Java ASMDataTable.ASMData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.fml.common.discovery.ASMDataTable
的用法示例。
在下文中一共展示了ASMDataTable.ASMData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInstancesOfAnnotation
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
public static <T> List<T> getInstancesOfAnnotation(ASMDataTable asmDataTable, Class annotationClass, Class<T> instanceClass) {
String annotationClassName = annotationClass.getCanonicalName();
Set<ASMDataTable.ASMData> asmDatas = asmDataTable.getAll(annotationClassName);
List<T> instances = new ArrayList<>();
for (ASMDataTable.ASMData asmData : asmDatas) {
try {
Class<?> asmClass = Class.forName(asmData.getClassName());
Class<? extends T> asmInstanceClass = asmClass.asSubclass(instanceClass);
T instance = asmInstanceClass.newInstance();
instances.add(instance);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | LinkageError e) {
HarshenCastle.LOGGER.error("Failed to load: {}", asmData.getClassName(), e);
}
}
return instances;
}
示例2: getPluginInstances
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
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;
}
示例3: getClass
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
/**
* @param data The ASMData harvested by FML.
* @return The class referred by this ASMData
*/
public static Class<?> getClass(ASMDataTable.ASMData data)
{
if (cache == null)
cache = Maps.newHashMap();
Class<?> c = null;
try
{
String name = data.getClassName();
if (cache.containsKey(name))
c = cache.get(name);
else
{
c = Class.forName(name);
cache.put(name, c);
}
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
return c;
}
示例4: getClassSafe
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
/**
* @param data The ASMData harvested by FML.
* @return The class referred by this ASMData
*/
public static Class<?> getClassSafe(ASMDataTable.ASMData data) throws ClassNotFoundException
{
if (cache == null)
cache = Maps.newHashMap();
Class<?> c = null;
String name = data.getClassName();
if (cache.containsKey(name))
c = cache.get(name);
else
{
c = Class.forName(name);
cache.put(name, c);
}
return c;
}
示例5: scrapeData
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
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();
}
示例6: registerEvents
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
private static void registerEvents(@Nonnull ASMDataTable dataTable) {
String className = EventRegister.class.getCanonicalName();
Set<ASMDataTable.ASMData> dataSet = new HashSet<>(dataTable.getAll(className));
for (ASMDataTable.ASMData data : dataSet) {
try {
Class clazz = Class.forName(data.getClassName());
if (EventRegister.IOptionalEvent.class.isAssignableFrom(clazz)) {
EventRegister.IOptionalEvent eventActive = (EventRegister.IOptionalEvent) clazz.newInstance();
if (eventActive.isActive()) {
MinecraftForge.EVENT_BUS.register(clazz.newInstance());
}
} else {
MinecraftForge.EVENT_BUS.register(clazz.newInstance());
}
} catch (Exception ignored) {
}
}
}
示例7: getInstances
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
/**
* 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.
*/
private static <T> List<T> getInstances(ASMDataTable asm, Class anno, Class<T> type) {
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;
}
示例8: inject
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
public static void inject(ModContainer mod, ASMDataTable data, Side side)
{
FMLLog.fine("Attempting to inject @EventBusSubscriber classes into the eventbus for %s", mod.getModId());
Set<ASMDataTable.ASMData> targets = data.getAnnotationsFor(mod).get(Mod.EventBusSubscriber.class.getName());
ClassLoader mcl = Loader.instance().getModClassLoader();
for (ASMDataTable.ASMData targ : targets)
{
try
{
//noinspection unchecked
List<ModAnnotation.EnumHolder> sidesEnum = (List<ModAnnotation.EnumHolder>)targ.getAnnotationInfo().get("value");
EnumSet<Side> sides = DEFAULT;
if (sidesEnum != null) {
sides = EnumSet.noneOf(Side.class);
for (ModAnnotation.EnumHolder h: sidesEnum) {
sides.add(Side.valueOf(h.getValue()));
}
}
if (sides == DEFAULT || sides.contains(side)) {
FMLLog.fine("Found @EventBusSubscriber class %s", targ.getClassName());
Class<?> subscriptionTarget = Class.forName(targ.getClassName(), true, mcl);
MinecraftForge.EVENT_BUS.register(subscriptionTarget);
FMLLog.fine("Injected @EventBusSubscriber class %s", targ.getClassName());
}
}
catch (Exception e)
{
FMLLog.log(Level.ERROR, e, "An error occurred trying to load an EventBusSubscriber %s for modid %s", targ.getClassName(), mod.getModId());
throw new LoaderException(e);
}
}
}
示例9: getField
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
public static Field getField(ASMDataTable.ASMData data)
{
try
{
return getClass(data).getField(data.getObjectName());
}
catch (NoSuchFieldException e)
{
return null;
}
}
示例10: addCache
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
public final void addCache(String modid, ASMDataTable.ASMData data)
{
if (modid == null)
modid = ASMDataUtil.getModId(data);
Class<?> clz = ASMDataUtil.getClass(data);
Class<? extends T> type = TypeUtils.getGenericTypeTo(this);
T annotation = ASMDataUtil.getAnnotation(data, type);
Optional<Field> f = Optional.fromNullable(ASMDataUtil.getField(data));
Optional<Object> o = ASMDataUtil.getObject(data);
cache.add(new ASMCache(clz, modid, annotation, o, f));
}
示例11: getInstances
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
public static <T> List<T> getInstances (ASMDataTable asmDataTable, Class<? extends Annotation> annotationClass, Class<T> instanceClass) {
final String annotationClassName = annotationClass.getCanonicalName();
final Set<ASMDataTable.ASMData> asmDatas = asmDataTable.getAll(annotationClassName);
final List<T> instances = new ArrayList<>();
for (final ASMDataTable.ASMData asmData : asmDatas)
try {
instances.add(Class.forName(asmData.getClassName()).asSubclass(instanceClass).newInstance());
}
catch (final Exception e) {
MMDLib.LOG.error("Failed to load: {}", asmData.getClassName(), e);
}
return instances;
}
示例12: registerCommands
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
public static void registerCommands(@Nonnull ASMDataTable asmDataTable) {
String annotationClassName = Command.class.getCanonicalName();
Set<ASMData> asmDatas = new HashSet<ASMData>(asmDataTable.getAll(annotationClassName));
for (ASMDataTable.ASMData asmData : asmDatas) {
try {
Class<?> asmClass = Class.forName(asmData.getClassName());
Class<? extends AbstractCommand> asmInstanceClass = asmClass.asSubclass(AbstractCommand.class);
AbstractCommand instance = asmInstanceClass.newInstance();
CommandManager.INSTANCE.registerCommand(instance);
} catch (Exception e) { e.printStackTrace(); }
}
}
示例13: fetchPlugins
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
private <T> List<T> fetchPlugins(ASMDataTable asmDataTable, Class annotationClass, Class<T> instanceClass){
String annotationClassName = annotationClass.getCanonicalName();
Set<ASMDataTable.ASMData> asmDatas = asmDataTable.getAll(annotationClassName);
List<T> instances = new ArrayList<>();
for (ASMDataTable.ASMData asmData : asmDatas)
try {
Class<?> asmClass = Class.forName(asmData.getClassName());
Class<? extends T> asmInstanceClass = asmClass.asSubclass(instanceClass);
T instance = asmInstanceClass.newInstance();
instances.add(instance);
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
ACLogger.severe("Failed to load: {}", asmData.getClassName(), e);
}
return instances;
}
示例14: getModId
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
/**
* @param data The ASMData harvested by FML.
* @return The mod's id of the ASMData referring to.
*/
public static String getModId(ASMDataTable.ASMData data)
{
return data.getCandidate().getContainedMods().get(0).getModId();
}
示例15: getAnnotations
import net.minecraftforge.fml.common.discovery.ASMDataTable; //导入方法依赖的package包/类
/**
* 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(e, "Could not load class {}", asmData.getClassName());
}
}
return map;
}