75

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

75 emeralds28 replies4,534 views
Bertiecrafter started 04/07/2020 4:45 pm history
and replied 05/19/2020 3:59 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



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
Posted by avatar
Bertiecrafter
Level 49 : Master Robot
89

comment Login or register to post a reply.

28 replies

1
05/19/2020 2:18 amhistory
Level 1 : New Miner
NAchatmahr
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.
1
05/19/2020 3:59 pm
Level 49 : Master Robot
Bertiecrafter
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.
1
05/15/2020 10:54 pm
Level 1 : New Miner
Rune_Bloodstone
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.

Thanks.
1
05/16/2020 4:03 amhistory
Level 49 : Master Robot
Bertiecrafter
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.
1
05/15/2020 1:50 pm
Level 49 : Master Robot
Bertiecrafter
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! =)
1
05/11/2020 8:07 pm
Level 17 : Journeyman Engineer
advoacite
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

https://www.nbt-data.com/datapack-generator
2
05/12/2020 8:50 amhistory
Level 49 : Master Robot
Bertiecrafter
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.
1
05/12/2020 11:12 am
Level 17 : Journeyman Engineer
advoacite
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 ;)
1
05/07/2020 4:16 pm
Level 13 : Journeyman Lemon
Chimerabot
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...
1
05/07/2020 5:30 pm
Level 49 : Master Robot
Bertiecrafter
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.
1
05/06/2020 10:42 am
Level 14 : Journeyman Engineer
JackieT
Bruh this is just how to make a daypack and then also some info about commands
1
05/06/2020 11:44 am
Level 49 : Master Robot
Bertiecrafter
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.
1
04/29/2020 7:39 pm
Level 4 : Apprentice Crafter
The_Dirty_Pirate
Don't really understand.....😐😐❓❓
2
04/29/2020 5:07 pm
Level 4 : Apprentice Crafter
Rukreep
Interesting...
3
04/27/2020 1:38 pm
Level 1 : New Miner
WhiteRavenZX
no entiendo nada ;-;
1
04/29/2020 7:44 pm
Level 10 : Journeyman Warrior
GiantPlaytime
translation I do not understand anything ;-;
2
04/27/2020 2:11 pmhistory
Level 49 : Master Robot
Bertiecrafter
GOOGLE TRANSLATE IN ACTION:

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
2
04/27/2020 1:39 pm
Level 1 : New Miner
WhiteRavenZX
lol porque no escribe en español
1
04/29/2020 7:42 pm
Level 10 : Journeyman Warrior
GiantPlaytime
translation lol because he doesn't write in spanish
7
04/16/2020 7:58 pm
Level 12 : Journeyman Architect
Darth_Builder
it's actually helpful
7
04/12/2020 8:33 pm
Level 34 : Artisan Crafter
SuperBuildcraft
Gotta say, this is an amazing tutorial. I already knew data packs pretty well, but this posts still gave me new knowledge!
2
04/26/2020 8:33 pm
Level 1 : New Miner
AKRAMSONTA
como me descargo estoooo
2
04/27/2020 1:40 pm
Level 1 : New Miner
WhiteRavenZX
no lo se
5
04/08/2020 2:41 pm
Level 25 : Expert Toast
mouse36
cool this is helpful i like it
4
04/08/2020 7:44 amhistory
Level 14 : Journeyman Explorer
J4TZplayZ
Cool. Maybe custom game resources such as modelling & textural animation mechanics next time? :)
3
04/08/2020 8:07 am
Level 49 : Master Robot
Bertiecrafter
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
4
04/08/2020 12:49 am
Level 26 : Expert Button Pusher
Millimedia Games
Great tutorial!
4
04/08/2020 2:09 am
Level 49 : Master Robot
Bertiecrafter
Thank you :P
Planet Minecraft Logo

Website

© 2010 - 2020
www.planetminecraft.com

Welcome