FANDOM


Data Pack Creation Edit

So you want to have a go at creating a data pack? Feel like you have got the macho to tackle the fire beast that is minecraft functions and submit to Gamemode 4? This tutorial should take you through the whole process!

What is a datapack? Edit

Datapacks are a feature for Minecraft Java Edition 1.13, and contain things such as structure files, loot tables, advancements, and functions, all packaged neatly into a single folder to easily be installed in any world. They are akin to resource packs, except are installed on the server instead of the client. They offer many advantages over command-blocks such as selector-resolution efficiency, pre-parsing for faster execution, and recursion looping.

Gamemode 4 uses datapacks as a way to run commands without needing "physical" command blocks in world, and allows us to finally have access to features like loot-tables and advancements that are inaccessible with only one-clicks.

Pre-requisites Edit

This assumes you understand how to format JSON and use commands. JSON is used in advancements and tags, and commands are used in functions. This is not a tutorial for JSON or commands.

Getting Started Edit

The Template Pack can be found here : https://github.com/Gamemode4Dev/GM4_Datapacks/tree/master/gm4_template_pack

Before you can start work on actually coding your fancy module, you'll need to do some set-up first in order for both Minecraft and the Gamemode 4 clocking system to recognize your datapack. Download the template pack from our GitHub, and drag the entire `gm4_template_pack` into the datapacks folder of Minecraft world you are developing your module in.

First, you'll need to edit some files:

  1. The overarching `gm4_template_pack` folder can be renamed to whatever you are calling your module, such as `Ridable Bats` or `Draconic Eeveeloutions`
  2. The `template` folder needs to be renamed to the internal namespace of your files. This is the identifier that differentiates your files from anyone elses, even if they're both called the same thing. This folder should be formatted in snake_case, like `potion_swords` or `pig_tractors`, and must be in lowercase letters without special characters. This name will also be used in later setup steps and referred to as the MODULE_ID
  3. Two filed within the `gm4/tags/functions` folder need to be edited. Inside both `init_check.json` and `pulse_check.json` are a line that look like `"MODULE_ID:init_check"` or `"MODULE_ID:pulse_check"`. `MODULE_ID` in both needs to be replaced with the namespace you chose in step 2.
  4. Inside your renamed `template` folder, open the `functions` folder. There are 4 files here, `init` `init_check` `pulse_check` and `main`. These 4 files cannot be renamed otherwise the clocking system will not run your module. Inside `init_check`, `init`, and `pulse_check` you'll find several more instances of `MODULE_ID`. Replace those with the namespace you chose in step 2.
  5. Inside `init`, you'll also find a few instances of `MODULE_NAME`. This is the name of your module as it will appear in-game when the clocking system initializes it, like `Potion Swords` or `Pig Tractors`.
  6. Finally, rename the `_pack.mcmeta` file to `pack.mcmeta` (remove the leading underscore).

Now that you've set-up the files you need you can begin work on your actual command-writing. The `main` function gets run by the clocking system roughly once a second, and is where you should start your module. Additional function files and sub-directories can be added as you need them under your namespace, as well as any loot-tables, structure files ect... that you need. Good Luck!

Advancements Edit

If you want to use a custom advancement for your module, there is a template in `gm4/advancements` that you can edit. Rename all instances of `MODULE_ID` to your namespace as needed and give the advancement an icon, name, description ect... The root advancement should be left alone.

Tips Edit

If you're having trouble getting your main function to run, take a look at the output log. Minecraft parses datapack files when they're loaded in, and any syntax errors it finds will reported there.

If you're not getting any errors, double check that you've edited all the necessary files for your functions to run. You will not have to edit anything in the `minecraft` namespace, nor any of the functions in the `gm4` namespace.

Structure of a Gamemode4 Data Pack Edit

The Template Pack can be found here and all things below are explained in reference to this : https://github.com/Gamemode4Dev/GM4_Datapacks/tree/master/gm4_template_pack

gm4_template_pack       
  ㄴpack.mcmeta
  ㄴdata
      ㄴgm4
          ㄴadvancements
          ㄴfunctions
          ㄴtags
             ㄴfunctions
  ㄴminecraft
      ㄴtags
          ㄴfunctions
  ㄴtemplate
       ㄴfunctions                                        

gm4_template_pack Edit

This is the base folder. All other folders are stored in here.

gm4_template_pack/pack.mcmeta Edit

This must be present in all datapacks. It allows the base game to recognize and load your datapack. This file stores a descriptor of your data pack that is displayed when doing "/datapack <enable/disable>"

data/gm4/advancements Edit

This is where advancement files go. The template contains two, root.json and MODULE_ID.json.

MODULE_ID.json is a template for an advancement relating to the module. By default, it will connect to gm4:root(the inital advancement) and you will have to set an image, title,description and trigger.

RootJson

root.json file. Used as base for all advancements.

root.json is used as the starter point for all sub advancements. (See image to side)

In the future, we plan on releasing an online tool that will produce a datapack that rearranges your advancement files into a tree-like progression.

data/gm4/functions Edit

This contains three files

init.mcfunction is used when gm4 is first installed to set up the clocking system and prepare for modules to be run. It is triggered by minecraft/tags/update.mcfunction

tick.mcfunction is run every tick to run clocks and is triggered by minecraft/tags/tick.json

update.mcfunction is used to start the installation process of newly installed modules and check if an existing module is out of date. It is triggered by minecraft/tags/load.json

data/gm4/tags/functions Edit

This folder contains two files:

init_check.json is used to check if the module needs to install.

pulse_check.json is used to check if the module should tick.

Both are triggered by the gm4 base function.

data/minecraft/tags/functions Edit

This file contains two tags that minecraft uses, tick and load. Minecraft will run tick every game tick and load every time the game loads. Gamemode 4 uses this to tick its own clock module.

data/template/functions Edit

This contains four files:

init.mcfunction sets up everything a module needs to run, and checks if other installed modules are up to date. It is triggered by int_check.mcfunction

init_check.mcfunction is triggered by data/gm4/tags/init_check.json and check if the module needs to be initialised.

main.mcfunction is the main function of a module and is triggered by pulse_check.mcfunction

pulse_check.mcfunction is triggered by data/gm4/tags/pulse_check.json and pulses the module on it's assigned tick.

Technical Edit

This is gritting stuff about the clock module and more. Read this is you dare, and if you want bad stomach cramps:

Order of Functions Edit

Functiontickorder

Order that functions are triggered. Some are conditional on whether it is the right tick for them to run.

Below is a flow chart that the orders of functions are run. All functions reference are explained in "Structure of a Gamemode 4 Data Pack"

Each function is triggered in order, as show by the arrows. Some are run every tick (like data/gm4/functions/ticks) and some are run on when told to via a condition eg data/gm4/tags/functions/pulse_check)

Gamemode 4 Clock System Edit

Community content is available under CC-BY-SA unless otherwise noted.