291

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

291 emeralds71 replies22,742 views
Bertiecrafter started 4/7/20 4:45 pm history
Junkwon replied 6/13/2021 9:26 am


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.

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. Debugging & Quality Control
  5. Let's play tag! (Load, tick, uninstall and other functions)
  6. Who? What? Where? But How? (Target Selectors and Relative Coordinates)
  7. The Scoreboard
    1. The Scoreboard: Where numbers are created, stored and juggled
    2. The Scoreboard (+ Triggers): We've got to go deeper!
  8. The Command Environment (/execute)
  9. Check a lot of things, but only once! (+ /execute if/unless)
  10. Named Binary Tag (NBT) format
    1. NBT: The hidden layer behind all of Minecraft
    2. NBT: Taking Control (/data & /execute store)
    3. NBT based targeting (+ /execute if data)
  11. The return of JSON
    1. The return of JSON: Introduction & Wiki Pages
    2. The return of JSON: The Workshop (+ Custom Recipes)


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.

Cheat sheet
  • Functions are files that consist of multiple commands. Tags are groups of functions.
  • Conventions
    • 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.
    • 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 Basics
  • Target Selectors:
    • 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.
  • Scoreboard:
    • 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.
  • Command Environment:
    • By default data pack commands execute as the "server entity" at worldspawn.
    • The /execute command can change the context of execution.
    • The /execute command has "instructions" that can be chained together as much as you want.
    • Order matters in the /execute command.
    • Full /execute syntax
  • NBT:
    • NBT looks like JSON, but distinguishes between more types (with suffixes) and doesn't require quotes around key names.
    • JSON within NBT must be surrounded by apostrophes!
    • Use /data to edit NBT data.
    • Use /execute to store NBT data on the scoreboard for arithmetic operations, before moving it back.
    • 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
    • Check for NBT using the "nbt=" target selector, the "/execute if data" instruction or the "/execute if block xyz <block>[​states]{nbt}" instruction.
    • 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.
  • JSON Extended:
Posted by avatar
Bertiecrafter
Level 62 : High Grandmaster Cyborg
355

Create an account or sign in to comment.

71 replies

1
06/13/2021 9:26 am
Level 1 : New Miner
Junkwon
Junkwon avatar
I have mobile jow i instal mods?
1
05/29/2021 2:49 pm
Level 1 : New Miner
User3608768G
User3608768G avatar
gg
1
05/25/2021 1:46 pm
Level 1 : New Miner
Isaacarieljaramillotorres
Isaacarieljaramillotorres avatar
esplicame como instalarme naruto minecraft
1
05/25/2021 1:46 pm
Level 1 : New Miner
Isaacarieljaramillotorres
Isaacarieljaramillotorres avatar
isaac
1
05/25/2021 1:17 am
Level 1 : New Miner
User3621169G
User3621169G avatar
oi
1
05/22/2021 11:59 pm
Level 1 : New Miner
dpu
dpu avatar
no entendi ;-;
1
05/20/2021 5:12 pm
Level 1 : New Miner
sofi87hds
sofi87hds avatar
holaaaaaa
1
05/16/2021 3:09 am
Level 1 : New Miner
S1k
S1k avatar
holaaaaaaaaaaaaa
1
05/12/2021 11:45 am
Level 1 : New Miner
User3598630G
User3598630G avatar
ben 10
2
05/04/2021 9:18 pm
Level 1 : New Miner
Andrea0608
Andrea0608 avatar
grax =3
1
05/03/2021 11:09 am
Level 1 : New Miner
Wt-Happy-Villager
Wt-Happy-Villager avatar
aboba
2
04/13/2021 12:35 pm
Level 1 : New Miner
Mirilapro
Mirilapro avatar
hola
2
03/25/2021 7:13 pm
Level 23 : Expert Warrior
LukaMudrohYT
LukaMudrohYT avatar
290 th sub Congratulations Bro!
I don't need this sh1t but ok lol :'D
1
03/26/2021 2:36 amhistory
Level 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
Thank you! It's a bit odd, but also satisfying how the counter on this submission is only showing 256
3
03/11/2021 9:44 pm
Level 10 : Journeyman Miner
-Google-
-Google- avatar
It so cool!!!
2
02/23/2021 7:34 am
Level 1 : New Miner
ceylin551042
ceylin551042 avatar
Bu nasıl indiriliyor acaba
???
1
02/23/2021 11:41 am
Level 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
Translated to "I wonder how this is downloaded"

