Search in sources :

Example 1 with ASMData

use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.

the class ForgeModContainer method modConstruction.

@Subscribe
public void modConstruction(FMLConstructionEvent evt) {
    List<String> all = Lists.newArrayList();
    for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashReportDetail.class.getName().replace('.', '/'))) all.add(asm.getClassName());
    for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/'))) all.add(asm.getClassName());
    Iterator<String> itr = all.iterator();
    while (itr.hasNext()) {
        String cls = itr.next();
        if (!cls.startsWith("net/minecraft/") && !cls.startsWith("net/minecraftforge/"))
            itr.remove();
    }
    FMLLog.log(ForgeVersion.MOD_ID, Level.DEBUG, "Preloading CrashReport Classes");
    //Sort it because I like pretty output ;)
    Collections.sort(all);
    for (String name : all) {
        FMLLog.log(ForgeVersion.MOD_ID, Level.DEBUG, "\t" + name);
        try {
            Class.forName(name.replace('/', '.'), false, MinecraftForge.class.getClassLoader());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    NetworkRegistry.INSTANCE.register(this, this.getClass(), "*", evt.getASMHarvestedData());
    ForgeNetworkHandler.registerChannel(this, evt.getSide());
    ConfigManager.load(this.getModId(), Config.Type.INSTANCE);
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) MalformedURLException(java.net.MalformedURLException) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with ASMData

use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.

the class ModAPIManager method registerDataTableAndParseAPI.

public void registerDataTableAndParseAPI(ASMDataTable dataTable) {
    this.dataTable = dataTable;
    Set<ASMData> apiList = dataTable.getAll("net.minecraftforge.fml.common.API");
    apiContainers = Maps.newHashMap();
    for (ASMData data : apiList) {
        Map<String, Object> annotationInfo = data.getAnnotationInfo();
        String apiPackage = data.getClassName().substring(0, data.getClassName().indexOf(".package-info"));
        String providedAPI = (String) annotationInfo.get("provides");
        String apiOwner = (String) annotationInfo.get("owner");
        String apiVersion = (String) annotationInfo.get("apiVersion");
        APIContainer container = apiContainers.get(providedAPI);
        if (container == null) {
            container = new APIContainer(providedAPI, apiVersion, data.getCandidate().getModContainer(), VersionParser.parseVersionReference(apiOwner));
            apiContainers.put(providedAPI, container);
        } else {
            container.validate(providedAPI, apiOwner, apiVersion);
        }
        container.addOwnedPackage(apiPackage);
        for (ModContainer mc : data.getCandidate().getContainedMods()) {
            String embeddedIn = mc.getModId();
            if (container.currentReferents.contains(embeddedIn)) {
                continue;
            }
            FMLLog.fine("Found API %s (owned by %s providing %s) embedded in %s", apiPackage, apiOwner, providedAPI, embeddedIn);
            if (!embeddedIn.equals(apiOwner)) {
                container.addAPIReference(embeddedIn);
            }
        }
    }
    for (APIContainer container : apiContainers.values()) {
        for (String pkg : container.packages) {
            Set<ModCandidate> candidates = dataTable.getCandidatesFor(pkg);
            for (ModCandidate candidate : candidates) {
                List<String> candidateIds = Lists.transform(candidate.getContainedMods(), new ModIdFunction());
                if (!candidateIds.contains(container.ownerMod.getLabel()) && !container.currentReferents.containsAll(candidateIds)) {
                    FMLLog.info("Found mod(s) %s containing declared API package %s (owned by %s) without associated API reference", candidateIds, pkg, container.ownerMod);
                    container.addAPIReferences(candidateIds);
                }
            }
        }
        if (apiContainers.containsKey(container.ownerMod.getLabel())) {
            ArtifactVersion owner = container.ownerMod;
            do {
                APIContainer parent = apiContainers.get(owner.getLabel());
                if (parent == container) {
                    FMLLog.finer("APIContainer %s is it's own parent. skipping", owner);
                    container.markSelfReferenced();
                    break;
                }
                FMLLog.finer("Removing upstream parent %s from %s", parent.ownerMod.getLabel(), container);
                container.currentReferents.remove(parent.ownerMod.getLabel());
                container.referredMods.remove(parent.ownerMod);
                owner = parent.ownerMod;
            } while (apiContainers.containsKey(owner.getLabel()));
        }
        FMLLog.fine("Creating API container dummy for API %s: owner: %s, dependents: %s", container.providedAPI, container.ownerMod, container.referredMods);
    }
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) DefaultArtifactVersion(net.minecraftforge.fml.common.versioning.DefaultArtifactVersion) ArtifactVersion(net.minecraftforge.fml.common.versioning.ArtifactVersion) ModCandidate(net.minecraftforge.fml.common.discovery.ModCandidate) ModIdFunction(net.minecraftforge.fml.common.functions.ModIdFunction)

Example 3 with ASMData

use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.

the class ModAPITransformer method unpackInterfaces.

private Set<ASMData> unpackInterfaces(Set<ASMData> packedInterfaces) {
    Set<ASMData> result = Sets.newHashSet();
    for (ASMData data : packedInterfaces) {
        @SuppressWarnings("unchecked") List<Map<String, Object>> packedList = (List<Map<String, Object>>) data.getAnnotationInfo().get("value");
        for (Map<String, Object> packed : packedList) {
            ASMData newData = data.copy(packed);
            result.add(newData);
        }
    }
    return result;
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) List(java.util.List) Map(java.util.Map)

Example 4 with ASMData

use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.

the class ProxyInjector method inject.

public static void inject(ModContainer mod, ASMDataTable data, Side side, ILanguageAdapter languageAdapter) {
    FMLLog.fine("Attempting to inject @SidedProxy classes into %s", mod.getModId());
    SetMultimap<String, ASMData> modData = data.getAnnotationsFor(mod);
    Set<ASMData> mods = modData.get(Mod.class.getName());
    Set<ASMData> targets = modData.get(SidedProxy.class.getName());
    ClassLoader mcl = Loader.instance().getModClassLoader();
    for (ASMData targ : targets) {
        try {
            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 @SidedProxy on %s for mod %s", targ.getClassName(), mod.getModId());
                    continue;
                }
            }
            if (!mod.getModId().equals(amodid)) {
                FMLLog.fine("Skipping proxy injection for %s.%s since it is not for mod %s", targ.getClassName(), targ.getObjectName(), mod.getModId());
                continue;
            }
            Class<?> proxyTarget = Class.forName(targ.getClassName(), true, mcl);
            Field target = proxyTarget.getDeclaredField(targ.getObjectName());
            if (target == null) {
                // Impossible?
                FMLLog.severe("Attempted to load a proxy type into %s.%s but the field was not found", targ.getClassName(), targ.getObjectName());
                throw new LoaderException(String.format("Attempted to load a proxy type into %s.%s but the field was not found", targ.getClassName(), targ.getObjectName()));
            }
            target.setAccessible(true);
            SidedProxy annotation = target.getAnnotation(SidedProxy.class);
            String targetType = side.isClient() ? annotation.clientSide() : annotation.serverSide();
            if (targetType.equals("")) {
                targetType = targ.getClassName() + (side.isClient() ? "$ClientProxy" : "$ServerProxy");
            }
            Object proxy = Class.forName(targetType, true, mcl).newInstance();
            if (languageAdapter.supportsStatics() && (target.getModifiers() & Modifier.STATIC) == 0) {
                FMLLog.severe("Attempted to load a proxy type %s into %s.%s, but the field is not static", targetType, targ.getClassName(), targ.getObjectName());
                throw new LoaderException(String.format("Attempted to load a proxy type %s into %s.%s, but the field is not static", targetType, targ.getClassName(), targ.getObjectName()));
            }
            if (!target.getType().isAssignableFrom(proxy.getClass())) {
                FMLLog.severe("Attempted to load a proxy type %s into %s.%s, but the types don't match", targetType, targ.getClassName(), targ.getObjectName());
                throw new LoaderException(String.format("Attempted to load a proxy type %s into %s.%s, but the types don't match", targetType, targ.getClassName(), targ.getObjectName()));
            }
            languageAdapter.setProxy(target, proxyTarget, proxy);
        } catch (Exception e) {
            FMLLog.log(Level.ERROR, e, "An error occurred trying to load a proxy into %s.%s", targ.getAnnotationInfo(), targ.getClassName(), targ.getObjectName());
            throw new LoaderException(e);
        }
    }
    // Allow language specific proxy injection.
    languageAdapter.setInternalProxies(mod, side, mcl);
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) Field(java.lang.reflect.Field)

