aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/repo
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-03 01:24:24 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-09 01:01:18 +0100
commit22f0cc59a2d3bc7900764e3916c670075ff9d35e (patch)
treeb503ff607cf818a539cbbaa403f6851ef979e03d /src/main/kotlin/repo
parent646843ba3b960ac48f9866b3640438d3cc1dafc4 (diff)
downloadFirmament-22f0cc59a2d3bc7900764e3916c670075ff9d35e.tar.gz
Firmament-22f0cc59a2d3bc7900764e3916c670075ff9d35e.tar.bz2
Firmament-22f0cc59a2d3bc7900764e3916c670075ff9d35e.zip
1.21.3 WIP
Diffstat (limited to 'src/main/kotlin/repo')
-rw-r--r--src/main/kotlin/repo/RepoDownloadManager.kt2
-rw-r--r--src/main/kotlin/repo/RepoManager.kt8
-rw-r--r--src/main/kotlin/repo/SBItemStack.kt22
-rw-r--r--src/main/kotlin/repo/recipes/GenericRecipeRenderer.kt19
-rw-r--r--src/main/kotlin/repo/recipes/RecipeLayouter.kt33
-rw-r--r--src/main/kotlin/repo/recipes/SBCraftingRecipeRenderer.kt50
6 files changed, 130 insertions, 4 deletions
diff --git a/src/main/kotlin/repo/RepoDownloadManager.kt b/src/main/kotlin/repo/RepoDownloadManager.kt
index d674f23..3efd83b 100644
--- a/src/main/kotlin/repo/RepoDownloadManager.kt
+++ b/src/main/kotlin/repo/RepoDownloadManager.kt
@@ -5,7 +5,7 @@ package moe.nea.firmament.repo
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsChannel
-import io.ktor.utils.io.jvm.nio.copyTo
+import io.ktor.utils.io.copyTo
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
diff --git a/src/main/kotlin/repo/RepoManager.kt b/src/main/kotlin/repo/RepoManager.kt
index c052fb9..725642e 100644
--- a/src/main/kotlin/repo/RepoManager.kt
+++ b/src/main/kotlin/repo/RepoManager.kt
@@ -9,10 +9,12 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import kotlinx.coroutines.launch
import net.minecraft.client.MinecraftClient
import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket
+import net.minecraft.recipe.display.CuttingRecipeDisplay
import moe.nea.firmament.Firmament
import moe.nea.firmament.Firmament.logger
import moe.nea.firmament.events.ReloadRegistrationEvent
import moe.nea.firmament.gui.config.ManagedConfig
+import moe.nea.firmament.util.MC
import moe.nea.firmament.util.MinecraftDispatcher
import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.tr
@@ -77,7 +79,7 @@ object RepoManager {
private fun trySendClientboundUpdateRecipesPacket(): Boolean {
return MinecraftClient.getInstance().world != null && MinecraftClient.getInstance().networkHandler?.onSynchronizeRecipes(
- SynchronizeRecipesS2CPacket(mutableListOf())
+ SynchronizeRecipesS2CPacket(mutableMapOf(), CuttingRecipeDisplay.Grouping.empty())
) != null
}
@@ -92,7 +94,7 @@ object RepoManager {
fun launchAsyncUpdate(force: Boolean = false) {
Firmament.coroutineScope.launch {
- ItemCache.ReloadProgressHud.reportProgress("Downloading", 0, -1) // TODO: replace with a proper boundy bar
+ ItemCache.ReloadProgressHud.reportProgress("Downloading", 0, -1) // TODO: replace with a proper bouncy bar
ItemCache.ReloadProgressHud.isEnabled = true
try {
RepoDownloadManager.downloadUpdate(force)
@@ -112,7 +114,7 @@ object RepoManager {
ItemCache.ReloadProgressHud.isEnabled = true
neuRepo.reload()
} catch (exc: NEURepositoryException) {
- MinecraftClient.getInstance().player?.sendMessage(
+ MC.sendChat(
tr("firmament.repo.reloadfail",
"Failed to reload repository. This will result in some mod features not working.")
)
diff --git a/src/main/kotlin/repo/SBItemStack.kt b/src/main/kotlin/repo/SBItemStack.kt
index 281075d..18126ee 100644
--- a/src/main/kotlin/repo/SBItemStack.kt
+++ b/src/main/kotlin/repo/SBItemStack.kt
@@ -1,9 +1,14 @@
package moe.nea.firmament.repo
+import com.mojang.serialization.Codec
+import com.mojang.serialization.codecs.RecordCodecBuilder
import io.github.moulberry.repo.constants.PetNumbers
import io.github.moulberry.repo.data.NEUIngredient
import io.github.moulberry.repo.data.NEUItem
import net.minecraft.item.ItemStack
+import net.minecraft.network.RegistryByteBuf
+import net.minecraft.network.codec.PacketCodec
+import net.minecraft.network.codec.PacketCodecs
import net.minecraft.text.Text
import net.minecraft.util.Formatting
import moe.nea.firmament.repo.ItemCache.asItemStack
@@ -40,6 +45,21 @@ data class SBItemStack constructor(
}
companion object {
+ val PACKET_CODEC: PacketCodec<in RegistryByteBuf, SBItemStack> = PacketCodec.tuple(
+ SkyblockId.PACKET_CODEC, { it.skyblockId },
+ PacketCodecs.VAR_INT, { it.stackSize },
+ { id, count -> SBItemStack(id, count) }
+ )
+ val CODEC: Codec<SBItemStack> = RecordCodecBuilder.create {
+ it.group(
+ SkyblockId.CODEC.fieldOf("skyblockId").forGetter { it.skyblockId },
+ Codec.INT.fieldOf("count").forGetter { it.stackSize },
+ ).apply(it) { id, count ->
+ SBItemStack(id, count)
+ }
+ }
+ val EMPTY = SBItemStack(SkyblockId.NULL, 0)
+
operator fun invoke(itemStack: ItemStack): SBItemStack {
val skyblockId = itemStack.skyBlockId ?: SkyblockId.NULL
return SBItemStack(
@@ -114,6 +134,8 @@ data class SBItemStack constructor(
val itemStack = itemStack_ ?: run {
if (skyblockId == SkyblockId.COINS)
return@run ItemCache.coinItem(stackSize).also { it.appendLore(extraLore) }
+ if (stackSize == 0)
+ return@run ItemStack.EMPTY
val replacementData = mutableMapOf<String, String>()
injectReplacementDataForPets(replacementData)
return@run neuItem.asItemStack(idHint = skyblockId, replacementData)
diff --git a/src/main/kotlin/repo/recipes/GenericRecipeRenderer.kt b/src/main/kotlin/repo/recipes/GenericRecipeRenderer.kt
new file mode 100644
index 0000000..9a1aea5
--- /dev/null
+++ b/src/main/kotlin/repo/recipes/GenericRecipeRenderer.kt
@@ -0,0 +1,19 @@
+package moe.nea.firmament.repo.recipes
+
+import io.github.moulberry.repo.NEURepository
+import io.github.moulberry.repo.data.NEURecipe
+import me.shedaniel.math.Rectangle
+import net.minecraft.item.ItemStack
+import net.minecraft.text.Text
+import net.minecraft.util.Identifier
+import moe.nea.firmament.repo.SBItemStack
+
+interface GenericRecipeRenderer<T : NEURecipe> {
+ fun render(recipe: T, bounds: Rectangle, layouter: RecipeLayouter)
+ fun getInputs(recipe: T): Collection<SBItemStack>
+ fun getOutputs(recipe: T): Collection<SBItemStack>
+ val icon: ItemStack
+ val title: Text
+ val identifier: Identifier
+ fun findAllRecipes(neuRepository: NEURepository): Iterable<T>
+}
diff --git a/src/main/kotlin/repo/recipes/RecipeLayouter.kt b/src/main/kotlin/repo/recipes/RecipeLayouter.kt
new file mode 100644
index 0000000..109bff5
--- /dev/null
+++ b/src/main/kotlin/repo/recipes/RecipeLayouter.kt
@@ -0,0 +1,33 @@
+package moe.nea.firmament.repo.recipes
+
+import io.github.notenoughupdates.moulconfig.gui.GuiComponent
+import net.minecraft.text.Text
+import moe.nea.firmament.repo.SBItemStack
+
+interface RecipeLayouter {
+ enum class SlotKind {
+ SMALL_INPUT,
+ SMALL_OUTPUT,
+
+ /**
+ * Create a bigger background and mark the slot as output. The coordinates should still refer the upper left corner of the item stack, not of the bigger background.
+ */
+ BIG_OUTPUT,
+ }
+
+ fun createItemSlot(
+ x: Int, y: Int,
+ content: SBItemStack?,
+ slotKind: SlotKind,
+ )
+
+ fun createLabel(
+ x: Int, y: Int,
+ text: Text
+ )
+
+ fun createArrow(x: Int, y: Int)
+
+ fun createMoulConfig(x: Int, y: Int, w: Int, h: Int, component: GuiComponent)
+}
+
diff --git a/src/main/kotlin/repo/recipes/SBCraftingRecipeRenderer.kt b/src/main/kotlin/repo/recipes/SBCraftingRecipeRenderer.kt
new file mode 100644
index 0000000..fd0c750
--- /dev/null
+++ b/src/main/kotlin/repo/recipes/SBCraftingRecipeRenderer.kt
@@ -0,0 +1,50 @@
+package moe.nea.firmament.repo.recipes
+
+import io.github.moulberry.repo.NEURepository
+import io.github.moulberry.repo.data.NEUCraftingRecipe
+import me.shedaniel.math.Point
+import me.shedaniel.math.Rectangle
+import net.minecraft.block.Blocks
+import net.minecraft.item.ItemStack
+import net.minecraft.text.Text
+import net.minecraft.util.Identifier
+import moe.nea.firmament.Firmament
+import moe.nea.firmament.repo.SBItemStack
+import moe.nea.firmament.util.tr
+
+class SBCraftingRecipeRenderer : GenericRecipeRenderer<NEUCraftingRecipe> {
+ override fun render(recipe: NEUCraftingRecipe, bounds: Rectangle, layouter: RecipeLayouter) {
+ val point = Point(bounds.centerX - 58, bounds.centerY - 27)
+ layouter.createArrow(point.x + 60, point.y + 18)
+ for (i in 0 until 3) {
+ for (j in 0 until 3) {
+ val item = recipe.inputs[i + j * 3]
+ layouter.createItemSlot(point.x + 1 + i * 18,
+ point.y + 1 + j * 18,
+ SBItemStack(item),
+ RecipeLayouter.SlotKind.SMALL_INPUT)
+ }
+ }
+ layouter.createItemSlot(
+ point.x + 95, point.y + 19,
+ SBItemStack(recipe.output),
+ RecipeLayouter.SlotKind.BIG_OUTPUT
+ )
+ }
+
+ override fun getInputs(recipe: NEUCraftingRecipe): Collection<SBItemStack> {
+ return recipe.allInputs.mapNotNull { SBItemStack(it) }
+ }
+
+ override fun getOutputs(recipe: NEUCraftingRecipe): Collection<SBItemStack> {
+ return SBItemStack(recipe.output)?.let(::listOf) ?: emptyList()
+ }
+
+ override fun findAllRecipes(neuRepository: NEURepository): Iterable<NEUCraftingRecipe> {
+ return neuRepository.items.items.values.flatMap { it.recipes }.filterIsInstance<NEUCraftingRecipe>()
+ }
+
+ override val icon: ItemStack = ItemStack(Blocks.CRAFTING_TABLE)
+ override val title: Text = tr("firmament.category.crafting", "SkyBlock Crafting")
+ override val identifier: Identifier = Firmament.identifier("crafting_recipe")
+}