2

I've seen a lot of questions for finding specific items in chests using commands using testforblock but how would you test if any block/item has been placed in a chest?

Thanks

  • As in, like a remote comparator? – MrLemon Aug 21 '15 at 15:40
  • @MrLemon I'm unsure what a comparator is fully used for. What I want is a command testing for an item in a chest, then a comparator next to that command block to activate another command block. – Chickenator Aug 21 '15 at 15:42
  • A comparator next to a chest (or any container), will output a redstone signal based on how full the chest is. For a chest, every full stack increases the output signal power by 0.44 (15/27). This number is rounded up, so that any single item in a chest produces an output power of 1. – MrLemon Aug 21 '15 at 15:47
  • @MrLemon I guess it is like a remote comparator then. It needs to do the same thing just from further away – Chickenator Aug 21 '15 at 15:47
5

You can use

/testforblock x y z minecraft:chest -1 {Items:[{}]}

Note the extra {} in the Items list. {Items:[{}]} checks if the list of item tags contains an item that matches all the tags present in {}. Obviously, {} does not contain any tags, meaning every item in the game matches this1.

You can achieve the opposite behavior using {Items:[]}, which will test for an empty list of items.

1 Technically, everything matches {}, including Creepers, but the Items tag limits the scope for us.

  • 1
    For once, Minecraft commands behave exactly like I thought they would. – MrLemon Aug 21 '15 at 15:59
  • Thanks! I needed this to create a mailbox type system on the server. This works perfectly! – Chickenator Aug 21 '15 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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