Getting Started
This guide takes you from zero to a working datapack using Kore and Kotlin. It also highlights a few Kotlin/Kore tips that Java beginners often miss.
Prerequisites
- Java 21 (JDK 21) or higher
- Kotlin + Gradle (using the Gradle wrapper is recommended)
- An IDE with Kotlin support (IntelliJ IDEA recommended)
- Basic knowledge of Minecraft datapacks will help you.
Option A — Use the Kore Template (recommended)
The fastest way to start is the Kore Template repository. It's preconfigured and ready to run.
- On GitHub: open https://github.com/Ayfri/Kore-Template and click “Use this template” to create your repo, or clone it directly.
- In IntelliJ IDEA:
- File > New > Project from Version Control
- Enter URL: https://github.com/Ayfri/Kore-Template and choose a directory
- Open the project, trust it, let Gradle import/sync
- In the
src/main/kotlinfolder, openMain.ktand run themainfunction
The template already sets Java 21 and enables the required Kotlin options.
Option B — Add Kore to an existing project
Add the dependency to your build file.
Gradle (Kotlin)
Gradle (Groovy)
Maven
Amper
Kotlin configuration
Enable context receivers (parameters) and set Java toolchain in your build.gradle.kts:
Your first datapack (Hello, Kore)
Create a Main.kt and paste:
- Run
mainfrom your IDE. - A datapack archive is produced; put it into your Minecraft world's
datapacks/folder. - In-game, run:
/function hello_kore:display_text.
Tips for Kotlin newcomers
- Null safety: Kotlin's type system distinguishes nullable and non-nullable types. Use
?for nullable types and prefer safe calls (?.) and the Elvis operator (?:). See Null Safety.
- Type inference: You rarely need to specify types explicitly—Kotlin infers them for you. Use
valfor read-only variables andvarfor mutable ones. Prefervalfor immutability.
- Smart casts: The compiler automatically casts types after checks (e.g.,
if (x is String) { x.length }).
- Extension functions: Add new functions to existing types without inheritance. Kore uses this for DSLs. See Extensions.
- Standard library: Kotlin's standard library is rich—explore kotlinlang.org/api/latest/jvm/stdlib/.
- DSLs + context receivers: Inside
dataPack { ... }, many builders are available without qualifiers. The compiler flag-Xcontext-parametersis required. - Extract helpers with extensions: Attach utilities to
DataPackto keep code organized:
- Name collisions in builders: Some builder names exist in multiple contexts (e.g.,
nbt,predicate). If your IDE auto-imports the wrong symbol, qualify withthis.inside the DSL scope to target the correct function, or fix the import. Example:
Then just remove this. now that you know the import is correct.
-
Idempotency: Declaring the same record twice is safe, Kore only keeps the last one.
-
Kotlin Playground: Try out code online at play.kotlinlang.org.
-
Official docs: The Kotlin documentation is excellent for learning language features and best practices.
Project layout and outputs
- Your code lives under
src/main/kotlin(template already set). - Generated datapacks:
.generate()writes a folder;.generateZip()writes a zip;.generateJar()targets mod loaders. - During development, enable pretty JSON in Configuration to inspect outputs.
- Split your code into multiple files to keep things organized.
Troubleshooting
- Unresolved DSL symbols: Ensure the Kore dependency is on the classpath and
-Xcontext-parametersis enabled. - Java version errors: Verify
jvmToolchain(21)and that your JDK is 21. - Dev loop: Re-run your program after edits to regenerate the datapack.
What to read next (Docs index)
Core guides
Features
- Functions
- Predicates
- Components
- Chat Components
- Colors
- Enchantments
- Dialogs
- Recipes
- Loot Tables
- Item Modifiers
- Advancements
- Scoreboards
- Worldgen
- Bindings
- Test Features (GameTest)
Helpers
See also
- “Hello World” walkthrough: Kore Hello World
- Minecraft wiki: Datapack
- Kore on GitHub
- Kore on Maven Central
- Kore on Discord
