feat: reload repo on other thread (who knew people had slow hard drives)
This commit is contained in:
@@ -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,8 +42,10 @@ 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()
|
||||||
|
Firmament.coroutineScope.launch {
|
||||||
RepoManager.reload()
|
RepoManager.reload()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
val redownload by button("redownload") {
|
val redownload by button("redownload") {
|
||||||
save()
|
save()
|
||||||
RepoManager.launchAsyncUpdate(true)
|
RepoManager.launchAsyncUpdate(true)
|
||||||
@@ -131,16 +136,12 @@ object RepoManager {
|
|||||||
|
|
||||||
fun reloadForTest(from: Path) {
|
fun reloadForTest(from: Path) {
|
||||||
neuRepo = makeNEURepository(from)
|
neuRepo = makeNEURepository(from)
|
||||||
|
GlobalScope.launch {
|
||||||
reload()
|
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,9 +169,11 @@ object RepoManager {
|
|||||||
if (Config.autoUpdate) {
|
if (Config.autoUpdate) {
|
||||||
launchAsyncUpdate()
|
launchAsyncUpdate()
|
||||||
} else {
|
} else {
|
||||||
|
Firmament.coroutineScope.launch {
|
||||||
reload()
|
reload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (TestUtil.isInTest) {
|
if (TestUtil.isInTest) {
|
||||||
|
|||||||
Reference in New Issue
Block a user