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.emptyIterator
|
||||||
import ru.dbotthepony.mc.otm.core.collect.filter
|
import ru.dbotthepony.mc.otm.core.collect.filter
|
||||||
import ru.dbotthepony.mc.otm.core.collect.map
|
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.isNotEmpty
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||||
import ru.dbotthepony.mc.otm.core.registryName
|
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 {
|
override fun serializeNBT(registries: HolderLookup.Provider): CompoundTag {
|
||||||
return CompoundTag().also {
|
val state = SerializedState(
|
||||||
it["items"] = ListTag().also {
|
slotIterator(true).map { SerializedItem(it.item, it.slot) }.toList(size),
|
||||||
for ((i, item) in slots.withIndex()) {
|
filters.withIndex().iterator().filter { it.value != null }.map { SerializedFilter(it.value!!, it.index) }.toList()
|
||||||
if (!item.isEmpty) {
|
)
|
||||||
it.add(item.save(registries).also {
|
|
||||||
it as CompoundTag
|
|
||||||
it["slotIndex"] = i
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it["filters"] = ListTag().also {
|
return SerializedState.CODEC.encodeStart(registries.createSerializationContext(NbtOps.INSTANCE), state)
|
||||||
for ((i, filter) in filters.withIndex()) {
|
.resultOrPartial { throw RuntimeException("Failed to encode container contents: $it") }.get() as CompoundTag
|
||||||
if (filter != null) {
|
|
||||||
it.add(CompoundTag().also {
|
|
||||||
it["filter"] = filter.registryName!!.toString()
|
|
||||||
it["slotIndex"] = i
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun isEmpty(): Boolean {
|
final override fun isEmpty(): Boolean {
|
||||||
|
Loading…
Reference in New Issue
Block a user