You cannot download anything in this, these are articles teaching you how to make your own data pack.
4
01/25/2021 12:51 am
Level 32 : Artisan Pixel Painter
Dunk__
Dunk__ avatar
thx now I know how to make datapacks!! :)
3
01/18/2021 8:04 am
Level 1 : New Explorer
SanctuaryThief
SanctuaryThief avatar
This is a great resource, and well worth the read. Thank you!
1
01/15/2021 1:01 pm
Level 1 : New Miner
anoine77_yt
anoine77_yt avatar
io 2
1
12/07/2020 10:44 pm
Level 1 : New Miner
User3329379G
User3329379G avatar
seerrrrrrrrrrrrrrrrrrrrrrfffff
1
12/07/2020 5:54 pm
Level 1 : New Miner
User3329379G
User3329379G avatar
io1
1
11/14/2020 1:24 pm
Level 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
Part 10 released! I also reorganized the "Resources, Notes & Best Practices" section with a multi-level list and wrapping it all in a spoiler.
1
11/11/2020 5:48 pm
Level 1 : New Miner
rodrigohaick
rodrigohaick avatar
Oi
3
09/11/2020 7:16 am
Level 6 : Apprentice Warrior
pronetherite145
pronetherite145 avatar
Cool
1
09/04/2020 1:48 pmhistory
Level 19 : Journeyman Pirate
The Dirty Pirate
The Dirty Pirate avatar
I use windows 10 so how would I do this? :[
1
03/25/2021 7:13 pm
Level 23 : Expert Warrior
LukaMudrohYT
LukaMudrohYT avatar
Same as win 7
2
09/04/2020 4:33 pm
Level 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
All tutorials are cross-platform (besides the first one). So assume you can use all info as-is, unless it specifically tells you that a certain section is not for Windows. On windows 10, make sure you know whether or not you're using the Java or Bedrock Edition.

Java edition has a launcher and no in-game store, which supports data packs. Bedrock Edition does have an in-game store, but doesn't support data packs. You'll need to find yourself a different tutorial on behavior packs if you want to modify Bedrock Edition functionality.
2
08/10/2020 2:02 pm
Level 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
Published part 9.3: NBT based targeting (+ /execute if data)!
1
08/07/2020 10:45 am
Level 1 : New Miner
HIHIHIHHI
HIHIHIHHI avatar
Data pack to minecraft players
1
03/25/2021 7:13 pm
Level 23 : Expert Warrior
LukaMudrohYT
LukaMudrohYT avatar
So?
1
07/19/2020 6:21 pm
Level 5 : Apprentice Crafter
pupit
pupit avatar
fanf
2
09/01/2020 10:29 am
Level 21 : Expert Archer
4nd73_j4q
4nd73_j4q avatar
you trying to spell fnaf
2
08/21/2020 9:23 pm
Level 23 : Expert Robot
barrett41z10
barrett41z10 avatar
... what?
3
07/19/2020 10:51 am
Level 1 : New Miner
marcelocajado
marcelocajado avatar
Eu realmente aprecio que você continue atualizando este datapack. Agradeço sua dedicação 🙏
3
07/19/2020 10:57 am
Level 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
I had to google translate this and I hope it translated correctly, but thank you for the kind words! =)
1
07/04/2020 7:53 pm
Level 1 : New Miner
cocoruta
cocoruta avatar
eu sei isso
2
06/23/2020 1:34 pm
Level 25 : Expert Skinner
RealPandaBoyPlaysYT
RealPandaBoyPlaysYT avatar
thanks
1
06/16/2020 11:36 am
Level 1 : New Miner
Duda games25
Duda games25 avatar
I como wue joga o datapack me ajudem
1
06/16/2020 11:33 am
Level 1 : New Miner
Duda games25
Duda games25 avatar
Oi
1
06/06/2020 8:51 pm
Level 1 : New Miner
TheOnlyXDgamerZ
TheOnlyXDgamerZ avatar
How to activate the packs
1
06/11/2020 9:55 am
Level 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
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.
3
06/01/2020 4:46 pm
Level 1 : New Crafter
schwar
schwar avatar
Cool! This makes so much more sense than the Minecraft Gamepedia.
1
05/19/2020 2:18 amhistory
Level 1 : New Miner
NAchatmahr
NAchatmahr avatar
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.
2
05/19/2020 3:59 pm
Level 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
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.
3
05/30/2020 7:46 pm
Level 21 : Expert Engineer
Loumardes
Loumardes avatar
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
1
05/15/2020 10:54 pm
Level 1 : New Miner
Rune_Bloodstone
Rune_Bloodstone avatar
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.
2
05/16/2020 4:03 amhistory
Level 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
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 62 : High Grandmaster Cyborg
Bertiecrafter
Bertiecrafter avatar
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 37 : Artisan Engineer
advoacite
advoacite avatar
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
Planet Minecraft

Website

© 2010 - 2021
www.planetminecraft.com

Welcome