dsls my beloveded

This commit is contained in:
yrsegal@gmail.com 2022-05-24 23:57:02 -04:00
parent 5f4c0c170d
commit 3e0d1f9fe0
2 changed files with 10 additions and 1 deletions

View file

@ -73,7 +73,7 @@ data class HexPattern(public val startDir: HexDir, public val angles: MutableLis
fun serializeToNBT() = NBTBuilder {
TAG_START_DIR %= byte(startDir.ordinal)
TAG_ANGLES %= byteArray(*angles.map(HexAngle::ordinal).toIntArray())
TAG_ANGLES %= byteArray(angles.map(HexAngle::ordinal))
}
// Terrible shorthand method for easy matching

View file

@ -40,12 +40,15 @@ object NBTBuilder {
inline fun string(value: String): StringTag = StringTag.valueOf(value)
inline fun byteArray(value: Collection<Number>): ByteArrayTag = ByteArrayTag(value.map { it.toByte() })
inline fun byteArray(vararg value: Int): ByteArrayTag = ByteArrayTag(ByteArray(value.size) { value[it].toByte() })
inline fun byteArray(vararg value: Byte): ByteArrayTag = ByteArrayTag(value)
inline fun byteArray(): ByteArrayTag = ByteArrayTag(byteArrayOf()) // avoiding overload ambiguity
inline fun longArray(value: Collection<Number>): LongArrayTag = LongArrayTag(value.map { it.toLong() })
inline fun longArray(vararg value: Int): LongArrayTag = LongArrayTag(LongArray(value.size) { value[it].toLong() })
inline fun longArray(vararg value: Long): LongArrayTag = LongArrayTag(value)
inline fun longArray(): LongArrayTag = LongArrayTag(longArrayOf()) // avoiding overload ambiguity
inline fun intArray(value: Collection<Number>): IntArrayTag = IntArrayTag(value.map { it.toInt() })
inline fun intArray(vararg value: Int): IntArrayTag = IntArrayTag(value)
}
@ -104,12 +107,15 @@ value class NbtCompoundBuilder(val tag: CompoundTag) {
inline fun string(value: String): StringTag = StringTag.valueOf(value)
inline fun byteArray(value: Collection<Number>): ByteArrayTag = ByteArrayTag(value.map { it.toByte() })
inline fun byteArray(vararg value: Int): ByteArrayTag = ByteArrayTag(ByteArray(value.size) { value[it].toByte() })
inline fun byteArray(vararg value: Byte): ByteArrayTag = ByteArrayTag(value)
inline fun byteArray(): ByteArrayTag = ByteArrayTag(byteArrayOf()) // avoiding overload ambiguity
inline fun longArray(value: Collection<Number>): LongArrayTag = LongArrayTag(value.map { it.toLong() })
inline fun longArray(vararg value: Int): LongArrayTag = LongArrayTag(LongArray(value.size) { value[it].toLong() })
inline fun longArray(vararg value: Long): LongArrayTag = LongArrayTag(value)
inline fun longArray(): LongArrayTag = LongArrayTag(longArrayOf()) // avoiding overload ambiguity
inline fun intArray(value: Collection<Number>): IntArrayTag = IntArrayTag(value.map { it.toInt() })
inline fun intArray(vararg value: Int): IntArrayTag = IntArrayTag(value)
}
@ -174,12 +180,15 @@ value class NbtListBuilder(val tag: ListTag) {
inline fun string(value: String): StringTag = StringTag.valueOf(value)
inline fun byteArray(value: Collection<Number>): ByteArrayTag = ByteArrayTag(value.map { it.toByte() })
inline fun byteArray(vararg value: Int): ByteArrayTag = ByteArrayTag(ByteArray(value.size) { value[it].toByte() })
inline fun byteArray(vararg value: Byte): ByteArrayTag = ByteArrayTag(value)
inline fun byteArray(): ByteArrayTag = ByteArrayTag(byteArrayOf()) // avoiding overload ambiguity
inline fun longArray(value: Collection<Number>): LongArrayTag = LongArrayTag(value.map { it.toLong() })
inline fun longArray(vararg value: Int): LongArrayTag = LongArrayTag(LongArray(value.size) { value[it].toLong() })
inline fun longArray(vararg value: Long): LongArrayTag = LongArrayTag(value)
inline fun longArray(): LongArrayTag = LongArrayTag(longArrayOf()) // avoiding overload ambiguity
inline fun intArray(value: Collection<Number>): IntArrayTag = IntArrayTag(value.map { it.toInt() })
inline fun intArray(vararg value: Int): IntArrayTag = IntArrayTag(value)
inline fun doubles(vararg value: Int): List<DoubleTag> = value.map { DoubleTag.valueOf(it.toDouble()) }