Use this as a starting point for your own datapack for Minecraft Java Edition. The template provides starting pack structure, and scripts to package and install your datapack.
You will need to install these programs to use the scripts with this template:
find
git
make
jq
sed
zip
Most Linux systems come with find
and sed
pre-installed.
- Clone this repository.
- Rename the directory
src/data/your_datapack_namespace
to a name of your choice. - Edit all of the files in
src/data/minecraft/tags/functions/
to changeyour_datapack_namespace
to the exact name you picked for the directory in step 2. - Modify
src/pack.mcmeta
and change the"description"
property to set the name and description for your datapack. - Replace
src/pack.png
with your own icon.
The template includes some example code that prevents creepers from breaking blocks when they explode. You probably want to replace the example code with your own.
There are three functions provided in the
src/data/your_datapack_namespace/functions/
directory. Each .mcfunction
file
defines a function.
load.mcfunction
runs when the datapack is installed - use this function for setup steps that need to run once, like adding scoreboardstick.mcfunction
runs every game tickuninstall.mcfunction
runs when the datapack is uninstalled - use this for cleanup, for example for removing the scoreboards that you added inload.mcfunction
.
Note that those three functions are set up by the configuration in the JSON
files in src/data/minecraft/tags/functions/
. It is important that your
datapack directory name matches the function namespace in those files!
You can adjust special scheduling for functions. For example if you don't want
a function that runs on every tick for example you can delete
src/data/minecraft/tags/functions/tick.json
and delete
src/data/your_datapack_namespace/functions/tick.mcfunction
.
One way to reduce lag from your datapack is to remove the tick
, and to instead
schedule a function that runs less often - for example once every second. To do
that use the schedule
command in your load
function:
schedule function your_datapack_namespace:do_something_every_second 1s
That schedules a function called
your_datapack_namespace:do_something_every_second
. You need to define that
function by creating a new file called
src/data/your_datapack_namespace/functions/do_something_every_second.mcfunction
.
Make sure to clean up by stopping the scheduled function in your uninstall
function:
schedule clear your_datapack_namespace:do_something_every_second
To package your datapack into a zip file run,
$ make
To install the datapack to your local Minecraft install run,
$ make install
This will automatically build the datapack package if there have been changes to source files since the package was last built.
The install script attempts to find your Minecraft directory automatically. It will install to the first directory it finds in this order:
- ~/.var/app/com.mojang.Minecraft/data/minecraft
- ~/.minecraft
If the script picks the wrong directory, or if it does not find your minecraft directory, you can override the directory path with an environment variable like this:
$ minecraft_directory=~/my/minecraft/directory make install