Minecraft: TestFor Command – Here’s How To Tell What Someone Has in Their Inventory

Join us on Reddit for the latest Marvel & DC news!

Share:

Gaining knowledge about what a player has in their inventory in Minecraft can give us a tactical advantage over them. Having this knowledge can also be part of something else we’re trying to pull off using commands, so how do you tell what someone has in their inventory specifically using the TestFor command?

  • Article Breakdown:
  • To tell what someone has in their inventory using the TestFor command, you can use the following command: /testfor @p {Inventory:[{id:"minecraft:item"}]}.
  • Note that this command will only test for a specific item, and you can’t use it to test for items in the entirety of a player’s inventory.

A quick introduction to the TestFor command

The TestFor command has been a fan favorite since it first made its way into Minecraft in 2013 with the Redstone Update. The command could test for players and entities. It worked because you had to specify the item or the player you wanted to test for and set the parameters on how you wanted to test for it.

That way, you could have tested for players or other entities in a specified radius, or you could have tested for specific items in a player’s inventory. The command was limited to command blocks until the 1.8 update when it stopped being exclusive to them.

If you’re wondering why I’m speaking about it in the past tense, it’s because the command is no longer available, at least in Java Edition. Nowadays, you have a plethora of commands that are far better than the TestFor command, whose applications have a wider range.

The command was removed from Java Edition in 2018 but is still available to players in Bedrock Edition.

The execute command

The execute command is a good substitute for the TestFor command in Minecraft Java. I’ll aim to explain how you can end up testing for items in a player’s inventory using the execute command.

Before I start, you can only use the command to check for specific items in a player’s inventory; if you want to check what items a player has in the entirety of their inventory, you’ll need to use mods.

Now, the command you’ll use is this: /execute if entity @p[nbt={Inventory:[{id:"minecraft:diamond"}]}]

It’s a bit long, and for you to customize the command to your liking, I’ll explain all parts of the command. Be aware that the command will work using a Redstone comparator. It’ll light up when players have the specified item in their inventory.

So, ‘execute if’ sets up the conditions on when the comparator will light up. The ‘@p’ will target the nearest player, but you can adjust it to target only certain players. The ‘type=minecraft:item’ specifies that we only want to check item entities.

The Nbt tags specify information for items and entities you create with different types of commands. In the case of our command, we’re testing for apples in a player’s inventory, but you can switch out to whatever you’d like by changing the ‘apple’ with emeralds, diamonds, or weapons like pickaxes or swords.

You’ll input this command in a command block you’ll give yourself with the /give @p command_block. You’ll then set the command to repeat, unconditional, and always active.

You’ll then want to place a redstone comparator next to it and another command block next to the comparator that will be impulse, unconditional, and needs redstone.

The second command block will act as a lightbulb to tell you when a player has that specified item in their inventory, and you can set it to shoot a totem of the undying particles. It’s endlessly customizable in that department.

One thing you want to make sure of is that you place the comparator, as shown in the picture above. Otherwise, it won’t work.

Testing for specific items using the TestFor command

We’ve already established that you can use the TestFor command in Bedrock Edition Minecraft. Luckily, it’s much easier to understand and use the command, so I’ll keep this section and the explanation short and simple.

The command is: /testfor @p {Inventory:[{id:"minecraft:item"}]}

Of course, you’ll replace the ‘item’ with the specific item you want to test for, but other than that, the command will stay the same. So, you’ll test for a player’s inventory and then specify what item you want to test for. You can input the command in a command block if you want to keep testing for items.

Testing for the entire inventory

Currently, the only way to test for all items in a player’s inventory is to use mods. One such mod is the Inv View mod, which works with the Fabric API. It’s a server-side mod, and you’ll need operator permissions on the server to test for them. The command you’ll use in the case of this mod is /view (inv|echest) <playername> and you’ll be able to view their entire inventory, even if they’re offline.

Have something to add? Let us know in the comments below!

Liked this article? Join us on Reddit for the latest Marvel & DC news!

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments