Fix ModLoadingContext being a singleton

This commit is contained in:
autaut03 2019-02-13 00:09:24 +02:00
parent d2da5a71e2
commit fe2b5657c5
1 changed files with 17 additions and 14 deletions

View File

@ -7,16 +7,18 @@ import net.minecraftforge.fml.config.ModConfig
import java.util.function.Supplier import java.util.function.Supplier
object FMLKotlinModLoadingContext { object FMLKotlinModLoadingContext {
private val context = ThreadLocal.withInitial { FMLKotlinModLoadingContext } private val context = ThreadLocal.withInitial { Context() }
fun get(): Context {
return context.get()
}
class Context {
var activeContainer: FMLKotlinModContainer? = null var activeContainer: FMLKotlinModContainer? = null
val modEventBus: IEventBus val modEventBus: IEventBus
get() = activeContainer!!.eventBus get() = activeContainer!!.eventBus
fun get(): FMLKotlinModLoadingContext {
return context.get()
}
fun <T> registerExtensionPoint(point: ExtensionPoint<T>, extension: Supplier<T>) { fun <T> registerExtensionPoint(point: ExtensionPoint<T>, extension: Supplier<T>) {
activeContainer!!.registerExtensionPoint(point, extension) activeContainer!!.registerExtensionPoint(point, extension)
} }
@ -28,4 +30,5 @@ object FMLKotlinModLoadingContext {
fun registerConfig(type: ModConfig.Type, spec: ForgeConfigSpec, fileName: String) { fun registerConfig(type: ModConfig.Type, spec: ForgeConfigSpec, fileName: String) {
activeContainer!!.addConfig(ModConfig(type, spec, activeContainer, fileName)) activeContainer!!.addConfig(ModConfig(type, spec, activeContainer, fileName))
} }
}
} }