Simple Timer Datapack with Kore
Table of Contents
- Simple Timer Datapack with Kore
- Prerequisites
- Creating the Timer Datapack with Commands
- Step 1: Setting Up the Datapack
- Step 2: Adding the Timer Functionality
- Step 3: Loading the Datapack
- Creating the Timer Datapack with Kore
- Step 1: Setting Up the Project
- Step 2: Adding the Timer Functionality
- Step 3: Building and Loading the Datapack
- A Simpler Approach: the Scheduler
Welcome to the world of Minecraft datapack creation! If you've ever wanted to create your own Minecraft datapack but felt limited by traditional tools, Kore, a Kotlin-based library, is here to make the process easier and more efficient. In this article, we'll guide you through creating a simple datapack that displays a message every 20 seconds using the "tick" function. We'll show you how to do this using traditional commands and then how to achieve the same result using Kore.
Prerequisites
Before we begin, ensure you have the following:
- Minecraft 1.21.11 installed
- Basic understanding of Minecraft commands
- Kotlin and Kore setup (refer to the Kore Template for setup instructions)
Check Kore Introduction for more information on how to set up Kore in your Kotlin project.
Creating the Timer Datapack with Commands
Step 1: Setting Up the Datapack
-
Create the Datapack Folder:
- Navigate to your Minecraft
savesdirectory. - Open the folder of the world where you want to add the datapack.
- Inside the world folder, create a new folder named
datapacks. - Inside the
datapacksfolder, create a new folder for your datapack, e.g.,timer_datapack.
- Navigate to your Minecraft
-
Create the
pack.mcmetaFile:- Inside the
timer_datapackfolder, create a file namedpack.mcmeta. - Add the following JSON content to the file:
{ "pack": { "min_format": 94, "max_format": 94, "description": "A simple timer datapack" } }- Since 1.21.9,
pack.mcmetausesmin_format/max_formatinstead of the oldpack_format;94is the data pack format for 1.21.11.
- Inside the
Step 2: Adding the Timer Functionality
-
Create the Functions Folder:
- Inside the
timer_datapackfolder, create a folder nameddata. - Inside the
datafolder, create another folder namedtimer. - Inside the
timerfolder, create a folder namedfunction. (Since 1.21 these directories are singular:function, notfunctions.)
- Inside the
-
Create the
tick.mcfunctionFile:- Inside the
functionfolder, create a file namedtick.mcfunction. - Add the following commands to the file:
scoreboard players add @a timer 1 execute as @a[scores={timer=400..}] run say 20 seconds have passed! execute as @a[scores={timer=400..}] run scoreboard players set @a[scores={timer=400..}] timer 0 - Inside the
-
Create the
load.mcfunctionFile:- Inside the
functionfolder, create a file namedload.mcfunction. - Add the following commands to the file:
scoreboard objectives add timer dummy - Inside the
-
Create the
tick.jsonFile:- Inside the
datafolder, create a folder namedminecraft. - Inside the
minecraftfolder, create a folder namedtags. - Inside the
tagsfolder, create a folder namedfunction. - Inside the
functionfolder, create a file namedtick.json. - Add the following JSON content to the file:
{ "values": [ "timer:tick" ] } - Inside the
-
Create the
load.jsonFile:- Inside the
functionfolder, create a file namedload.json. - Add the following JSON content to the file:
{ "values": [ "timer:load" ] } - Inside the
Step 3: Loading the Datapack
-
Load the Datapack:
- Start Minecraft and open the world where you added the datapack.
- Use the command
/reloadto load the datapack. - You should see a message in the chat confirming the datapack is loaded.
-
Test the Timer:
- Wait for 20 seconds and you should see the message "20 seconds have passed!" in the chat.
Creating the Timer Datapack with Kore
Step 1: Setting Up the Project
-
Clone the Kore Template:
- Clone the Kore Template repository to your local machine.
-
Open the Project:
- Open the project in your preferred Kotlin IDE (e.g., IntelliJ IDEA).
Step 2: Adding the Timer Functionality
- Create the Timer Function:
- Inside the
src/main/kotlindirectory, create a new Kotlin file namedTimer.kt. - Add the following Kotlin code to the file:
import io.github.ayfri.kore.arguments.scores.ScoreboardCriteria import io.github.ayfri.kore.arguments.scores.score import io.github.ayfri.kore.arguments.types.literals.allPlayers import io.github.ayfri.kore.arguments.types.literals.self import io.github.ayfri.kore.commands.execute.execute import io.github.ayfri.kore.commands.say import io.github.ayfri.kore.commands.scoreboard.scoreboard import io.github.ayfri.kore.dataPack import io.github.ayfri.kore.functions.load import io.github.ayfri.kore.functions.tick import kotlin.io.path.Path fun main() { val seconds = 20 // Change this value to the number of seconds you want to wait before the message is sent. val datapack = dataPack("timer") { load { scoreboard.objectives.add("timer", ScoreboardCriteria.DUMMY) } tick { scoreboard.objective("timer").add(allPlayers(), 1) execute { ifCondition { score(self(), "timer") greaterThanOrEqualTo seconds * 20 } run { say("20 seconds have passed!") scoreboard.objective("timer").reset(allPlayers()) } } } path = Path("path/to/your/minecraft/saves/[Your World Name]/datapacks") } datapack.generateZip() } - Inside the
Step 3: Building and Loading the Datapack
-
Build the Datapack:
- Use the build tool provided by the Kore template to build the datapack.
- The built datapack will be located in the
builddirectory.
-
Load the Datapack:
- Copy the built datapack to the
datapacksfolder of your Minecraft world. - Start Minecraft and open the world where you added the datapack.
- Use the command
/reloadto load the datapack. - You should see a message in the chat confirming the datapack is loaded.
- Copy the built datapack to the
-
Test the Timer:
- Wait for 20 seconds and you should see the message "20 seconds have passed!" in the chat.
A Simpler Approach: the Scheduler
The version above counts ticks by hand with a scoreboard, which is great for learning how timers work under the hood. But Kore ships a helpers module with a Scheduler that wraps Minecraft's /schedule command, so you do not have to manage objectives, the tick function, or execute checks at all.
First, add the helpers module to your dependencies (alongside the core kore one):
implementation("io.github.ayfri.kore:helpers:VERSION")
Then the whole timer becomes a few lines:
import io.github.ayfri.kore.arguments.numbers.seconds
import io.github.ayfri.kore.commands.say
import io.github.ayfri.kore.dataPack
import io.github.ayfri.kore.helpers.schedulerManager
import kotlin.io.path.Path
fun main() {
val datapack = dataPack("timer") {
schedulerManager {
// Runs 20 seconds after load, then repeats every 20 seconds.
addScheduler(20.seconds, 20.seconds) {
say("20 seconds have passed!")
}
}
path = Path("path/to/your/minecraft/saves/[Your World Name]/datapacks")
}
datapack.generateZip()
}
addScheduler(delay, period) takes a first delay and a repeat period, both as readable TimeNumber values like 20.seconds or 5.ticks. Drop the period argument and it runs only once. No scoreboard, no tick function, no manual reset. For delayed tasks, cancellation, and scheduling by function reference, see the Scheduler docs.
Need a per-entity countdown instead of a global loop (a respawn delay, an ability cooldown)? The
oopmodule has aregisterTimer(...)helper withstart(entity)andonComplete(entity) { ... }methods, plus a boss-bar variant. Check the OOP module docs.
Congratulations! You've successfully created a simple timer datapack that displays a message every 20 seconds, first with traditional commands, then with Kore's scoreboard DSL, and finally with the one-liner Scheduler from the helpers module. Happy coding!