• Hey! Register here to create your account, engage with the community, and talk about what is new!

Simple Guide to Item Tags

grobulae

Moderator
Moderator
Joined
Sep 6, 2020
Messages
127
Reaction score
26
If you're looking to cleanly identify similar items with code, to "unstack" normally stack-able items, or just hold data in an item, then Item Tags are for you!

What are Item Tags?
When you use a shulker like it's intended, that is, putting an item in it and carrying it with you, how does it remember what items it has in it? One might say it knows it from the lore, or it just magically knows from the almighty powers of Jere; but no, Jere has much better things to use his magical powers for. The data in the shulker is stored in special containers called Item Tags, which are small little lines held in an item that contains data, either a number or text. When you store items in a shulker and pick it up, the insides are stored as text in an item tag.

If you want to see this for yourself, you can do a little experiment at home! First, you need to enable Advanced Item Tooltips, which, when activated, will show you how many item tags an item has, and it's ID. To activate this, simply press F3+H. Your chat should give you a little message, then if you open your inventory and hover over an item, you'll see some extra text under the lore in &8, like shown:

tag1.png

Now that you have Advanced Item Tooltips on, it's time to do the fun part! Pick out any color of shulker (i chose light gray), then check its tags. If it's brand new from the creative menu, it will have no tags, so it will only contain the ID. Then, just place it down, and put any old item inside. Then, pick it up and check again! Tada! Now it has a tag! This is because now that it has items inside, it has the necessity to store the data inside, so the next time you place it, it uses that stored data to fill it again.

tag2before.png Before
tag2after.png After

Item Tags are stored in the NBT, just like lore, so that's why it says NBT: x tag(s).

Tags are stored in two parts: The name, then the value, just like block tags. They're a bit like limited variables, only able to be a number or string of text! For example, a shulker might use the tag Data = blah, blah, blah (This isn't the exact name or contained info, but you get the point.)

How Can I Use Them?
Item Tags have lots of interesting and creative uses, especially with covertly identifying items as opposed to more ugly methods. You can apply Item Tags to items with code using Item Set Vars, or using the /item command. Make sure that when you call for these tags to check them, you use the right name!

I might post a tutorial for a system involving Item Tags in the future, but for now, I just have a few tips for you!

1. Use simple tag names
Using simple tag names can decrease the margin for error in your code. This goes for most code anyway.

2. Tags can only be numbers or text
Make sure that you remember this, it can save you lots of headaches.

3. Items with different tags will not stack or register as the same
This might be useful if you don't want normally stackable items to not stack, or if you want to differentiate two items in code.

4. Tell me if I missed anything!
Tutorials work best when they aren't rough!

1600098429519.png
 
Top Bottom