NBT Compound - ShaneBeee/SkBee GitHub Wiki

NBT Compounds are the base of how NBT works in SkBee. Let's break down the different ways to get an NBT compound.

Getting Values

So now that you know what NBT looks like and a bit of how it works, now it's time to get into getting the values of a key (aka tag) and entire compounds of things, which is actually very simple to do.

Getting The Compound of an Object

Commonly when dealing with NBT compounds, you will want to get the compound of the object to then manipulate it later on, luckily that's very easy to do with the nbt compound expression.

The expression allows you to get the compound of many things, including entities, blocks, items, chunks, files and strings.

Strings

The basic way to create a new NBT compound is from a string.

nbt compound of %string%

EX:

set {_n} to nbt compound from "{someNBT:1}"

This will create a simple new NBT compound, which can be manipulated however you want, or merged with another compound (ie: an entity, or item)
To create an empty compound, here is what you'd do:

set {_n} to nbt compound from "{}"

With this, you can manipulate it however you want.

ItemStacks

There are a couple different methods for getting NBT compounds for items. Let's look at the syntaxes, then look and what they do.

full nbt of %itemtype%
nbt of %itemtype%
components nbt of %itemtype%

Full NBT Compound

The first option here will return the FULL NBT of an ItemStack.
This includes "id" (which item it is), "Count" (how many in the stack) and "tag" (this is where MC stores all info on an item stack).
NOTE: When getting NBT for an ItemStack this way, it will be a copy of the NBT. This means any changes will NOT apply directly to the ItemStack, you will have to create a new item from this compound (luckily we have an expression for that).

Here is an example of getting the FULL NBT of an item looks like.

set {_n} to full nbt of diamond sword of sharpness 5

This is what the compound would visually look like:
Minecraft 1.20.4 and below:

{id: "minecraft:diamond_sword", Count: 1b, tag: {Enchantments: [{id: "minecraft:sharpness", lvl: 5s}], Damage: 0}}

Minecraft 1.20.5 and above:

{id: "minecraft:diamond_sword", count: 1, components: {"minecraft:enchantments": {levels: {"minecraft:sharpness": 5}}}}

NBT Compound

The second option will return everything that is within the "tag" compound of an ItemStack.
NOTE: When getting NBT for an ItemStack this way, any changes you make to this compound will directly apply to the ItemStack.
NOTE: For Minecraft 1.20.5+ this will return everything within the "minecraft:custom_data" component of the "components" compound.

Here is an example of getting the item NBT of an item looks like.

set {_n} to nbt of diamond sword of sharpness 5

This is what the compound would visually look like:
Minecraft 1.20.4 and below:

{Enchantments: [{id: "minecraft:sharpness", lvl: 5s}], Damage: 0}

Minecraft 1.20.5 and above:

{}

NBT Components Compound

(This is for Minecraft 1.20.5+)
This option will return everything that is within the "components" compound of an ItemStack.
NOTE: When getting NBT for an ItemStack this way, any changes you make to this compound will directly apply to the ItemStack.

Here is an example of getting the item NBT of an item looks like.

set {_n} to components nbt of diamond sword of sharpness 5

This is what the compound would visually look like:

{"minecraft:enchantments":{levels:{"minecraft:sharpness":5}}}

Custom Item NBT

Anytime you want to add custom NBT to an item, it will need to be within the "tag" tag.
If you are using nbt compound just plop your custom NBT anywhere, but if you are using the full nbt compound expression, make sure to store all custom data within the "tag" tag.
For Minecraft 1.20.5+ you have a few options:

  • If using full nbt of %item% you will need to store custom data in the "minecraft:custom_data" tag of the "components" tag.
  • If using nbt of %item% you can put your data anywhere as this will already be in the "minecraft:custom_data" component.
  • If using components nbt of %item% you will need to store custom data in the "minecraft:custom_data" tag.

Entities

You can easily get the NBT compound from an entity

nbt compound of %entity%

EX:

set {_nbt} to nbt compound of event-entity

Any changes you apply to this compound, will automatically update the entity.

Custom Entity NBT

Minecraft does not natively support custom NBT on entities.
Luckily SkBee has a hacky method to allow this.
All custom NBT on an entity will need to be stored within the "custom" tag.

Blocks

You can easily get the NBT compound from a block.

nbt compound of %block%

EX:

set {_n} to nbt compound of target block of player

Any changes you apply to this compound, will automatically update the block.

Custom Block NBT

Minecraft does not natively support custom NBT on blocks.
Luckily SkBee has a hacky method to allow this.
All custom NBT on a block will need to be stored within the "custom" tag.

Chunks

You can easily get the NBT compound of a chunk.

nbt compound of %chunk%

EX:

set {_nbt} to nbt compound of chunk at player

This allows you to store whatever data you want in a specific chunk.
Chunk must be loaded for this to work.

Files

You can easily grab the NBT compound of a file

nbt compound of file %string%

EX:

set {_nbt} to nbt compound of file "world/playerdata/someuuid.dat"

This example would return the NBT compound of an offline player.
If the file isn't found, SkBee will create a new file for you.
This can be great alternative for saving information to files.
Files can end with ".dat" or ".nbt" (other formats.... I dunno what'll happen).
When manipulating file NBT, changes will not be automatically applied, but don't worry, you can easily save the file with this effect:

save nbt file of %nbtcompounds%

EX:

save nbt file of {_nbt}