0

I am trying to get a command block to teleport 1 Polished Granite (which is dropped on the floor) 1 block above itself (the command block). It also has a custom name, being "Block A" , and my command looks like this:

tp @e[type=item,nbt={Item:[{id:"minecraft:polished_granite",Count:1b,tag:[{display:"{Name:\"text\":\"Block A\"}"}]}]}] ~ ~1 ~

The output given by the command block, however, says there was no entity detected. I could use name="Polished Granite" inside of the @e[] instead to detect the Polished Granite itself, but I want it to detect specifically the one with the custom name. Does anyone know what I'm doing wrong?

1 Answer 1

0

Item and tag are not lists and display isn't a string, but Name is. And if you look at your supposed display "string", you see "Name", then a colon, then an escaped string, then another colon, then another escaped string. Both in NBT and in JSON, there's only ever one piece of text, a colon and a second piece of text, never three.

So in total, removing the square brackets from Item and tag and fixing the display stuff:

tp @e[type=item,nbt={Item:{id:"minecraft:polished_granite",Count:1b,tag:{display:{Name:"{\"text\":\"Block A\"}"}}}}] ~ ~1 ~

You can figure out these things by creating the item entity that you want and executing:

/data get entity @e[type=item,sort=nearest,limit=1]

It tells you all the NBT of the item. Now just copy that (I always leave the game log window open for something like that) and reduce it to the parts you need.
Alternatively, you can pay very close attention to the wiki's NBT lists (for example here (archive), because it does tell you the data type of everything (including if it's a list or not), it's just a bit hard to see, often it's only indicated by the icon on the left.

2
  • thank you so much! i didn't really understand when to use specific kinds of brackets and stuff, but this explained a lot. Thanks for the command as well!
    – person
    May 24, 2019 at 19:21
  • Square brackets for lists, curly brackets for compounds (basically everything except single values). You can also always look up example commands. May 24, 2019 at 19:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .