From 508b8352cfbc066b025943cf1cbf8be5e5edb88a Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 4 May 2023 18:23:54 +0200 Subject: Add somewhat faulty crafting recipes --- .../moe/nea/notenoughupdates/repo/RepoManager.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt') diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt index 6470914..acaaacd 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt @@ -1,20 +1,22 @@ package moe.nea.notenoughupdates.repo import io.github.cottonmc.cotton.gui.client.CottonHud +import io.github.moulberry.repo.NEURecipeCache import io.github.moulberry.repo.NEURepository import io.github.moulberry.repo.NEURepositoryException +import io.github.moulberry.repo.data.NEURecipe +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents 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.hud.ProgressBar -import moe.nea.notenoughupdates.util.data.DataHolder -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.minecraft.client.MinecraftClient import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket import net.minecraft.text.Text +import moe.nea.notenoughupdates.NotEnoughUpdates +import moe.nea.notenoughupdates.NotEnoughUpdates.logger +import moe.nea.notenoughupdates.hud.ProgressBar import moe.nea.notenoughupdates.util.SkyblockId +import moe.nea.notenoughupdates.util.data.DataHolder object RepoManager : DataHolder(serializer(), "repo", ::Config) { @Serializable @@ -43,6 +45,13 @@ object RepoManager : DataHolder(serializer(), "repo", ::Conf } } + private val recipeCache = NEURecipeCache.forRepo(neuRepo) + + fun getAllRecipes() = neuRepo.items.items.values.asSequence().flatMap { it.recipes } + + fun getRecipesFor(skyblockId: SkyblockId): Set = recipeCache.recipes[skyblockId.neuItem] ?: setOf() + fun getUsagesFor(skyblockId: SkyblockId): Set = recipeCache.usages[skyblockId.neuItem] ?: setOf() + private fun trySendClientboundUpdateRecipesPacket(): Boolean { return MinecraftClient.getInstance().world != null && MinecraftClient.getInstance().networkHandler?.onSynchronizeRecipes( SynchronizeRecipesS2CPacket(mutableListOf()) -- cgit