Minecraft Java Edition – How to Use Inventory Scanner Commands

minecraft-commandsminecraft-java-edition

I want to do a sort of "inventory scanner" that scans EVERY slots of the inventory of a player. I don't want to write 32 commands in 32 commands blocks, so is there a way to make it short?

For more precision, what I need to scan is the TNT blocks, lava buckets, flint & steel, detected either if renamed or not renamed.

Best Answer

Try using

/testfor @p {Inventory:[{id:"<block or item>"}]}

This will check for a specific item in the inventory, ignoring slots, using only 1 command block per item. Make sure you use the modpack prefix before your items. For vanilla Minecraft items, it is minecraft:<block or item>.