TransWikia.com

How do I test for a named item in a players inventory? (Minecraft 1.13)

Arqade Asked by Warloch 11 on November 26, 2020

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?

4 Answers

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.

Answered by Warloch 11 on November 26, 2020

execute as @a if entity @s[nbt={Inventory:[{id:"minecraft:emerald",Count:3b}]}]

Just change "Emerald" to whwatever item you want, and you can change "3" to the amount of items you're looking for. That should work for Minecraft 1.13+. I'm currently on Minecraft 1.14.3 Java Edition.

Answered by Azvic on November 26, 2020

Just Figured the problem out with enchanted items. It doesn't work up until 1.14.4 yet, but I found a solution, easier faster, and better.

/give @p minecraft:red_banner{D2Quest1Item:1b,display:{Name:"{"text":"Red Flag"}"},Unbreakable:1,Enchantments:[{id:"minecraft:binding_curse",lvl:1}]} 1

/execute if entity @a[distance=..3,gamemode=adventure,team=Blue,nbt={Inventory:[{id:"minecraft:red_banner",tag:{D2Quest1Item:1b}}]}]

This just adds a custom tag, which is easily detected by the command block.

Answered by Larry on November 26, 2020

/execute as @a if entity @s[nbt={inventory:[{id:"minecraft:<name>"}]}] would do the trick for computer users

/execute as @a if entity @s[nbt={inventory:[{id:"<name>"}]}] i think would work for mobile users(pe edition)

Answered by debugger on November 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP