diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/IdentifierSerializer.kt | 28 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/LogIfNull.kt | 13 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/IdentifierSerializer.kt b/src/main/kotlin/moe/nea/firmament/util/IdentifierSerializer.kt new file mode 100644 index 0000000..3c1aa52 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/util/IdentifierSerializer.kt @@ -0,0 +1,28 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.util + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import net.minecraft.util.Identifier + +object IdentifierSerializer : KSerializer<Identifier> { + val delegateSerializer = String.serializer() + override val descriptor: SerialDescriptor + get() = SerialDescriptor("Identifier", delegateSerializer.descriptor) + + override fun deserialize(decoder: Decoder): Identifier { + return Identifier(decoder.decodeSerializableValue(delegateSerializer)) + } + + override fun serialize(encoder: Encoder, value: Identifier) { + encoder.encodeSerializableValue(delegateSerializer, value.toString()) + } +} diff --git a/src/main/kotlin/moe/nea/firmament/util/LogIfNull.kt b/src/main/kotlin/moe/nea/firmament/util/LogIfNull.kt new file mode 100644 index 0000000..b0476ee --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/util/LogIfNull.kt @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.util + + +fun runNull(block: () -> Unit): Nothing? { + block() + return null +} |