Minecraft – Entity Inventory Slot Detection

minecraft-commandsminecraft-java-edition

I'm trying to use a command for a map I am creating and I need to test for if an armorstand by the name of Skeletor is wearing a golden helemet on its head. Here's the command I've been using:

/testfor @e[name=Skeletor,Inventory=[{Slot:103,id:golden_helemet}] 

but its says:

The entity UUID provided is in an invalid format.

Best Answer

The error you are getting simply means that no entity can be found that matches your target selector. Basically, the target selector then returns NULL, which is not a valid UUID, hence the message.

As to why your command fails, you have confused target selector arguments with data tags, which represent NBT data. While some target selector arguments duplicate checking for NBT data, for example [name=Bob] <-> {CustomName:Bob}, these are different things. In particular, some commands are unable to check NBT data altogether, such as execute (scoreboard does, and is therefore a common very workaround to turn NBT into a target selector).

Luckily, testfor is able to check matching NBT data as an optional argument:

testfor <player> [dataTag]

There is another issue with your command, which is that the Inventory data tag is only valid for players. Mobs have an Equipment tag instead, which is a list of 5 Item tags (Hand, Feet, Legs, Chest, Head). Due to Minecraft's partial tag matching, you can leave the other 4 tags empty:

In order to make your command work, you should use

/testfor @e[name=Skeletor] {Equipment:[{},{},{},{},{id:minecraft:golden_helmet}]}

For reasons unknown to me, you need to use the full item id, including the minecraft: prefix. Using only id:golden_helmet does not work.