aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntrySerializer.kt
blob: 15731cb1ed235fca285b8748091dfe95f9a7b4e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package moe.nea.firmament.rei

import io.github.moulberry.repo.data.NEUItem
import me.shedaniel.rei.api.common.entry.EntrySerializer
import me.shedaniel.rei.api.common.entry.EntryStack
import net.minecraft.nbt.NbtCompound
import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.SkyblockId

object NEUItemEntrySerializer : EntrySerializer<NEUItem?> {
    const val SKYBLOCK_ID_ENTRY = "SKYBLOCK_ID"

    override fun supportSaving(): Boolean = true
    override fun supportReading(): Boolean = true

    override fun read(tag: NbtCompound): NEUItem? {
        return RepoManager.getNEUItem(SkyblockId(tag.getString(SKYBLOCK_ID_ENTRY)))
    }

    override fun save(entry: EntryStack<NEUItem?>, value: NEUItem?): NbtCompound {
        return NbtCompound().apply {
            putString(SKYBLOCK_ID_ENTRY, value?.skyblockItemId ?: "null")
        }
    }
}