Function Data Packs for Dummies | A tutorial blog series!school

94 emeralds36 replies6,516 views
Bertiecrafter started 04/07/2020 4:45 pm history
cocoruta replied 07/04/2020 7:53 pm

Let's learn about Function Data Packs

Have you thought about creating a data pack, but have no idea how to start or perhaps you already know how to create basic data packs, but would like to learn more? Fortunately, I took the time to create an extensive blog tutorial series that anyone can start reading. Even if your command knowledge doesn't go beyond /time, /kill and /gamemode, you can still start right this second and create your first datapack today. The more experienced data pack creators can skip ahead the first few posts and see if there is anything that I can teach you or you can correct me on.

The series is far from finished, more posts will be created in the future and existing posts might be improved. Feedback and questions are welcome in the replies below.

Table of Contents

  1. What are data packs and why would I create them?
  2. Who's JSON (and what's /tellraw)?
  3. Creating a new data pack and your first function
  4. Let's play tag! (Load, tick, uninstall and other functions)
  5. Who? What? Where? But How? (Target Selectors and Relative Coordinates)
  6. The Scoreboard
    1. The Scoreboard: Where numbers are created, stored and juggled
    2. The Scoreboard (+ Triggers): We've got to go deeper!
  7. The Command Environment (/execute)
  8. Check a lot of things, but only once! (+ /execute if/unless)
  9. Named Binary Tag (NBT) format
    1. NBT: The hidden layer behind all of Minecraft
    2. NBT: Taking Control (/data & /execute store)

Resources, Notes & Best Practices

The tutorials provide links to resources whenever they are needed. However, you can use the following list for an overview of these resources, notes and best practices.
  • Functions are files that consist of multiple commands. Tags are groups of functions.
  • JSON: Do not add a comma behind the last item of an array or object
  • JSON structure for text components (/tellraw, but also signs, name tags and books)
  • JSON for text components: Do not use array notation, always start with an object.
  • Explanation of the JSON/NBT type icons that are used in JSON/NBT structures on the wiki pages
  • Contents of pack.mcmeta and latest pack_format number
  • Give your data pack a unique namespace (like your own username) and also create a folder inside the functions folder to uniquely identify functions across your own data packs.
  • Any kind of tag starts with #, like /function #minecraft:load. Besides minecraft:load, minecraft:tick is another built-in tag that you can register your functions in.
  • You should provide an uninstall function to avoid leaving a mess when your datapack gets uninstalled.
  • Any player arguments in commands can have target selectors, which can target non-player entities as well.
  • All target selector variables and arguments
  • The distance target selector argument needs a range, since an exact distance will never match anything. So use distance=..5 instead of distance=5
  • ~x ~y ~z defines a location relative to the coordinates of the execution location, while ^left ^up ^forwards also takes the rotation of the execution location into account.
  • The health scoreboard criteria shows up as fancy hearts in the tab list.
  • The display name of scoreboard objectives can contain unicode characters (fun symbols), which show up in the display slots.
  • All scoreboard criteria
  • The scoreboard doesn't allow decimals. Multiply the value by a big number before dividing to see more digits behind the dot.
  • Read-only objectives can be modified by first copying the values to a dummy objective using the "operation" subcommand of /scoreboard
  • The values of an objective with "trigger" criteria can be modified by /trigger. Since /trigger can be used by non-op players, you can create clickable buttons in chat using /tellraw and then fire functions whenever their score is 1.
  • Order matters in the /execute command
  • Full /execute syntax
  • Always put an #As/At comment on the first line of a function to avoid spending hours on debugging. You can split it up into separate #As and #At comments if the location is different from the executing entity location.
  • Try to be efficient with checks and avoid duplicates.
  • JSON within NBT must be surrounded by apostrophes!
  • NBT: Color Picker and Hex to Integer conversion
  • NBT: Chunk Format - For all mobs, projectiles, vehicles, falling blocks, block entities and a couple of other things.
  • NBT: Player.dat Format - This page describes the NBT format for the "player" entity and all items.
  • NBT: UUID generator
  • NBT Path syntax
  • You cannot access JSON elements within NBT (for text on signs or in books) using NBT paths, since JSON must always be provided as a string instead of an object.
Posted by avatar
Level 51 : Grandmaster Cyborg

comment Login or register to post a reply.

36 replies

