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.

player

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
{DataVersion:1139}

Dimension

-1 (The player is the Nether)
0 (The player is in the Overworld)
1 (The player is in the End)

Example
{Dimension:0}

EnderItems

data (An item in the player's ender chest)

Example
{EnderItems:[{id:"minecraft:diamond_sword"}]}

foodLevel

number (The level in the Hunger bar. A full Hunger bar has a value of 20)

Example
{foodLevel:20}

foodExhaustionLevel

number (The level of exhaustion)

Example
{foodExhaustionLevel:0}

foodSaturationLevel

number (The current level of saturation)

Example
{foodSaturationLevel:5}

foodTickTimer

ticks (The value of the Food timer in game ticks)

Example
{foodTickTimer:0}

Inventory

data (An item in the player's inventory)

Example
{Inventory:[{id:"minecraft:diamond_sword"}]}

playerGameType

0 (The player is in Survival mode)
1 (The player is in Creative mode)
2 (The player is in Adventure mode)
3 (The player is in Spectator mode)

Example
{playerGameType:1}

Score

number (The value that will be displayed as the Score when the player dies)

Example
{Score:126}

SelectedItemSlot

number (The hotbar slot that the player currently has selected. The first slot is 0, second slot is 1, and so on)

Example
{SelectedItemSlot:0}

SelectedItem

data (The item that is currently selected in the hotbar)

Example
{SelectedItem:{id:"minecraft:diamond_sword"}}

ShoulderEntityLeft

data (The entity sitting on the player's left shoulder. Currently, this can only be a parrot)

Example
{ShoulderEntityLeft:{id:"minecraft:parrot"}}

ShoulderEntityRight

data (The entity sitting on the player's right shoulder. Currently, this can only be a parrot)

Example
{ShoulderEntityRight:{id:"minecraft:parrot"}}

Sleeping

0 (The player is not sleeping)
1 (The player is sleeping)

Example
{Sleeping:0}

SleepTimer

ticks (The number of game ticks that the player has been sleeping in a bed)

Example
{SleepTimer:2400}

SpawnX

number (The X coordinate of the player's bed or spawn point)

Example
{SpawnX:520}

SpawnY

number (The Y coordinate of the player's bed or spawn point)

Example
{SpawnY:97}

SpawnZ

number (The Z coordinate of the player's bed or spawn point)

Example
{SpawnZ:101}

SpawnForced

0 (The player will not spawn if no bed is found)
1 (The player will spawn if no bed is found)

Example
{SpawnForced:0}

XpLevel

number (The level on the experience bar)

Example
{XpLevel:20}

XpP

number (The percentage on the experience bar until the next level)

Example
{XpP:50}

XpSeed

number (The seed that will be used for the next enchantment when using an enchanting table)

Example
{XpSeed:12345}

XpTotal

number (The total XP earned during the current life. This value is displayed as the Score when player dies)

Example
{XpTotal:126}

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.