feat: reload repo on other thread (who knew people had slow hard drives)

This commit is contained in:
Linnea Gräf
2025-07-07 12:48:26 +02:00
parent 5ead6193b4
commit 8e4e349963

View File

@@ -7,7 +7,10 @@ import io.github.moulberry.repo.data.NEURecipe
import io.github.moulberry.repo.data.Rarity import io.github.moulberry.repo.data.Rarity
import java.nio.file.Path import java.nio.file.Path
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.minecraft.client.MinecraftClient import net.minecraft.client.MinecraftClient
import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket
import net.minecraft.recipe.display.CuttingRecipeDisplay import net.minecraft.recipe.display.CuttingRecipeDisplay
@@ -39,7 +42,9 @@ object RepoManager {
val disableItemGroups by toggle("disable-item-groups") { true } val disableItemGroups by toggle("disable-item-groups") { true }
val reload by button("reload") { val reload by button("reload") {
save() save()
RepoManager.reload() Firmament.coroutineScope.launch {
RepoManager.reload()
}
} }
val redownload by button("redownload") { val redownload by button("redownload") {
save() save()
@@ -131,16 +136,12 @@ object RepoManager {
fun reloadForTest(from: Path) { fun reloadForTest(from: Path) {
neuRepo = makeNEURepository(from) neuRepo = makeNEURepository(from)
reload() GlobalScope.launch {
reload()
}
} }
fun reload() { suspend fun reload() = withContext(Dispatchers.Default) {
if (!TestUtil.isInTest && !MC.instance.isOnThread) {
MC.instance.send {
reload()
}
return
}
try { try {
logger.info("Repo reload started.") logger.info("Repo reload started.")
neuRepo.reload() neuRepo.reload()
@@ -168,7 +169,9 @@ object RepoManager {
if (Config.autoUpdate) { if (Config.autoUpdate) {
launchAsyncUpdate() launchAsyncUpdate()
} else { } else {
reload() Firmament.coroutineScope.launch {
reload()
}
} }
} }