NBT - Tag (Expression) — SkBee

Addon: SkBee · Category: Expression · Since: 1.0.0

Syntax

%nbttype% %string% of %nbtcompound%

Description

Get/set/delete the value of the specified tag of an NBT compound. Also supports getting nested tags using a semi colon as a delimiter. If the return value is a list, you can use it as a list, as it will automatically split it for ya. **Notes**: - `uuid tag` will set an int array tag (This is how MC stores uuids). On return it'll convert back to a uuid. - `boolean tag` will store as a byte but will convert to/from a boolean. - GET FROM LIST BY POSITION: You can get the element of a list by adding `[%number%]` to the end of a tag (This only works for getters, not set/add/remove/delete) see examples.

**Custom Tags**: Not all objects in Minecraft support custom NBT data, here are some examples of where custom data can be stored. Optionally you can use `custom nbt of %object%` and let SkBee handle custom data storage. - Entity: Custom data can be stored in the "data" compound tag of an entity's NBT compound. - Block Entity (such as furnace/cheset): Custom data can be stored in the "components" tag within the "minecraft:custom_data" tag. - Item: Custom data can be stored in the "minecraft:custom_data" tag.

**Changers**: - ADD: You can add numbers to number type tags, you can also add numbers/strings/compounds to lists type tags. - REMOVE: You can remove numbers from number type tags, you can also remove numbers/strings from lists type tags.(You can NOT remove compounds from lists type tags)

Examples

# Getting the value of a simple tag
set {_damage} to int tag "minecraft:damage" of nbt of player's tool
set {_sheared} to byte tag "Sheared" of nbt of target entity
set {_pass::*} to compound list tag "Passengers" of nbt of last spawned entity
set {_pos::*} to double list tag "Pos" of nbt of {_sheep}
set {_burntime} to short tag "BurnTime" of nbt of target block
set {_items::*} to compound list tag "Items" of nbt of target block

# Getting the value of a nested tag
set {_maybuild} to byte tag "abilities;mayBuild" of nbt of player
set {_x} to int tag "Leash;X" of nbt of target entity
set {_pos::*} to int array tag "LastDeathLocation;pos" of nbt of player

# Setting the value of a simple tag
set int tag "Damage" of nbt of player's tool to 100
set byte tag "Sheared" of nbt of last spawned entity to 1
set double list tag "Pos" of nbt of {_sheep} to 1,100,1
set short tag "BurnTime" of nbt of target block to 150

# Setting the value of a nested tag
set byte tag "abilities;mayBuild" of nbt of player to 1
set int array tag "LastDeathLocation;pos" of nbt of player to 1,64,1

# Setting the value of a custom tag of an entity/block
set int tag "custom;points" of nbt of player to 55
set short tag "custom;bloop" of nbt of last spawned entity to 10
set uuid tag of "custom;owner" of nbt of target block to uuid of player

# Adding to the value of a tag
add 10 to int tag "Score" of nbt of player
add 50 to int tag "custom;points" of nbt of player

# Removeing from a value of a tag
remove 10 from int tag "Score" of nbt of player
remove 25 from int tag "custom;points" of nbt of player

# Getting elements from lists
set {_c} to compound tag "Inventory[0]" of nbt of player
set {_x} to double tag "Pos[0]" of nbt of player
set {_y} to double tag "Pos[1]" of nbt of player
set {_z} to double tag "Pos[2]" of nbt of player
set {_s} to string tag "some_strings[5]" of {_nbt}
set {_i} to int tag "intlist[1]" of {_nbt}
set {_b} to byte tag "someBytes[10]" of {_nbt}

# Minecraft 1.20.5+ item component stuff
set int tag "minecraft:max_damage" of nbt of player's tool to 500
set int tag "minecraft:max_stack_size" of nbt of player's tool to 25
set byte tag "minecraft:enchantment_glint_override" of nbt of player's tool to 1
set compound tag "minecraft:fire_resistant" of nbt of player's tool to nbt from "{}"
set string tag "minecraft:rarity" of nbt of player's tool to "epic"

# All custom data must be within the "minecraft:custom_data" compound
# See NBT Compound expression for futher details on the `custom nbt` expression
set byte tag "Points" of custom nbt of player's tool to 10
set int tag "MyBloop" of custom nbt of player's tool to 152
# These examples will do the same as above
set byte tag "minecraft:custom_data;Points" of nbt of player's tool to 10
set int tag "minecraft:custom_data;MyBloop" of nbt of player's tool to 152

View source