Display broken favourites
This commit is contained in:
@@ -8,16 +8,18 @@ import moe.nea.notenoughupdates.repo.RepoManager
|
|||||||
import moe.nea.notenoughupdates.util.SkyblockId
|
import moe.nea.notenoughupdates.util.SkyblockId
|
||||||
|
|
||||||
object NEUItemEntrySerializer : EntrySerializer<NEUItem?> {
|
object NEUItemEntrySerializer : EntrySerializer<NEUItem?> {
|
||||||
|
const val SKYBLOCK_ID_ENTRY = "SKYBLOCK_ID"
|
||||||
|
|
||||||
override fun supportSaving(): Boolean = true
|
override fun supportSaving(): Boolean = true
|
||||||
override fun supportReading(): Boolean = true
|
override fun supportReading(): Boolean = true
|
||||||
|
|
||||||
override fun read(tag: NbtCompound): NEUItem? {
|
override fun read(tag: NbtCompound): NEUItem? {
|
||||||
return RepoManager.getNEUItem(SkyblockId(tag.getString("SKYBLOCK_ID")))
|
return RepoManager.getNEUItem(SkyblockId(tag.getString(SKYBLOCK_ID_ENTRY)))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun save(entry: EntryStack<NEUItem?>, value: NEUItem?): NbtCompound {
|
override fun save(entry: EntryStack<NEUItem?>, value: NEUItem?): NbtCompound {
|
||||||
return NbtCompound().apply {
|
return NbtCompound().apply {
|
||||||
putString("SKYBLOCK_ID", value?.skyblockItemId ?: "null")
|
putString(SKYBLOCK_ID_ENTRY, value?.skyblockItemId ?: "null")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry
|
|||||||
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
|
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
|
import moe.nea.notenoughupdates.repo.ItemCache
|
||||||
import moe.nea.notenoughupdates.repo.ItemCache.asItemStack
|
import moe.nea.notenoughupdates.repo.ItemCache.asItemStack
|
||||||
import moe.nea.notenoughupdates.repo.RepoManager
|
import moe.nea.notenoughupdates.repo.RepoManager
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ class NEUReiPlugin : REIClientPlugin {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun EntryStack<NEUItem>.asItemEntry(): EntryStack<ItemStack> {
|
fun EntryStack<NEUItem>.asItemEntry(): EntryStack<ItemStack> {
|
||||||
return EntryStack.of(VanillaEntryTypes.ITEM, value.asItemStack())
|
return EntryStack.of(VanillaEntryTypes.ITEM, value?.asItemStack())
|
||||||
}
|
}
|
||||||
|
|
||||||
val SKYBLOCK_ITEM_TYPE_ID = Identifier("notenoughupdates", "skyblockitems")
|
val SKYBLOCK_ITEM_TYPE_ID = Identifier("notenoughupdates", "skyblockitems")
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ object ItemCache : IReloadable {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun brokenItemStack(neuItem: NEUItem): ItemStack {
|
fun brokenItemStack(neuItem: NEUItem?): ItemStack {
|
||||||
return ItemStack(Items.PAINTING).apply {
|
return ItemStack(Items.PAINTING).apply {
|
||||||
setCustomName(Text.literal(neuItem.displayName))
|
setCustomName(Text.literal(neuItem?.displayName ?: "null"))
|
||||||
appendLore(listOf(Text.translatable("notenoughupdates.repo.brokenitem", neuItem.skyblockItemId)))
|
appendLore(listOf(Text.translatable("notenoughupdates.repo.brokenitem", neuItem?.skyblockItemId)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,8 @@ object ItemCache : IReloadable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NEUItem.asItemStack(): ItemStack {
|
fun NEUItem?.asItemStack(): ItemStack {
|
||||||
|
if (this == null) return brokenItemStack(null)
|
||||||
var s = cache[this.skyblockItemId]
|
var s = cache[this.skyblockItemId]
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
s = asItemStackNow()
|
s = asItemStackNow()
|
||||||
|
|||||||
Reference in New Issue
Block a user