07/04/2020 7:53 pm
Level 1 : New Miner
eu sei isso
06/23/2020 1:34 pm
Level 6 : Apprentice Modder
06/16/2020 11:36 am
Level 1 : New Miner
Duda games25
I como wue joga o datapack me ajudem
06/16/2020 11:33 am
Level 1 : New Miner
Duda games25
06/06/2020 8:51 pm
Level 1 : New Miner
How to activate the packs
06/11/2020 9:55 am
Level 52 : Grandmaster Cyborg
Please provide more information if you are having problems with something. What are you trying to do and what isn't working?

Part 3 should explain how to create a data pack and check if it works.
06/01/2020 4:46 pm
Level 1 : New Explorer
Cool! This makes so much more sense than the Minecraft Gamepedia.
05/19/2020 2:18 amhistory
Level 1 : New Miner
I have a idea but I dont know if it can be done. But I was wondering if a double ender chest might be do able... The thinking for this is to some how get the double chest data of a normal chest, add or change the ender chest to be similar but with the ender chest properties. A bigger ender chest!? I think it would be fun or great to have for worlds/servers with alot of new items. Tho I think this might be pushing it but never hurts to ask or try.
05/19/2020 3:59 pm
Level 52 : Grandmaster Cyborg
Unfortunately, it's not possible for the following reasons:
- Ender chests are stored on the player data itself and you can't modify player data.
- Data modifications require a good understanding of NBT (9.1) and how to modify it (upcoming 9.2)

- Even if ender chests would be normal chests, Minecraft does have some error-correcting code in place. This is very inconsistent though, so I'm not sure if it will tell you off if you try to put an item in a non-existant slot.
- Another thing you could come up with is using normal chests and writing/reading from /data "storage". The problem with that is that you can't dynamically select data. (See 9.1, if you would put each player chest into a key with a certain value, you can't get access to the value based on a key, unless you write that key statically into the function file. AKA you can't insert any kind of "variable" to get a compound value by key).
- You could then try putting the key as integer into the chest data and use a list of chests instead of a compound, but then you need to assign each player a new id and then try every piece of chest data for that id until you find one. (By taking the first chest data from the list, checking it and moving it to the end of the list, repeat).

As you can see, it's really easy to stumble down a rabbit hole and I don't even know if you can work out that last option without walking into another wall.
05/30/2020 7:46 pm
Level 18 : Journeyman Engineer
actually you can quite easily store and load back the whole chest data at once using /data into a storage, just target the item list itself instead of each individual items, I have done something similar with structureblocks

What will need you extra work is the player id system to assign back enderchest, and adding a second id layer to distinct each enderchest per players

@Nachatmahr, if you have discord, there is many dedicated discord servers you may join, and nice people wich can help you to figure out stuff and get unstuck with yours projects

Also my own experience learning datapacking was to get my hand of few commands technics, find out a creative way to do something with it and doing it

and now I got way much more creatives ideas which I know I can implement myself, than I have time to achieve them ;)

Currently working on ambitious projects on minecraft never seen before, I wish you good luck and great datapacking experiences
05/15/2020 10:54 pm
Level 1 : New Miner
Great series so far. I was having trouble following the info on Gamepedia, but I got everything working up to tutorial 4! What I really am having trouble with is changing loot tables. A cow that drops a diamond might be interesting! Can you add something about loot tables?

I think the problem I'm having is how to get my custom loot table (namespaced) to replace the vanilla one. I can unload the vanilla datapack and when I kill a cow it drops nothing. Not sure how I can get my cow.json to become active.

05/16/2020 4:03 amhistory
Level 52 : Grandmaster Cyborg
You could replace the vanilla loot table. So make the file path and filename perfectly match the vanilla minecraft one, causing it to overwrite it.
You can go to .minecraft/versions/<version>/<version>.jar and open it with 7Zip or WinRAR to find the file path of the loot table, so you can replicate the path inside the minecraft namespace in your datapack.

Another way is using the /data command (will be covered in a future tutorial, perhaps part 9.2) to overwrite the DeathLootTable NBT tag (see 9.1 for getting to know NBT) for each newly spawned cow. Make sure to give each cow a tag to prevent setting the tag every tick. Something like /data modify entity @e[​type=cow,tag=!set_loot_table] ....... & /tag @e[​type=cow,tag=!set_loot_table] add set_loot_table

