Skip to content

Martmists-GH/kotlin-codec-plugin

Repository files navigation

Kotlin Codec Plugin

A kotlin compiler plugin to create codecs for Mojang's Codec system.

Usage

Important: To make the CODEC field resolve in IntelliJ, make sure to open the registry and disable kotlin.k2.only.bundled.compiler.plugins.enabled

Add the codec-annotations and codec-plugin folders to your project, then add to your build files:

// build.gradle.kts
plugins {
    ...
    id("com.martmists.codecs")
}

dependencies {
    ...
    implementation(project(":codec-annotations"))
}

// settings.gradle.kts
include(":codec-annotations")
includeBuild("codec-plugin")

Then in your code:

import com.martmists.serialization.RecordCodec
import com.martmists.serialization.MapCodec

@RecordCodec
data class MyType(
    val x: Int,
    val y: String,
)

@MapCodec
data class OtherType(
    val text: @CodecLocation(TextCodecs::class, "CODEC") Text,
    @SerialName("some_other_attribute")
    val someOtherAttribute: String,
)

// elsewhere
val codec: Codec<MyType> = MyType.CODEC
val codec2: MapCodec<OtherType> = OtherType.CODEC

About

A kotlin compiler plugin for Mojang Codecs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages