package codechicken.lib.asm;

import net.minecraftforge.fml.relauncher.IFMLCallHook;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Map;

@TransformerExclusions({ "codechicken.lib.asm", "codechicken.lib.config" })
public class CCLCorePlugin implements IFMLLoadingPlugin , IFMLCallHook{

    public static Logger logger = LogManager.getLogger("CodeChicken Lib");

    @Override
    public String[] getASMTransformerClass() {
        return new String[] { "codechicken.lib.asm.ClassHeirachyManager", "codechicken.lib.asm.BlockStateLoaderTransformer" };
    }

    @Override
    public String getModContainerClass() {
        return null;
    }

    @Override
    public String getSetupClass() {
        return getClass().getName();
    }

    @Override
    public void injectData(Map<String, Object> data) {

    }

    @Override
    public String getAccessTransformerClass() {
        return null;
    }

    @Override
    public Void call() throws Exception {
        new ASMHelper();
        return null;
    }
}

@@ -23,16 +23,118 @@
 b.asm;%0A%0A
+import net.minecraft.launchwrapper.Launch;%0Aimport net.minecraftforge.fml.relauncher.FMLInjectionData;%0A
 import n
@@ -423,16 +423,179 @@
 ava.
-util.Map
+io.File;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.jar.Attributes;%0Aimport java.util.jar.JarFile;%0Aimport java.util.jar.Manifest
 ;%0A%0A@
@@ -1415,16 +1415,36 @@
 ption %7B%0A
+        scanMods();%0A
         
@@ -1486,11 +1486,1543 @@
 l;%0A    %7D
+%0A%0A    private void scanMods() %7B%0A        File modsDir = new File((File) FMLInjectionData.data()%5B6%5D, %22mods%22);%0A        for (File file : modsDir.listFiles()) %7B%0A            scanMod(file);%0A        %7D%0A        File versionModsDir = new File(modsDir, (String) FMLInjectionData.data()%5B4%5D);%0A        if (versionModsDir.exists()) %7B%0A            for (File file : versionModsDir.listFiles()) %7B%0A                scanMod(file);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private void scanMod(File file) %7B%0A        if (!file.getName().endsWith(%22.jar%22) && !file.getName().endsWith(%22.zip%22)) %7B%0A            return;%0A        %7D%0A%0A        try %7B%0A            JarFile jar = new JarFile(file);%0A            try %7B%0A                Manifest manifest = jar.getManifest();%0A                if (manifest == null) %7B%0A                    return;%0A                %7D%0A                Attributes attr = manifest.getMainAttributes();%0A                if (attr == null) %7B%0A                    return;%0A                %7D%0A%0A                String transformer = attr.getValue(%22CCTransformerExclusions%22);%0A                if (transformer != null) %7B%0A                    List%3CString%3E exclusions = Arrays.asList(transformer.split(%22,%22));%0A                    for (String ex : exclusions) %7B%0A                        Launch.classLoader.addTransformerExclusion(ex);%0A                    %7D%0A                %7D%0A            %7D finally %7B%0A                jar.close();%0A            %7D%0A        %7D catch (Exception e) %7B%0A            logger.error(%22CodeChickenLib: Failed to read jar file: %22 + file.getName(), e);%0A        %7D%0A    %7D
 %0A%7D%0A

Add ability for mods to define ClassTransformer exclusions inside their manifest.