How do I detect an item with a name in someones inventory for 1.13?

So I'm trying to make a thing where you walk up to it and a gate opens if you have a paper that is named on you but since the 1.13 update I don't know how to do that


Solution 1:

The things that have changed since 1.12 are the JSON formatting of custom names, the position of the NBT data of the command and the /execute command itself.

Let's say I would like to test if I have a paper on me that is named "Card". Here's what the command would look like:

/execute if entity @p[nbt={Inventory:[{id:"minecraft:paper",tag:{display:{Name:"{\"text\":\"Card\"}"}}}]}]

First of all, I use /execute if instead of /testfor. Next, I put the NBT into a different position, @p[nbt={NBT}] instead of just @p {NBT}. Finally, the JSON formatting. Instead of {Name:"<Name>"} I used {Name:"{\"text\":\"<Name>\"}"}.