0

I'm trying to test for anything but a specific item in a chest. I've heard that this would be possible by removing the brackets.

The normal to test for an item is;

/testforblock X Y Z minecraft:chest -1 {Items:[{id:"minecraft:diamond"}]}

And the syntax to test for anything but the item would be;

/testforblock X Y Z minecraft:chest -1 {Items:[id:"minecraft:diamond"]}

However, this doesn't work, probably because removing the brackets doesn't actually invert the command. Does anyone know how I can test for any item except a diamond in my chest?

The chest is emptied each time it is tested, so I'm testing for the following situations;

There's a diamond in the chest, there is an item that isn't a diamond in the chest, or there's nothing in the chest.

  • Also, does anyone know what the [dataValue] actually does? – Jaïr Paalman Dec 28 '15 at 17:33
  • So what do you want your logic to be? I'm assuming you want if(contains(items) && !contains(diamond)). In any case you're going to need multiple command blocks. – MBraedley Dec 28 '15 at 17:40
  • 1
    @JaïrPaalman for chests, data value is the orientation of the chest. The wiki has a section on data values for most blocks. -1 simply matches all values. – MrLemon Dec 28 '15 at 17:44
  • You might want to take a look at this question and answer for testing if a chest is empty or not. – MBraedley Dec 28 '15 at 17:46
  • @MBraedley The chest is emptied each test, so basically I'm testing wether there's a diamond, anything but a diamond or nothing at all. – Jaïr Paalman Dec 28 '15 at 18:00
1

Curly brackets denote the type of data, which in this case is a compound, not a logical operator. Individual item data is stored within a compound, while the "Inventory" tag itself is a list (which encases all its data in square brackets).

You cannot detect it directly. What you can do instead is invert the produced signal after detecting if the block contains the item. Example via 1.9 command blocks:

Repeating>chain>chain

In order from left to right:

  1. The initial /testforblock command to check if the chest contains a diamond.

    /testforblock ~ ~1 ~ minecraft:chest -1 {Items:[{id:"minecraft:diamond"}]}
    
  2. A second /testforblock that checks if the previous command block has a SuccessCount value of 0. If it's 0, that means the command failed to find a diamond in the chest. Change coordinates as needed.

    /testforblock ~ ~ ~-1 minecraft:repeating_command_block -1 {SuccessCount:0}
    
  3. Conditional. Command to run if the second /testforblock was successful.

    /say Chest did not have a diamond
    
| improve this answer | |
  • That's a nice use of testforblock and conditionals instead of stats block or (shudder) comparators. – MrLemon Dec 29 '15 at 14:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.