Syntax of loot tables themselves might not be covered for a while as covering everything about commands is my first priority. Advancements and predicates are also on the list for after commands, so I'd have to think about what comes next when we're at that point.
05/15/2020 1:50 pm
Level 52 : Grandmaster Cyborg
Is it me or did "recipe packs" (that use nothing but recipe files) decrease by A LOT this last month? Whether it's because of this tutorial series or not, I enjoy seeing the higher quality uploads! =)
05/11/2020 8:07 pm
Level 21 : Expert Engineer
your pack.mcmeta is wrong

"pack": {
"description": "Some awesome description",
"pack_format": 5

If you want to you could link my datapack generator for anyone who just wants to save time at the start, I was going to do a blog on this topic myself but you beat me too it

Check it out and if you think it helpful add it to your blog post

05/12/2020 8:50 amhistory
Level 52 : Grandmaster Cyborg
Although the structure of pack.mcmeta I posted is not wrong, it uses the wrong pack_format number. At the time of writing, it said that the number was not used and therefore I wrote a "1". I will update the blog with the right number and a minecraft wiki source for up-to-date format numbers.
05/12/2020 11:12 am
Level 21 : Expert Engineer
yeah no problem i was just confused i suppose if you want to support older version of minecraft you would change the umber to suit ;)
05/07/2020 4:16 pm
Level 17 : Journeyman Lemon
Is there changeable variables for visibility in, say, water or lava? I was thinking of creating a datapack in anticipation of the Nether update allowing you to swim in lava as you would in water, but that might be too complicated...
05/07/2020 5:30 pm
Level 52 : Grandmaster Cyborg
No, you can't really change graphics settings or modify the block behaviour. However, you can see if a resource pack allows you to make the water a little more opaque (it works for the block textures of water, but idk about the "fog" you see while you swim) or perhaps night vision, fire resistance or water breathing increase visibility in lava? You'd have to just try it.
05/06/2020 10:42 am
Level 16 : Journeyman Engineer
Bruh this is just how to make a daypack and then also some info about commands
05/06/2020 11:44 am
Level 52 : Grandmaster Cyborg
Well, it's in the title.... Idk what you expected haha
Even though commands are a priority, in a far future the other parts of a datapack will be covered as well.
The tutorial series is meant to teach you about creating data packs, not just create 1 specific complex datapack. If it was just that, a lot of people would struggle to create a different datapack.
There are challenges and a quick start guide though, if you're looking for more hands-on experience.
04/29/2020 7:39 pm
Level 6 : Apprentice Crafter
Don't really understand.....😐😐❓❓
04/29/2020 5:07 pm
Level 8 : Apprentice Toast
04/27/2020 1:38 pm
Level 1 : New Miner
no entiendo nada ;-;
04/29/2020 7:44 pm
Level 12 : Journeyman Warrior
translation I do not understand anything ;-;
04/27/2020 2:11 pmhistory
Level 52 : Grandmaster Cyborg

ES: Intenta poner toda la página en el traductor de Google: haga clic aquí
EN: Try putting the entire page in Google Translate: Click here

I tried haha
04/27/2020 1:39 pm
Level 1 : New Miner
lol porque no escribe en español
04/29/2020 7:42 pm
Level 12 : Journeyman Warrior
translation lol because he doesn't write in spanish
04/16/2020 7:58 pm
Level 15 : Journeyman Architect
it's actually helpful
04/12/2020 8:33 pm
Level 36 : Artisan Crafter
Gotta say, this is an amazing tutorial. I already knew data packs pretty well, but this posts still gave me new knowledge!
04/26/2020 8:33 pm
Level 1 : New Miner
como me descargo estoooo
04/27/2020 1:40 pm
Level 1 : New Miner
no lo se
04/08/2020 2:41 pm
Level 25 : Expert Toast
cool this is helpful i like it
04/08/2020 7:44 amhistory
Level 15 : Journeyman Explorer
Cool. Maybe custom game resources such as modelling & textural animation mechanics next time? :)
04/08/2020 8:07 am
Level 52 : Grandmaster Cyborg
Both of these belong to resource packs. I first need to finish covering the commands area of datapacks, then extend to other technical files like advancements, recipes, structures and all that. In the end, if everything that's closer to the core of datapacks is covered, I might write about resource packs xD
04/08/2020 12:49 am
Level 27 : Expert Button Pusher
Millimedia Games
Great tutorial!
04/08/2020 2:09 am
Level 52 : Grandmaster Cyborg
Thank you :P
Planet Minecraft Logo


© 2010 - 2020