NBT Tags for Player in Minecraft (Java Edition 1.12)
This Minecraft tutorial explains the NBT tags (formerly called data tags) that you can use for a player in Minecraft Java Edition (PC/Mac) 1.12.
TIP: If you are not running Minecraft Java Edition (PC/Mac) 1.12, find NBT tags for player in another version of Minecraft:
Background
Players have a unique set of NBT tags that can be used in Minecraft commands such as: /testfor and /scoreboard.
What are NBT tags (formerly called Data Tags)?
NBT tags allow you to set certain properties of a player. The NBT tag is always surrounded in {} such as {Dimension:0}. If there is more than one NBT tag used in a game command, the NBT tags are separated by a comma such as {Dimension:0, foodLevel:20}.
List of NBT Tags
Here is a list of the NBT tags that you can use for a player in Minecraft Java Edition (PC/Mac) 1.12:
NBT Tag | Value (Description) |
---|---|
DataVersion | version (The version of the player's NBT structure. Each version/snapshot of Minecraft has its own unique version number. Minecraft 1.12 has a DataVersion value of 1139) Example |
Dimension | -1 (The player is the Nether) Example |
EnderItems | data (An item in the player's ender chest) Example |
foodLevel | number (The level in the Hunger bar. A full Hunger bar has a value of 20) Example |
foodExhaustionLevel | number (The level of exhaustion) Example |
foodSaturationLevel | number (The current level of saturation) Example |
foodTickTimer | ticks (The value of the Food timer in game ticks) Example |
Inventory | data (An item in the player's inventory) Example |
playerGameType | 0 (The player is in Survival mode) Example |
Score | number (The value that will be displayed as the Score when the player dies) Example |
SelectedItemSlot | number (The hotbar slot that the player currently has selected. The first slot is 0, second slot is 1, and so on) Example |
SelectedItem | data (The item that is currently selected in the hotbar) Example |
ShoulderEntityLeft | data (The entity sitting on the player's left shoulder. Currently, this can only be a parrot) Example |
ShoulderEntityRight | data (The entity sitting on the player's right shoulder. Currently, this can only be a parrot) Example |
Sleeping | 0 (The player is not sleeping) Example |
SleepTimer | ticks (The number of game ticks that the player has been sleeping in a bed) Example |
SpawnX | number (The X coordinate of the player's bed or spawn point) Example |
SpawnY | number (The Y coordinate of the player's bed or spawn point) Example |
SpawnZ | number (The Z coordinate of the player's bed or spawn point) Example |
SpawnForced | 0 (The player will not spawn if no bed is found) Example |
XpLevel | number (The level on the experience bar) Example |
XpP | number (The percentage on the experience bar until the next level) Example |
XpSeed | number (The seed that will be used for the next enchantment when using an enchanting table) Example |
XpTotal | number (The total XP earned during the current life. This value is displayed as the Score when player dies) Example |
NBT Tag Examples
To test if there are any players that have an experience level of 20:
/testfor @p {XpLevel:20}
To test if there is a parrot on any players left shoulder:
/testfor @a {ShoulderEntityLeft:{id:"minecraft:parrot"}}
To add 1 to the objective called FirstObjective for all players if they have a diamond sword in inventory:
/scoreboard players add @a FirstObjective 1 {Inventory:[{id:"minecraft:diamond_sword"}]}
Target Selectors
Before we finish discussing data tags, let's quickly explore how to use target selectors. The @p and @a target selectors allows you to target players in your commands.
You can add a radius value to target players within a certain radius of blocks (for example, r=5
lets you target players within a 5 block radius of where the command is run).
Target all players within a 5 block radius:
@a[r=5]
Target the nearest player within a 5 block radius:
@p[r=5]
Target Selector Examples
To test for all players within a 50 block radius:
/testfor @a[r=50]
To summon a lightning bolt at all players:
/execute @a ~ ~ ~ /summon lightning_bolt
To kill the nearest player with a maximum experience level of 20 (this command may kill you as well):
/kill @p[l=20]
Next, learn how to use the game commands in Minecraft.
Advertisements