Minecraft Datapack Developer Tools

By Jesse Strijker | Feb 25th , 2024

After two weeks of programming minecraft datapacks, one can realise that datapacks dont really have an effective programming language. The programming you do are Minecraft commands and can be limited in nature. As per last week where I explained the inability to have variables in most commands.

A prime example was encountered this week. For the game’s magic system a mana system is used. Based on if you have high mana or low mana, a weapons function and visuals should swap. Example: A low mana sword, steals hearts, and a high mana sword steals mana. 

This requires for each player, for each swapable weapon for each inventory and hotbar slot to be checked for a weapon and if it needs to be swapped when the player reaches the threshold for low or high mana. Normally you would do this with a few loops in code. To loop through all players, then through weapons there are, and lastly through all slots in players inventory checking for a weapon to replace. This is not possible in mc functions however. Simply altering the variable of the slot number to be checked is not possible. So this needs be done with a lot, but i mean a lot of if statements, all cases have to be written out. If the player has high mana, run this function, and in that function all inventory slots are checked for a specific weapon and replaced. This means for each weapon 35 slots to be checked for high mana and 35 slots to be checked for low mana. E.g. a lot of slots and a lot of copy pasting if done manually.

Luckily that is not what was opted for. I wrote a script to write my mcfunctions file. So basically a script for a script. In javascript i generate a file, and loop through all inv slots and generate a Minecraft command for it which is placed in the mc functions file. This file can be placed in the datapack and ran in either the loop function or based on a mana change and it works. Below is an image of such a file it generates.

Quite repetative as you can see. The script was written in JS with node.js. 

An example of it working in game:

Category: Minecraft, Programming