Bindings (Import Existing Datapacks)

Warning

The bindings module isexperimental. APIs and generated output may change without notice.

The bindings module lets you import existing datapacks and generates Kotlin types so you can reference functions, resources, and tags safely in your code.

Add the module

If you are working in a multi-module setup:

dependencies {
	implementation("io.github.ayfri.kore:bindings:<VERSION>")
}
Kotlin

Quick start

import io.github.ayfri.kore.bindings.api.importDatapacks

importDatapacks {
	configuration {
		outputPath("src/main/kotlin")
		packagePrefix = "kore.dependencies"
	}

	github("pixigeko.minecraft-default-data:1.21.8") {
		subPath = "data"
	}

	modrinth("vanilla-refresh")
	curseforge("repurposed-structures-illager-invasion-compat")
	url("https://example.com/pack.zip")
}
Kotlin

Using generated bindings

When you import a datapack, Kore generates a data object with a name derived from the datapack's name (e.g., VanillaRefresh).

Accessing resources

Resources are organized by namespace and type. If a datapack has only one namespace, resources are accessible directly:

import kore.dependencies.vanillarefresh.VanillaRefresh

function("my_function") {
	// Call a function from the imported datapack
	function(VanillaRefresh.Functions.MAIN_TICK)

	// Reference a loot table
	loot(VanillaRefresh.LootTables.BLOCKS.IRON_ORE)
}
Kotlin

If the datapack uses multiple namespaces, they are nested:

VanillaRefresh.Minecraft.LootTables.CHESTS.ABANDONED_MINESHAFT
Kotlin

Tags

Tags are also imported and can be used wherever a tag of that type is expected:

function("my_function") {
	// Check if the item is in an imported item tag
	execute {
		`if`(entity(self), items(VanillaRefresh.Tags.Items.MY_CUSTOM_TAG))
	}
}
Kotlin

Pack metadata

The generated object also contains information about the original datapack:

val path = VanillaRefresh.PATH // Path to the source file/folder
val packMeta = VanillaRefresh.pack // PackSection object from pack.mcmeta
Kotlin

Generated structure

For each imported datapack, a Kotlin file is generated containing:

  • A data object named after the datapack.
  • Nested data objects for each namespace (if multiple).
  • Nested enums or objects for each resource type:
    • Functions: All .mcfunction files.
    • Advancements: All advancements.
    • LootTables: All loot tables.
    • Recipes: All recipes.
    • Tags: All tags, further nested by type (Blocks, Items, Functions, etc.).
    • Worldgen: All worldgen resources, further nested by type (Biomes, Structures, etc.).

Subfolders in the datapack are preserved as nested objects.

Explore without generating

You can explore the content of a datapack programmatically without generating any code.

import io.github.ayfri.kore.bindings.api.exploreDatapacks

val datapacks = exploreDatapacks {
	github("user.repo:main")
}

val pack = datapacks.first()
println("Datapack: ${pack.name}")
println("Functions: ${pack.functions.size}")
pack.functions.forEach { println(" - ${it.id}") }
Kotlin

Download sources

GitHub

Downloads a repository or a specific asset from a release.

Patterns:

  • user.repo: Latest commit on the default branch.
  • user.repo:tag: Specific tag, branch, or commit.
  • user.repo:tag:asset.zip: Specific asset from a release.
github("pixigeko.minecraft-default-data:1.21.8")
Kotlin

Modrinth

Downloads the latest or a specific version of a Modrinth project.

Patterns:

  • slug: Latest stable version.
  • slug:version: Specific version ID or number.
modrinth("vanilla-refresh")
Kotlin

CurseForge

Downloads from CurseForge. Requires the CURSEFORGE_API_KEY environment variable.

Patterns:

  • projectId: Latest file for the project.
  • projectId:fileId: Specific file.
  • slug: Project slug.
  • slug:fileId: Specific file for a project slug.
  • URL: Full CurseForge project URL.
curseforge("418120") // Project ID
Kotlin

URL / local path

Patterns:

  • https://example.com/pack.zip
  • ./path/to/pack (Local folder)
  • ./path/to/pack.zip (Local zip)

Configuration

Global configuration

Defined in the configuration {} block:

Property Default Description
outputPath build/generated/kore/imported Directory where Kotlin files will be generated.
packagePrefix kore.dependencies Base package for all generated bindings.
generateSingleFile true If true, generates one Kotlin file per datapack.
skipCache false If true, re-downloads even if already in cache.
debug false Prints extra information during the process.

Per-datapack configuration

Defined in the block following a source:

github("user.repo") {
	remappedName = "MyPack"       // Change the generated object name
	packageName = "custom.pkg"    // Change the package for this pack
	subPath = "datapacks/main"    // Only import from this subfolder
	includes = listOf("data/**")  // Only include files matching these patterns
	excludes = listOf("**/test/**") // Exclude files matching these patterns
}
Kotlin

Cache

Downloaded files are cached in ~/.kore/cache/datapacks to speed up subsequent runs. Use skipCache = true in the global configuration or delete the cache folder to force a re-download.

Troubleshooting

  • Rate Limits: GitHub API is limited for unauthenticated calls.
  • CurseForge API: Ensure your API key is valid and has permissions for the project.
  • Invalid resources: If a resource type is unknown to Kore, it will be skipped to avoid generating invalid code.