Skip to content

Commit

Permalink
Fix concurrently getting ModLoadingContext
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSpring committed Dec 30, 2024
1 parent 163c056 commit 7cda8c0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/kotlin/net/minecraftforge/fml/ModLoadingContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,19 @@ open class ModLoadingContext(protected val mod: ForgeMod) {
return get(source).activeContainer
}

// TODO: actually handle multithreading this properly
@JvmStatic
fun get(): ModLoadingContext {
if (kiltActiveModId != null) {
if (!contexts.contains(kiltActiveModId)) {
val mod = Kilt.loader.getMod(kiltActiveModId!!) ?: throw Exception("Kilt has not finished loading mods yet!")
contexts[kiltActiveModId!!] = ModLoadingContext(mod)
// ensure the mod ID doesn't get overwritten at the exact same time
val modId = kiltActiveModId

if (modId != null) {
if (!contexts.contains(modId)) {
val mod = Kilt.loader.getMod(modId) ?: throw Exception("Kilt has not finished loading mods yet!")
contexts[modId] = ModLoadingContext(mod)
}

return contexts[kiltActiveModId]!!
return contexts[modId]!!
}

return getForgeContext()
Expand Down

0 comments on commit 7cda8c0

Please sign in to comment.