diff options
Diffstat (limited to 'src/main/kotlin/util/json/BlockPosSerializer.kt')
-rw-r--r-- | src/main/kotlin/util/json/BlockPosSerializer.kt | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/main/kotlin/util/json/BlockPosSerializer.kt b/src/main/kotlin/util/json/BlockPosSerializer.kt new file mode 100644 index 0000000..144b0a0 --- /dev/null +++ b/src/main/kotlin/util/json/BlockPosSerializer.kt @@ -0,0 +1,25 @@ +package moe.nea.firmament.util.json + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.serializer +import net.minecraft.util.math.BlockPos + +object BlockPosSerializer : KSerializer<BlockPos> { + val delegate = serializer<List<Int>>() + + override val descriptor: SerialDescriptor + get() = SerialDescriptor("BlockPos", delegate.descriptor) + + override fun deserialize(decoder: Decoder): BlockPos { + val list = decoder.decodeSerializableValue(delegate) + require(list.size == 3) + return BlockPos(list[0], list[1], list[2]) + } + + override fun serialize(encoder: Encoder, value: BlockPos) { + encoder.encodeSerializableValue(delegate, listOf(value.x, value.y, value.z)) + } +} |