aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/repo
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-08-04 04:26:51 +0200
committernea <romangraef@gmail.com>2022-08-04 04:26:51 +0200
commit05a4a5b3817ea3e70662d3834fd56a1b249fa70e (patch)
treea02169948679be5a748a3255e99738133bf8f83c /src/main/kotlin/moe/nea/notenoughupdates/repo
parentc83890afc8304fc0a1b1d0ea8da791c6d9b90439 (diff)
downloadfirmament-05a4a5b3817ea3e70662d3834fd56a1b249fa70e.tar.gz
firmament-05a4a5b3817ea3e70662d3834fd56a1b249fa70e.tar.bz2
firmament-05a4a5b3817ea3e70662d3834fd56a1b249fa70e.zip
screen padding
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/repo')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt13
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt27
2 files changed, 34 insertions, 6 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt
index 893b1c0..8deb4c3 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/ItemCache.kt
@@ -4,6 +4,8 @@ import com.mojang.serialization.Dynamic
import io.github.moulberry.repo.IReloadable
import io.github.moulberry.repo.NEURepository
import io.github.moulberry.repo.data.NEUItem
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.launch
import moe.nea.notenoughupdates.NotEnoughUpdates
import moe.nea.notenoughupdates.util.LegacyTagParser
import moe.nea.notenoughupdates.util.appendLore
@@ -70,7 +72,18 @@ object ItemCache : IReloadable {
ResourceLocation("skyblockitem", skyblockItemId.lowercase().replace(";", "__"))
+ var job: Job? = null
+
override fun reload(repository: NEURepository) {
cache.clear()
+ val j = job
+ if (j != null && j.isActive) {
+ j.cancel()
+ job = NotEnoughUpdates.coroutineScope.launch {
+ repository.items?.items?.values?.forEach {
+ it.asItemStack() // Rebuild cache
+ }
+ }
+ }
}
}
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt
index 70ee18e..375b2bb 100644
--- a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt
+++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt
@@ -1,6 +1,7 @@
package moe.nea.notenoughupdates.repo
import io.github.moulberry.repo.NEURepository
+import io.github.moulberry.repo.NEURepositoryException
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
@@ -9,15 +10,16 @@ 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.chat.Component
import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket
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 user: String = "NotEnoughUpdates",
+ var repo: String = "NotEnoughUpdates-REPO",
+ var autoUpdate: Boolean = true,
+ var branch: String = "dangerous",
)
var recentlyFailedToUpdateItemList = false
@@ -33,7 +35,9 @@ object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Co
}
private fun trySendClientboundUpdateRecipesPacket(): Boolean {
- return Minecraft.getInstance().level != null && Minecraft.getInstance().connection?.handleUpdateRecipes(ClientboundUpdateRecipesPacket(mutableListOf())) != null
+ return Minecraft.getInstance().level != null && Minecraft.getInstance().connection?.handleUpdateRecipes(
+ ClientboundUpdateRecipesPacket(mutableListOf())
+ ) != null
}
init {
@@ -46,7 +50,18 @@ object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Co
fun launchAsyncUpdate() {
NotEnoughUpdates.coroutineScope.launch {
RepoDownloadManager.downloadUpdate()
+ reload()
+ }
+ }
+
+ fun reload() {
+ try {
neuRepo.reload()
+ } catch (exc: NEURepositoryException) {
+ Minecraft.getInstance().player?.sendSystemMessage(
+ Component.literal("Failed to reload repository. This will result in some mod features not working.")
+ )
+ exc.printStackTrace()
}
}
@@ -54,7 +69,7 @@ object RepoManager : ConfigHolder<RepoManager.Config>(serializer(), "repo", ::Co
if (config.autoUpdate) {
launchAsyncUpdate()
} else {
- neuRepo.reload()
+ reload()
}
}