use of net.minecraftforge.fml.common.discovery.ASMDataTable in project MinecraftForge by MinecraftForge.
the class Loader method setupTestHarness.
/**
* Used to setup a testharness with a single dummy mod instance for use with various testing hooks
* @param containers A list of dummy containers that will be returned as "active" for all queries
*/
public void setupTestHarness(ModContainer... containers) {
modController = new LoadController(this);
mods = Lists.newArrayList(containers);
namedMods = Maps.uniqueIndex(mods, new ModIdFunction());
modController.transition(LoaderState.LOADING, false);
modController.transition(LoaderState.CONSTRUCTING, false);
ObjectHolderRegistry.INSTANCE.findObjectHolders(new ASMDataTable());
modController.forceActiveContainer(containers[0]);
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable in project ForestryMC by ForestryMC.
the class ForestryPluginUtil method getForestryModules.
public static Map<String, List<IForestryModule>> getForestryModules(ASMDataTable asmDataTable) {
List<IForestryModule> instances = getInstances(asmDataTable, ForestryModule.class, IForestryModule.class);
Map<String, List<IForestryModule>> modules = new LinkedHashMap<>();
for (IForestryModule module : instances) {
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
modules.computeIfAbsent(info.containerID(), k -> new ArrayList<>()).add(module);
}
return modules;
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable in project BloodMagic by WayofTime.
the class PluginUtil method gatherPlugins.
@SuppressWarnings("unchecked")
@Nonnull
public static List<Pair<IBloodMagicPlugin, BloodMagicPlugin>> gatherPlugins(ASMDataTable dataTable) {
Stopwatch stopwatch = Stopwatch.createStarted();
List<Pair<IBloodMagicPlugin, BloodMagicPlugin>> discoveredAnnotations = Lists.newArrayList();
Set<ASMDataTable.ASMData> discoveredPlugins = dataTable.getAll(BloodMagicPlugin.class.getName());
for (ASMDataTable.ASMData data : discoveredPlugins) {
try {
Class<?> asmClass = Class.forName(data.getClassName());
Class<? extends IBloodMagicPlugin> pluginClass = asmClass.asSubclass(IBloodMagicPlugin.class);
IBloodMagicPlugin instance = pluginClass.newInstance();
BMLog.API.info("Discovered plugin at {}", data.getClassName());
discoveredAnnotations.add(Pair.of(instance, pluginClass.getAnnotation(BloodMagicPlugin.class)));
} catch (Exception e) {
e.printStackTrace();
}
}
// Bring core plugin up to top
discoveredAnnotations.sort((o1, o2) -> {
if (o1.getLeft().getClass() == BloodMagicCorePlugin.class)
return -1;
return o1.getClass().getCanonicalName().compareToIgnoreCase(o2.getClass().getCanonicalName());
});
BMLog.API.info("Discovered {} potential plugin(s) in {}", discoveredAnnotations.size(), stopwatch.stop());
return discoveredAnnotations;
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable in project RebornCore by TechReborn.
the class RegistrationManager method init.
public static void init(FMLPreInitializationEvent event) {
long start = System.currentTimeMillis();
ASMDataTable asmDataTable = event.getAsmData();
loadFactorys(asmDataTable);
Set<ASMDataTable.ASMData> asmDataSet = asmDataTable.getAll(RebornRegistry.class.getName());
List<ASMDataTable.ASMData> asmDataList = new ArrayList<>(asmDataSet);
asmDataList.sort(Comparator.comparingInt(RegistrationManager::getPriority));
for (ASMDataTable.ASMData data : asmDataList) {
try {
Class clazz = Class.forName(data.getClassName());
if (isEarlyReg(data)) {
handleClass(clazz, null);
continue;
}
registryClasses.add(clazz);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
// Sorts all the classes to (try) and ensure they are loaded in the same oder on the client/server.
// Hopefully this fixes the issue with packets being misaligned
registryClasses.sort(Comparator.comparing(Class::getCanonicalName));
RebornCore.logHelper.info("Pre loaded registries in" + (System.currentTimeMillis() - start) + "ms");
}
use of net.minecraftforge.fml.common.discovery.ASMDataTable in project MinecraftForge by MinecraftForge.
the class AutomaticEventSubscriber method inject.
public static void inject(ModContainer mod, ASMDataTable data, Side side) {
FMLLog.fine("Attempting to inject @EventBusSubscriber classes into the eventbus for %s", mod.getModId());
SetMultimap<String, ASMData> modData = data.getAnnotationsFor(mod);
Set<ASMDataTable.ASMData> mods = modData.get(Mod.class.getName());
Set<ASMDataTable.ASMData> targets = modData.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());
String amodid = (String) targ.getAnnotationInfo().get("modid");
if (Strings.isNullOrEmpty(amodid)) {
amodid = ASMDataTable.getOwnerModID(mods, targ);
if (Strings.isNullOrEmpty(amodid)) {
FMLLog.bigWarning("Could not determine owning mod for @EventBusSubscriber on %s for mod %s", targ.getClassName(), mod.getModId());
continue;
}
}
if (!mod.getModId().equals(amodid)) {
FMLLog.fine("Skipping @EventBusSubscriber injection for %s since it is not for mod %s", targ.getClassName(), mod.getModId());
//We're not injecting this guy
continue;
}
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);
}
}
}
Aggregations