diff options
author | nea <romangraef@gmail.com> | 2022-08-03 02:31:05 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-08-03 02:31:05 +0200 |
commit | 2625eeb7dedb05b524b08721e1267acdcd93e5c1 (patch) | |
tree | 476117af52a76f22c445b8b8dac4778f24ce5c51 /src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt | |
parent | b9455467863f194accf30a89b2c2998822f2c105 (diff) | |
download | Firmament-2625eeb7dedb05b524b08721e1267acdcd93e5c1.tar.gz Firmament-2625eeb7dedb05b524b08721e1267acdcd93e5c1.tar.bz2 Firmament-2625eeb7dedb05b524b08721e1267acdcd93e5c1.zip |
scuffed config screen
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt index f3d53e8..70ee18e 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt @@ -2,29 +2,59 @@ package moe.nea.notenoughupdates.repo import io.github.moulberry.repo.NEURepository import kotlinx.coroutines.launch +import kotlinx.serialization.Serializable +import kotlinx.serialization.serializer import moe.nea.notenoughupdates.NotEnoughUpdates import moe.nea.notenoughupdates.NotEnoughUpdates.logger +import moe.nea.notenoughupdates.util.ConfigHolder +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.minecraft.client.Minecraft import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket -object RepoManager { +object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Config) { + @Serializable + data class Config( + var user: String = "NotEnoughUpdates", + var repo: String = "NotEnoughUpdates-REPO", + var autoUpdate: Boolean = true, + var branch: String = "dangerous", + ) + var recentlyFailedToUpdateItemList = false val neuRepo: NEURepository = NEURepository.of(RepoDownloadManager.repoSavedLocation).apply { registerReloadListener(ItemCache) registerReloadListener { - if (Minecraft.getInstance().connection?.handleUpdateRecipes(ClientboundUpdateRecipesPacket(mutableListOf())) == null) { + if (!trySendClientboundUpdateRecipesPacket()) { logger.warn("Failed to issue a ClientboundUpdateRecipesPacket (to reload REI). This may lead to an outdated item list.") + recentlyFailedToUpdateItemList = true } } } + private fun trySendClientboundUpdateRecipesPacket(): Boolean { + return Minecraft.getInstance().level != null && Minecraft.getInstance().connection?.handleUpdateRecipes(ClientboundUpdateRecipesPacket(mutableListOf())) != null + } + + init { + ClientTickEvents.START_WORLD_TICK.register(ClientTickEvents.StartWorldTick { + if (recentlyFailedToUpdateItemList && trySendClientboundUpdateRecipesPacket()) + recentlyFailedToUpdateItemList = false + }) + } fun launchAsyncUpdate() { NotEnoughUpdates.coroutineScope.launch { - if (RepoDownloadManager.downloadUpdate()) { - neuRepo.reload() - } + RepoDownloadManager.downloadUpdate() + neuRepo.reload() + } + } + + fun initialize() { + if (config.autoUpdate) { + launchAsyncUpdate() + } else { + neuRepo.reload() } } |