/*
 * The FML Forge Mod Loader suite.
 * Copyright (C) 2012 cpw
 *
 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */
package cpw.mods.fml.common;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;

/**
 * A simple delegating class loader used to load mods into the system
 * 
 * 
 * @author cpw
 *
 */
public class ModClassLoader extends URLClassLoader
{

    public ModClassLoader()
    {
        super(new URL[0], ModClassLoader.class.getClassLoader());
    }

    public void addFile(File modFile) throws MalformedURLException
    {
        URL url = modFile.toURI().toURL();
        super.addURL(url);
    }
    
    public File getParentSource() {
        ClassLoader cl=getParent();
        if (cl instanceof URLClassLoader) {
            URLClassLoader ucl=(URLClassLoader) cl;
            URL pUrl=ucl.getURLs()[0];
            try
            {
                return new File(pUrl.toURI());
            }
            catch (URISyntaxException e)
            {
                // NOOP
            }
        }
        Loader.log.severe("Unable to process our input to locate the minecraft code");
        throw new LoaderException();
    }
}

@@ -821,16 +821,49 @@
 o.File;%0A
+import java.lang.reflect.Method;%0A
 import j
@@ -885,32 +885,32 @@
 edURLException;%0A
-
 import java.net.
@@ -1333,69 +1333,577 @@
     
-URL url = modFile.toURI().toURL();%0A        super.addURL(url);
+ClassLoader cl=getParent();%0A        if (cl instanceof URLClassLoader) %7B%0A            URLClassLoader ucl=(URLClassLoader) cl;%0A            URL url = modFile.toURI().toURL();%0A            try %7B%0A                Method addUrl=URLClassLoader.class.getMethod(%22addUrl%22, URL.class);%0A                addUrl.setAccessible(true);%0A                addUrl.invoke(ucl, url);%0A            %7D catch (Exception e) %7B%0A                Loader.log.severe(%22A fatal error occured attempting to load a file into the classloader%22);%0A                throw new LoaderException(e);%0A            %7D%0A        %7D
 %0A   

Fix package private resolution of fields/methods from base minecraft by loading into minecraft's class loader not our own