Slot Data

This commit is contained in:
2026-09-09 17:43:29 +08:00
parent 54409d9e8a
commit 0d22e85d88
15 files changed
+494 -5

No files matched your search

@@ -16,12 +16,10 @@ public sealed interface IdSet {
public fun BytesBuffer.readIdSet(): IdSet {
val type = this.readVarInt()
return if (type == 0) {
IdSet.Tag(tagName = this.readMcString())
} else {
return if (type == 0) IdSet.Tag(tagName = this.readMcString()) else {
val count = type - 1
val ids = ArrayList<Int>(count)
(0 until count).forEach { _ -> ids.add(this.readVarInt()) }
repeat(count) { ids.add(this.readVarInt()) }
IdSet.Entries(ids)
}
}
@@ -42,7 +42,6 @@ public fun BytesBuffer.writePrefixedStringArray(value: List<String>) {
}
public inline fun <T> BytesBuffer.readPrefixed(reader: BytesBuffer.() -> T): List<T> {
val count = this.readVarInt()
require(count in 0..4096) {
@@ -57,4 +56,14 @@ public inline fun <T> BytesBuffer.readPrefixed(reader: BytesBuffer.() -> T): Lis
public inline fun <T> BytesBuffer.writePrefixed(list: List<T>, writer: BytesBuffer.(T) -> Unit) {
this.writeVarInt(list.size)
for (item in list) this.writer(item)
}
public fun <T> BytesBuffer.readPrefixOptional(reader: BytesBuffer.() -> T): T? {
val hasValue = readBoolean()
return if (hasValue) reader() else null
}
public fun <T> BytesBuffer.writePrefixedOptional(value: T?, writer: BytesBuffer.(T) -> Unit) {
writeBoolean(value != null)
if (value != null) writer(value)
}