Add YACL config menu
This commit is contained in:
@@ -19,127 +19,129 @@ import moe.nea.firmament.util.MinecraftDispatcher
|
||||
import moe.nea.firmament.util.SkyblockId
|
||||
|
||||
object RepoManager {
|
||||
object Config : ManagedConfig("repo") {
|
||||
var username by string("username") { "NotEnoughUpdates" }
|
||||
var reponame by string("reponame") { "NotEnoughUpdates-REPO" }
|
||||
var branch by string("branch") { "master" }
|
||||
val autoUpdate by toggle("autoUpdate") { true }
|
||||
val reset by button("reset") {
|
||||
username = "NotEnoughUpdates"
|
||||
reponame = "NotEnoughUpdates-REPO"
|
||||
branch = "master"
|
||||
save()
|
||||
}
|
||||
object Config : ManagedConfig("repo") {
|
||||
var username by string("username") { "NotEnoughUpdates" }
|
||||
var reponame by string("reponame") { "NotEnoughUpdates-REPO" }
|
||||
var branch by string("branch") { "master" }
|
||||
val autoUpdate by toggle("autoUpdate") { true }
|
||||
val reset by button("reset") {
|
||||
username = "NotEnoughUpdates"
|
||||
reponame = "NotEnoughUpdates-REPO"
|
||||
branch = "master"
|
||||
save()
|
||||
}
|
||||
|
||||
val disableItemGroups by toggle("disable-item-groups") { true }
|
||||
val reload by button("reload") {
|
||||
save()
|
||||
RepoManager.reload()
|
||||
}
|
||||
val redownload by button("redownload") {
|
||||
save()
|
||||
RepoManager.launchAsyncUpdate(true)
|
||||
}
|
||||
}
|
||||
val enableYacl by toggle("enable-yacl") { false }
|
||||
|
||||
val currentDownloadedSha by RepoDownloadManager::latestSavedVersionHash
|
||||
val disableItemGroups by toggle("disable-item-groups") { true }
|
||||
val reload by button("reload") {
|
||||
save()
|
||||
RepoManager.reload()
|
||||
}
|
||||
val redownload by button("redownload") {
|
||||
save()
|
||||
RepoManager.launchAsyncUpdate(true)
|
||||
}
|
||||
}
|
||||
|
||||
var recentlyFailedToUpdateItemList = false
|
||||
val currentDownloadedSha by RepoDownloadManager::latestSavedVersionHash
|
||||
|
||||
val neuRepo: NEURepository = NEURepository.of(RepoDownloadManager.repoSavedLocation).apply {
|
||||
registerReloadListener(ItemCache)
|
||||
registerReloadListener(ExpLadders)
|
||||
registerReloadListener(ItemNameLookup)
|
||||
ReloadRegistrationEvent.publish(ReloadRegistrationEvent(this))
|
||||
registerReloadListener {
|
||||
Firmament.coroutineScope.launch(MinecraftDispatcher) {
|
||||
if (!trySendClientboundUpdateRecipesPacket()) {
|
||||
logger.warn("Failed to issue a ClientboundUpdateRecipesPacket (to reload REI). This may lead to an outdated item list.")
|
||||
recentlyFailedToUpdateItemList = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var recentlyFailedToUpdateItemList = false
|
||||
|
||||
val essenceRecipeProvider = EssenceRecipeProvider()
|
||||
val recipeCache = BetterRepoRecipeCache(essenceRecipeProvider)
|
||||
val neuRepo: NEURepository = NEURepository.of(RepoDownloadManager.repoSavedLocation).apply {
|
||||
registerReloadListener(ItemCache)
|
||||
registerReloadListener(ExpLadders)
|
||||
registerReloadListener(ItemNameLookup)
|
||||
ReloadRegistrationEvent.publish(ReloadRegistrationEvent(this))
|
||||
registerReloadListener {
|
||||
Firmament.coroutineScope.launch(MinecraftDispatcher) {
|
||||
if (!trySendClientboundUpdateRecipesPacket()) {
|
||||
logger.warn("Failed to issue a ClientboundUpdateRecipesPacket (to reload REI). This may lead to an outdated item list.")
|
||||
recentlyFailedToUpdateItemList = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
neuRepo.registerReloadListener(essenceRecipeProvider)
|
||||
neuRepo.registerReloadListener(recipeCache)
|
||||
}
|
||||
val essenceRecipeProvider = EssenceRecipeProvider()
|
||||
val recipeCache = BetterRepoRecipeCache(essenceRecipeProvider)
|
||||
|
||||
fun getAllRecipes() = neuRepo.items.items.values.asSequence().flatMap { it.recipes }
|
||||
init {
|
||||
neuRepo.registerReloadListener(essenceRecipeProvider)
|
||||
neuRepo.registerReloadListener(recipeCache)
|
||||
}
|
||||
|
||||
fun getRecipesFor(skyblockId: SkyblockId): Set<NEURecipe> = recipeCache.recipes[skyblockId] ?: setOf()
|
||||
fun getUsagesFor(skyblockId: SkyblockId): Set<NEURecipe> = recipeCache.usages[skyblockId] ?: setOf()
|
||||
fun getAllRecipes() = neuRepo.items.items.values.asSequence().flatMap { it.recipes }
|
||||
|
||||
private fun trySendClientboundUpdateRecipesPacket(): Boolean {
|
||||
return MinecraftClient.getInstance().world != null && MinecraftClient.getInstance().networkHandler?.onSynchronizeRecipes(
|
||||
SynchronizeRecipesS2CPacket(mutableListOf())
|
||||
) != null
|
||||
}
|
||||
fun getRecipesFor(skyblockId: SkyblockId): Set<NEURecipe> = recipeCache.recipes[skyblockId] ?: setOf()
|
||||
fun getUsagesFor(skyblockId: SkyblockId): Set<NEURecipe> = recipeCache.usages[skyblockId] ?: setOf()
|
||||
|
||||
init {
|
||||
ClientTickEvents.START_WORLD_TICK.register(ClientTickEvents.StartWorldTick {
|
||||
if (recentlyFailedToUpdateItemList && trySendClientboundUpdateRecipesPacket())
|
||||
recentlyFailedToUpdateItemList = false
|
||||
})
|
||||
}
|
||||
private fun trySendClientboundUpdateRecipesPacket(): Boolean {
|
||||
return MinecraftClient.getInstance().world != null && MinecraftClient.getInstance().networkHandler?.onSynchronizeRecipes(
|
||||
SynchronizeRecipesS2CPacket(mutableListOf())
|
||||
) != null
|
||||
}
|
||||
|
||||
fun getNEUItem(skyblockId: SkyblockId): NEUItem? = neuRepo.items.getItemBySkyblockId(skyblockId.neuItem)
|
||||
init {
|
||||
ClientTickEvents.START_WORLD_TICK.register(ClientTickEvents.StartWorldTick {
|
||||
if (recentlyFailedToUpdateItemList && trySendClientboundUpdateRecipesPacket())
|
||||
recentlyFailedToUpdateItemList = false
|
||||
})
|
||||
}
|
||||
|
||||
fun launchAsyncUpdate(force: Boolean = false) {
|
||||
Firmament.coroutineScope.launch {
|
||||
ItemCache.ReloadProgressHud.reportProgress("Downloading", 0, -1) // TODO: replace with a proper boundy bar
|
||||
ItemCache.ReloadProgressHud.isEnabled = true
|
||||
try {
|
||||
RepoDownloadManager.downloadUpdate(force)
|
||||
ItemCache.ReloadProgressHud.reportProgress("Download complete", 1, 1)
|
||||
} finally {
|
||||
ItemCache.ReloadProgressHud.isEnabled = false
|
||||
}
|
||||
reload()
|
||||
}
|
||||
}
|
||||
fun getNEUItem(skyblockId: SkyblockId): NEUItem? = neuRepo.items.getItemBySkyblockId(skyblockId.neuItem)
|
||||
|
||||
fun reload() {
|
||||
try {
|
||||
ItemCache.ReloadProgressHud.reportProgress("Reloading from Disk",
|
||||
0,
|
||||
-1) // TODO: replace with a proper boundy bar
|
||||
ItemCache.ReloadProgressHud.isEnabled = true
|
||||
neuRepo.reload()
|
||||
} catch (exc: NEURepositoryException) {
|
||||
MinecraftClient.getInstance().player?.sendMessage(
|
||||
Text.literal("Failed to reload repository. This will result in some mod features not working.")
|
||||
)
|
||||
ItemCache.ReloadProgressHud.isEnabled = false
|
||||
exc.printStackTrace()
|
||||
}
|
||||
}
|
||||
fun launchAsyncUpdate(force: Boolean = false) {
|
||||
Firmament.coroutineScope.launch {
|
||||
ItemCache.ReloadProgressHud.reportProgress("Downloading", 0, -1) // TODO: replace with a proper boundy bar
|
||||
ItemCache.ReloadProgressHud.isEnabled = true
|
||||
try {
|
||||
RepoDownloadManager.downloadUpdate(force)
|
||||
ItemCache.ReloadProgressHud.reportProgress("Download complete", 1, 1)
|
||||
} finally {
|
||||
ItemCache.ReloadProgressHud.isEnabled = false
|
||||
}
|
||||
reload()
|
||||
}
|
||||
}
|
||||
|
||||
fun initialize() {
|
||||
if (Config.autoUpdate) {
|
||||
launchAsyncUpdate()
|
||||
} else {
|
||||
reload()
|
||||
}
|
||||
}
|
||||
fun reload() {
|
||||
try {
|
||||
ItemCache.ReloadProgressHud.reportProgress("Reloading from Disk",
|
||||
0,
|
||||
-1) // TODO: replace with a proper boundy bar
|
||||
ItemCache.ReloadProgressHud.isEnabled = true
|
||||
neuRepo.reload()
|
||||
} catch (exc: NEURepositoryException) {
|
||||
MinecraftClient.getInstance().player?.sendMessage(
|
||||
Text.literal("Failed to reload repository. This will result in some mod features not working.")
|
||||
)
|
||||
ItemCache.ReloadProgressHud.isEnabled = false
|
||||
exc.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun getPotentialStubPetData(skyblockId: SkyblockId): PetData? {
|
||||
val parts = skyblockId.neuItem.split(";")
|
||||
if (parts.size != 2) {
|
||||
return null
|
||||
}
|
||||
val (petId, rarityIndex) = parts
|
||||
if (!rarityIndex.all { it.isDigit() }) {
|
||||
return null
|
||||
}
|
||||
val intIndex = rarityIndex.toInt()
|
||||
if (intIndex !in Rarity.values().indices) return null
|
||||
if (petId !in neuRepo.constants.petNumbers) return null
|
||||
return PetData(Rarity.values()[intIndex], petId, 0.0, true)
|
||||
}
|
||||
fun initialize() {
|
||||
if (Config.autoUpdate) {
|
||||
launchAsyncUpdate()
|
||||
} else {
|
||||
reload()
|
||||
}
|
||||
}
|
||||
|
||||
fun getPotentialStubPetData(skyblockId: SkyblockId): PetData? {
|
||||
val parts = skyblockId.neuItem.split(";")
|
||||
if (parts.size != 2) {
|
||||
return null
|
||||
}
|
||||
val (petId, rarityIndex) = parts
|
||||
if (!rarityIndex.all { it.isDigit() }) {
|
||||
return null
|
||||
}
|
||||
val intIndex = rarityIndex.toInt()
|
||||
if (intIndex !in Rarity.values().indices) return null
|
||||
if (petId !in neuRepo.constants.petNumbers) return null
|
||||
return PetData(Rarity.values()[intIndex], petId, 0.0, true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user