2

In 1.12, the command:

clear @p paper 0 1 {display:{Name:"[Winning Ticket] Musical Minecarts",Lore:[" Take this ticket to the reward "," collections at the entrance of the ", " Games area to claim your prize! "]}}

would remove a piece of paper with that specific name and lore from the player's inventory. I assumed the 1.13 conversion would be:

 execute at @p as @p run clear @s paper{display:{Name:"[Winning Ticket] Musical Minecarts",Lore:[" Take this ticket to the reward "," collections at the entrance of the ", " Games area to claim your prize! "]}} 1

but this doesn't work. As well as this, the command:

give @p minecraft:paper{display:{Name:"[Winning Ticket] Musical Minecarts",Lore:[" Take this ticket to the reward "," collections at the entrance of the ", " Games area to claim your prize! "]}} 1

only gives the item, without the custom display name, despite the lore being correct. What is the correct syntax for these two commands?

  • What are the error messages? – Fabian Röling Jul 18 '18 at 22:43
1

The relevant change here has to do with item names. Instead of being simple strings, they use JSON text components -- the same format you'd see in /tellraw, but bundled into a string. This allows you to use colors or translations in your item names.

These are both valid ways of formatting JSON text:

  • "[Winning Ticket] Musical Minecarts"
  • {"text":"[Winning Ticket] Musical Minecarts"}

When you put these into an item name, this is all put into a literal string, so you'll need to escape the quotes like so:

  • Name:"\"[Winning Ticket] Musical Minecarts\""
  • Name:"{\"text\":\"[Winning Ticket] Musical Minecarts\"}"

However, clearing an item by name is usually a bad idea. Given items can have any kind of arbitrary NBT, and you can simply check for that in the /clear.

give @p paper{ticket:1b,display:{Name:"\"[Winning Ticket] Musical Minecarts\"",Lore:[" Take this ticket to the reward "," collections at the entrance of the ", " Games area to claim your prize! "]}}
clear @p paper{ticket:1b} 1
  • Ah, you were 4 minutes earlier than me. :D Interesting, I didn't know that simple strings still work if you do it "\"like this\"". Upvote! – Fabian Röling Jul 18 '18 at 22:54
0

Firstly I removed an unnecessary space from the command, they are likely to break NBT. Also, are you sure you want to space at the beginning and end of every line of the lore?

Getting the NBT of an item is easy now in 1.13: Throw it on the ground and execute for example /data get entity @e[type=item,distance=..10,limit=1]. You can even specify a path behind it, like Item.tag.

The NBT for the command you want can then just be copied from the output, except for a bug that itself inserts spaces into the NBT. Also you have to give yourself the item with a different syntax now, because item names are now a JSON component instead of a simple string. This means that you can also colour it, make it bold, translated, obfuscated, etc.

New give syntax, the same works for clear:

/give @s paper{display:{Name:"{\"text\":\"[Winning Ticket] Musical Minecarts\"}",Lore:[" Take this ticket to the reward "," collections at the entrance of the "," Games area to claim your prize! "]}}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.