Example 5 with ASMData

use of net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData in project MinecraftForge by MinecraftForge.

the class MinecraftForge method preloadCrashClasses.

public static void preloadCrashClasses(ASMDataTable table, String modID, Set<String> classes) {
    //Find all ICrashReportDetail's handlers and preload them.
    List<String> all = Lists.newArrayList();
    for (ASMData asm : table.getAll(ICrashReportDetail.class.getName().replace('.', '/'))) all.add(asm.getClassName());
    for (ASMData asm : table.getAll(ICrashCallable.class.getName().replace('.', '/'))) all.add(asm.getClassName());
    all.retainAll(classes);
    if (all.size() == 0)
        return;
    FMLLog.log(modID, Level.DEBUG, "Preloading CrashReport Classes");
    //Sort it because I like pretty output ;)
    Collections.sort(all);
    for (String name : all) {
        FMLLog.log(modID, Level.DEBUG, "\t" + name);
        try {
            Class.forName(name.replace('/', '.'), false, MinecraftForge.class.getClassLoader());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData)

Aggregations

ASMData (net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData)12 Field (java.lang.reflect.Field)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 ASMDataTable (net.minecraftforge.fml.common.discovery.ASMDataTable)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 Subscribe (com.google.common.eventbus.Subscribe)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LoaderException (net.minecraftforge.fml.common.LoaderException)1 ModContainer (net.minecraftforge.fml.common.ModContainer)1 ModCandidate (net.minecraftforge.fml.common.discovery.ModCandidate)1 ModAnnotation (net.minecraftforge.fml.common.discovery.asm.ModAnnotation)1 EnumHolder (net.minecraftforge.fml.common.discovery.asm.ModAnnotation.EnumHolder)1 ModIdFunction (net.minecraftforge.fml.common.functions.ModIdFunction)1