:gem: Lapis: Bringing modern Kotlin standards to M...
# ksp
e
💎 Lapis: Bringing modern Kotlin standards to Minecraft modding with KSP2 for Sponge Mixins! K Hi everyone! I’m excited to share my first KSP project! It’s a tool designed to modernize bytecode injections in Minecraft modding by bringing the entire Mixin development workflow closer to idiomatic Kotlin standards. For years, the community has been forced to write Mixins in Java. This is because Mixin classes are literally "merged" into Minecraft's bytecode at runtime, and the strict requirements of the Mixin transformer make it nearly impossible to use Kotlin directly. As a result, even Kotlin-based mods were forced to maintain a Java footprint, preventing developers from having a 100% Kotlin codebase. I wanted to create a Kotlin-way to handle these injections without the headache. What Lapis does right now: • Bytecode Mapping & DSL: Instead of deciphering long JVM descriptors in every method, Lapis lets you define a clear
@Schema
of classes and members you're working with. This schema powers a high-level DSL that hides the verbosity of Mixins behind type-safe, generated wrappers. • Idiomatic Kotlin Wrappers: I’ve re-imagined core Mixin mechanics to feel like native Kotlin. For example: ◦ Method Injection: While standard Mixins force you to pass every single argument even if you don't need them, Lapis uses Kotlin's default arguments to call original logic, keeping your code clean and focused. ◦ Cancellation: Instead of manually managing return logic after a cancellation, Lapis provides a wrapper that returns
Nothing
, naturally terminating the flow. • Automated Logic Sharing: Usually, modders have to manually create and implement interface injections to access Mixin logic from their main code. Lapis removes this boilerplate entirely by automatically generating these interfaces and providing Kotlin extensions directly on the game classes. • Automatic Configuration: Lapis automatically generates required Mixin json configs and AW/AT to handle class and member visibility, so you don't have to maintain these files manually. • Advanced Pipeline: The processor is built as a multi-stage pipeline (Parser -> Validator -> Transformer -> Generator). To accurately parse functional types, I even had to go beyond the standard KSP API and dive into PSI. • Custom Kotlin2JavaPoet Converter: Since Mixins must stay in Java, I built a custom converter to translate KotlinPoet types into JavaPoet types. The project is in active development! I am currently refactoring the internal IR and working on: • Shadow Support: Coming very soon! Automated generation of shadow fields and methods to access game class members. • Escape Hatch: Support for writing full Mixins in Kotlin for those who need total control. This involves a complete converter that translates the entire Kotlin Mixin class into its Java counterpart, keeping all automated interface and extension generation features intact. I’m happy to chat about KSP in the thread! And if you’re into modding, I’d love to hear your thoughts and suggestions on how to make the DX even better. (Although this is my first KSP-based tool, it’s already powering several of my mods currently running on thousands of players' machines...) GitHub: https://github.com/Recrafter/lapis
💡 1
👀 2
🎉 1
c
Hey! It'd be nice if the README had some code examples 👀
e
Hey! I was planning to dump all the details into the Wiki, but I definitely pushed that to the extreme. 😅 I’ve just updated the README with code examples to show how Lapis looks in practice. Check it out!
I've added a more detailed example to the readme, so if you're interested, you can check it out again ;)