aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/repo/SBItemStack.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-06 17:44:58 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-06 17:44:58 +0100
commit06534f9d09732ed29a6fa6bc48def5f7c2b0b865 (patch)
treec77dbd01b6538fa6974e72b9a7df038f0dc9017b /src/main/kotlin/repo/SBItemStack.kt
parentee21f2da76ea2218ef6a0c6fefa97befa654d115 (diff)
downloadFirmament-06534f9d09732ed29a6fa6bc48def5f7c2b0b865.tar.gz
Firmament-06534f9d09732ed29a6fa6bc48def5f7c2b0b865.tar.bz2
Firmament-06534f9d09732ed29a6fa6bc48def5f7c2b0b865.zip
Re-add REI
Diffstat (limited to 'src/main/kotlin/repo/SBItemStack.kt')
-rw-r--r--src/main/kotlin/repo/SBItemStack.kt19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main/kotlin/repo/SBItemStack.kt b/src/main/kotlin/repo/SBItemStack.kt
index 281075d..e1cbdbb 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,20 @@ 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)
+ }
+ }
+
operator fun invoke(itemStack: ItemStack): SBItemStack {
val skyblockId = itemStack.skyBlockId ?: SkyblockId.NULL
return SBItemStack(