Clear named (and lored) item from players inventory 1.13 [duplicate]
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?
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