I want to get the NBT data of a block as a string e.g. The NBT data of a chest. I know that this is possible as I had to do it a year or so ago for a key to a house I had built.
3 Answers
You can use the /blockdata
command to see tile entity data. Providing no input will show the current state of that data. For instance, stand on top of a chest and run the following:
/blockdata ~ ~-1 ~ {}
This way isn't very efficient, but it's how I have always done it (and I don't know another way):
Look at the chest, hold ctrl, and press your pick block button (configurable in options). This should give you a chest item with identical NBT data.
Place a command block down anywhere that doesn't have armor stands adjacent to it (including diagonally)
Run the command using the command block:
/summon ArmorStand ~ ~ ~ {ShowArms:1}
Then put the chest item in the hand of the armor stand, then run this command in the command block:
/entitydata @e[type=ArmorStand,c=1] {}
You can then go to the output of the command block, look for the
Items
tag and copy the text within the following '['. Alternatively, you can copy the whole output, paste it in a text editor, press ctrl + F, and search for the tag.
An example of what I would copy is:
Items:[0:{Slot:0b,id:"minecraft:sandstone",Count:1b,Damage:0s}
Just in case, as of ItemsAdder 3.4.1-r4
, the following command should return entity data, including NBT, of an item currently being held by a player Player1
:
/data get entity @p[name=Player1] SelectedItem
If it does not output anything in-game, you might want to try it on the server console.