Make mattery container actually serialize data
This commit is contained in:
parent
fbfca5d937
commit
f3b6926a45
@ -32,6 +32,7 @@ import ru.dbotthepony.mc.otm.core.collect.count
|
||||
import ru.dbotthepony.mc.otm.core.collect.emptyIterator
|
||||
import ru.dbotthepony.mc.otm.core.collect.filter
|
||||
import ru.dbotthepony.mc.otm.core.collect.map
|
||||
import ru.dbotthepony.mc.otm.core.collect.toList
|
||||
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||
import ru.dbotthepony.mc.otm.core.registryName
|
||||
@ -286,29 +287,13 @@ open class MatteryContainer(var listener: ContainerListener, private val size: I
|
||||
}
|
||||
|
||||
override fun serializeNBT(registries: HolderLookup.Provider): CompoundTag {
|
||||
return CompoundTag().also {
|
||||
it["items"] = ListTag().also {
|
||||
for ((i, item) in slots.withIndex()) {
|
||||
if (!item.isEmpty) {
|
||||
it.add(item.save(registries).also {
|
||||
it as CompoundTag
|
||||
it["slotIndex"] = i
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
val state = SerializedState(
|
||||
slotIterator(true).map { SerializedItem(it.item, it.slot) }.toList(size),
|
||||
filters.withIndex().iterator().filter { it.value != null }.map { SerializedFilter(it.value!!, it.index) }.toList()
|
||||
)
|
||||
|
||||
it["filters"] = ListTag().also {
|
||||
for ((i, filter) in filters.withIndex()) {
|
||||
if (filter != null) {
|
||||
it.add(CompoundTag().also {
|
||||
it["filter"] = filter.registryName!!.toString()
|
||||
it["slotIndex"] = i
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return SerializedState.CODEC.encodeStart(registries.createSerializationContext(NbtOps.INSTANCE), state)
|
||||
.resultOrPartial { throw RuntimeException("Failed to encode container contents: $it") }.get() as CompoundTag
|
||||
}
|
||||
|
||||
final override fun isEmpty(): Boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user