Search in sources :

Example 1 with ModClassLoader

use of net.minecraftforge.fml.common.ModClassLoader in project SpongeForge by SpongePowered.

the class SpongeModPluginContainer method constructMod.

@Subscribe
public void constructMod(FMLConstructionEvent event) {
    try {
        if (this.invalid) {
            throw new InvalidPluginException();
        }
        // Add source file to classloader so we can load it.
        ModClassLoader modClassLoader = event.getModClassLoader();
        modClassLoader.addFile(getSource());
        modClassLoader.clearNegativeCacheFor(this.candidate.getClassList());
        Class<?> pluginClazz = Class.forName(this.className, true, modClassLoader);
        Injector injector = spongeInjector.getParent().createChildInjector(new PluginModule((PluginContainer) this, pluginClazz));
        this.injector = injector;
        this.instance = injector.getInstance(pluginClazz);
        // TODO: Detect Scala or use meta to know if we're scala and use proper adapter here...
        ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), new ILanguageAdapter.JavaAdapter());
        Sponge.getEventManager().registerListeners(this, this.instance);
    } catch (Throwable t) {
        this.controller.errorOccurred(this, t);
    }
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ModClassLoader(net.minecraftforge.fml.common.ModClassLoader) ProxyInjector(net.minecraftforge.fml.common.ProxyInjector) Injector(com.google.inject.Injector) ILanguageAdapter(net.minecraftforge.fml.common.ILanguageAdapter) PluginModule(org.spongepowered.common.inject.plugin.PluginModule) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)1 Injector (com.google.inject.Injector)1 ILanguageAdapter (net.minecraftforge.fml.common.ILanguageAdapter)1 ModClassLoader (net.minecraftforge.fml.common.ModClassLoader)1 ProxyInjector (net.minecraftforge.fml.common.ProxyInjector)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1 PluginModule (org.spongepowered.common.inject.plugin.PluginModule)1