Minecraft – How to test for a named item in a players inventory? (Minecraft 1.13)

minecraft-commandsminecraft-java-edition

So I'm trying to make a command that tests for a named item in a players inventory, and executes if they have that item. I know that you can test for an item type, but how do I make it test for a name too? Please bear in mind: I am trying to figure this out for Minecraft 1.13, not any previous versions.

*Edit: I have already tried this command with no success:

execute at @a[nbt={Inventory:[{id:"minecraft:blaze_rod",Count:1b,tag:{display:{Name:"{\"text\":\"Doomstick\"}"}}}]}] run say hi

Edit 2: So after some testing I think it has to do with the attribute modifiers or text color I'm using with the name. Any ideas?

Best Answer

So, after a few hours of debugging and fruitless research, I realized that: a: My conjecture in Edit 2 about text format was correct, and b: it can be solved by including the other text json like so (Please pardon any errors in my json format):

execute at @a[nbt={Inventory:[{id:"minecraft:blaze_rod",Count:1b,tag:{display:{Name:"{\"text\":\"Doomstick\",\"color\":\"dark_red\",\"bold\":\"true\",\"italic\":\"true\"}"}}}]}] run say hi

Hopefully this helped anyone out there experiencing a similar issue.