# NBT Tags

{% hint style="warning" %}
Disclaimer: the SkBee addon *will* be required for modifying and adding NBT tags.

Download SkBee from [<mark style="color:blue;">Shane Bee's GitHub</mark>](https://github.com/ShaneBeee/SkBee/releases).
{% endhint %}

{% hint style="info" %}
If you are new to working with NBT or SkBee, check out the [SkBee Wiki](https://github.com/ShaneBeee/SkBee/wiki).

Everything here can also be found in the SkBee wiki, and all syntax can be found on the documentation.
{% endhint %}

NBT (Named Binary Tags) is a wonderful way to add customisation to items, blocks, and entities. In fact, NBT is how many things are stored in base Minecraft, such as an item's durability, lore, attributes, and enchantments. By using NBT, you can modify the standard tags, or create and work with your own custom tags!

NBT tags are the most streamlined way to modify and customise an object, and in many cases, they can be used as an alternative to variables!

***

## Setting NBT

Tag syntax: `%tag type% tag %tag name% of %NBT compound%`

Components:

* Tag type: The type of NBT tag the tag will be. [List of all available types](https://github.com/ShaneBeee/SkBee/wiki/NBT-Intro#datatypes-in-nbt).
* Tag name: A string that serves as a key to access the value of a tag. Note that nested tags use a semicolon, `;`.
* NBT Compound: the NBT compound that you are modifying or getting the tag from.

Examples:

```
set (int tag "stats;luck" of (NBT compound of player's tool)) to 100
```

{% hint style="warning" %}
NBT tags and compounds are quite long, a good idea is to surround them with parentheses.

See the [Parentheses page](/syntask/optimisations/parentheses.md) to learn how parentheses can make your code faster and easier to read and run.
{% endhint %}

***

## Checking NBT

To check if an object's NBT has a certain tag, you can use the has tag condition:

Syntax: `%NBT compound% has [NBT] tag %tag name%`

Negative syntax: `%NBT compound% (does not|doesn't) have [NBT] tag %tag name%`

Example:

{% code overflow="wrap" lineNumbers="true" %}

```python
if (NBT compound of {_item}) has NBT tag "example":
  give player 1 of diamond
```

{% endcode %}

When checking the value of a tag, just use the tag in a condition like you would with any other object.

Examples:

{% code overflow="wrap" lineNumbers="true" %}

```python
(string tag "helloThere" of (NBT compound of {_item})) = "GeneralKenobi"
```

{% endcode %}

{% hint style="info" %}
If a tag may not be set, you can also assign a value using the default value expression:

Syntax: <https://skripthub.net/docs/?id=2617>

Note that this does not assign the specified value to the actual tag, but will use the specified value in the line of code if the NBT tag is null.
{% endhint %}

{% code overflow="wrap" lineNumbers="true" %}

```python
set {_tag} to (int tag "customAbility;uses" of (NBT compound of player's helmet))
if ({_tag} ? 0) = 0:
  send "Your helmet needs to be recharged!" to player
```

{% endcode %}

***

## Applications

NBT is very useful, it can be utelised in a variety of ways. Here are some of the ways NBT can be used:

### Default NBT

Minecraft uses NBT everywhere. Every block, item, and entity has NBT hidden beneath the surface.

Want to make an armour stand invisible? Invulnerable? Want to give yourself a fancy item? Spawn a mob with a custom name and items or armour? Online command generators (such as MCStacker and Minecraft Command Science) do all of this through NBT. And with SkBee, it can be done in Skript.

While Skript has more common ways to do some of these, NBT is still a very powerful and versatile way to mess with things in base Minecraft, especially for the things Skript doesn't have effects or expressions for.

### Custom items

NBT is absolutely perfect for working with custom items. So much that it deserves a whole new page.

{% hint style="info" %}
See the [Custom Items page](/syntask/storage/nbt-tags/custom-items.md) for applications of NBT with custom items.
{% endhint %}

### Storage

NBT tags allow you to attach data directly to an object. This is excellent for storing things such as a custom amount of uses for an item, or keeping track of who was the last one to interact with a block. This is a much better option than storing with variables or putting the remaining uses in the item's lore. And, of course, don't forget that having a bunch of needless variables wastes storage space.

NBT tags are much better than variables in these cases. For example, many generator servers need to keep track of who owns each generator, but setting `{gens::owner::%event-location%}` to the owner means one variable *per generator*. Players could have dozens, or even hundreds of generators each. That's a lot of variables. Instead, simply add an NBT tag to the generator when it is placed!

{% hint style="info" %}
See the [Deleting Variables page](/syntask/storage/variables/deleting-variables.md) to learn more about preserving storage space.

See the [UUIDs page](/syntask/storage/uuids.md) to learn why storing a UUID is always better long-term.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://x8ight.gitbook.io/syntask/storage/nbt-tags.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
