Data
This tutorial is about the /data command. It is very complicated and in my opinion the most complicated command which is why it is last. It is very advanced and useful and I had to use it with the collab I did with Blue Commander on More Enchants. However feel free to skip this and come back later if it gets too complicated. The reason that motivated me to do this was because in mcstacker.com the data command is very limited. Selectors play a big part in this so if you aren't that advanced with them you won't be able to do that cool stuff with data, like target specific items on the floor who have a custom tag in their item data and are in a radius of 1 of a player.
Ok the first parameter is the type of operation you want. There are four options, get, merge, modify and remove. The difference between merge and modify is that merge you have hard code the data you want to apply and modify applies it from a specified entity. Following this is always going to be block or entity and then the selector for entity or the coordinates for block. For entity make sure you only have one entity allowed by the selector (or zero however that's useless). Rather than going through the rest of the options I will just explain an example for block and entity for each of the operations.
​
First up is get. /data get entity @e[type=item,tag=EnchantItem,sort=nearest,limit=1] Item.tag.Enchantments. This command gets the entity data of the nearest item with the tag of EnchantItem (it is important to note that this is the tag for the specific entity, not any custom tags added for the item as this will be in the nbt data), then you have an optional path. This means it will only display information of Item.tag.Enchantments or in other words it will get the Item (meaning not the entity but the item it is displaying), then get its tags then from there get the enchantments. This command will display all the enchantments of the item. Remember the Item.tag.Enchantments part is optional, I only did it incase you needed it, but if you want all the data then feel free to leave that last part out, Technically there is another optional argument called scale however I haven't needed it and I don't fully understand it enough to make it easy to understand in this tutorial. Now for the block example. /data get block ~ ~ ~ Items[0] and another example /data get block ~ ~ ~ Items[{Slot:0b}]. The last arguments are the path and is optional like before, so is the scale however like before I won't talk about it. This gets the block data of the block in your position, the reason I do this is because if you stand on a chest, due to the chests smaller hitbox it will be in the same block you are as your coordinates are from your feet. Then I specify two options for the path. The first gets the first item, not the first slot, but the first item. This means if you have nothing in the first three slots followed by a chest in the fourth this will grab the chest. Next is specifying the slot, this allows you to get a specific slot, in this example slot 0. Also if you have double chests this command will only get the data of the individual chest unlike the replaceitem command which acts on the entire double chest. So be careful of that when using this command. Also this operation can be used for more than debugging, it is used in the execute store command page.
​
Next operation is merge. the only additional parameter is the nbt tag you want to merge to that entity or block. /data merge entity @e[type=item,sort=nearest,limit=1] {Item:{id:"minecraft:iron_ingot"}}. I will only show one example since it is fairly simple. You target the desired entity or block and you can add information. This example will turn the nearest item (from wherever the command executes, if it is from a datapack and not specified it will be 0,0) into an iron ingot. I used this in the More Enchants collab I did when doing autosmelt (with slight adjustments but that's the basic principle).
​
Next operation is modify, this one has a lot of options and is basically a merge but with lots of extra features. If merge satisfies your needs then you can skip this, but if you want to know more keep reading. So I feel like I should explain each option as there would be too many examples for this one. The first option is the path, however this time it is required, next option is the sub-operation, (complicated I know but bear with me), you can choose append, insert, merge, prepend and set. Append inserts after the current data, prepend inserts before the current data, insert inserts in the current data, (when I say data I am referring to the data given by the path), merge takes the data given after and puts it into the current data (however unspecified data is left), set completely overrides the current data with the data given after. Next option is from or value. Value is like in the merge operation, it allows you to set an immediate value (immediate and hardcoded are interchangeable, basically it means you can't change it, it is constant and you have to specify it). If you choose value then you specify the data right after. From is the main thing I like about this, it allows you to take the data from another entity. If you choose from then you specify block or entity, you can take Item data from an item on the ground and put it into the chest so that is why it allows you to choose differently from the object being modified, then the selector or coordinates and last the path (the path is optional this time however in most cases you need to specify the same path for both of them). Ok now I will give just one example so you can see how it all comes together, /data modify entity @e[type=item,sort=nearest,limit=1] Item merge from entity @e[type=item,sort=furthest,limit=1] Item. This takes the Item data (if you are wondering the entity data in total can be PickUpDelay, coordinates, is on fire just to name a few) from the farthest item and merges it with the closest item. I know that was complicated but it is only like that so you can read the command more like a sentence, especially given we are working with nbt data which is in my opinion the most complicated part of commands since it was not made to look pretty and only usable by technical players.
​
Now we are onto the last operation, remove, just like the rest you get to specify the block or entity with the coordinates or selector, after this you write the path and then that will be nullified. For example /data remove block ~ ~ ~ Items. In More Enchants we stored the players inventory in two chest minecarts to detect changes in the inventory and locate the item to be enchanted, however this was replaced by using /entity store in conjunction with /data get. The minecarts are constantly being deleted and replaced and this would amount to numerous item droppings so we used a similar command as the example to clear out all the Items. However it was adapted to the entity.
​
If you made it to the end, congratulations! This was very complicated and in my opinion the most complicated single command, especially with /data modify. If you made it through this you can make some really cool one commands or datapacks. And believe it or not modding despite having a different syntax and a proper programming language needs to do the same stuff with nbt data so its helpful even if you are a modder.
​
​
​