Search in sources :

Example 1 with ASMDataTable

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]);
}
Also used : ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) ModIdFunction(net.minecraftforge.fml.common.functions.ModIdFunction)

Example 2 with ASMDataTable

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;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ForestryModule(forestry.api.modules.ForestryModule) Iterator(java.util.Iterator) Map(java.util.Map) ResourceLocation(net.minecraft.util.ResourceLocation) Set(java.util.Set) Log(forestry.core.utils.Log) IForestryModule(forestry.api.modules.IForestryModule) ArrayList(java.util.ArrayList) I18n(net.minecraft.util.text.translation.I18n) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) ForestryModule(forestry.api.modules.ForestryModule) IForestryModule(forestry.api.modules.IForestryModule) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IForestryModule(forestry.api.modules.IForestryModule) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ASMDataTable

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;
}
Also used : ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) IBloodMagicPlugin(WayofTime.bloodmagic.api.IBloodMagicPlugin) BloodMagicPlugin(WayofTime.bloodmagic.api.BloodMagicPlugin) Stopwatch(com.google.common.base.Stopwatch) IBloodMagicPlugin(WayofTime.bloodmagic.api.IBloodMagicPlugin) Pair(org.apache.commons.lang3.tuple.Pair) Nonnull(javax.annotation.Nonnull)

Example 4 with ASMDataTable

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");
}
Also used : ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) ArrayList(java.util.ArrayList)

Example 5 with ASMDataTable

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);
        }
    }
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) Side(net.minecraftforge.fml.relauncher.Side) ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) ASMDataTable(net.minecraftforge.fml.common.discovery.ASMDataTable) ModAnnotation(net.minecraftforge.fml.common.discovery.asm.ModAnnotation) List(java.util.List)

Aggregations

ASMDataTable (net.minecraftforge.fml.common.discovery.ASMDataTable)15 Field (java.lang.reflect.Field)4 ASMData (net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData)4 Stopwatch (com.google.common.base.Stopwatch)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 Nonnull (javax.annotation.Nonnull)2 Property (net.minecraftforge.common.config.Property)2 ModAnnotation (net.minecraftforge.fml.common.discovery.asm.ModAnnotation)2 Side (net.minecraftforge.fml.relauncher.Side)2 Pair (org.apache.commons.lang3.tuple.Pair)2 BloodMagicPlugin (WayofTime.bloodmagic.api.BloodMagicPlugin)1 IBloodMagicPlugin (WayofTime.bloodmagic.api.IBloodMagicPlugin)1 GuideBook (amerifrance.guideapi.api.GuideBook)1 IGuideBook (amerifrance.guideapi.api.IGuideBook)1 Book (amerifrance.guideapi.api.impl.Book)1 INBTData (arekkuusu.solar.api.entanglement.quantum.data.INBTData)1 NBTHolder (arekkuusu.solar.api.entanglement.quantum.data.INBTData.NBTHolder)1 Joiner (com.google.common.base.Joiner)1