TransWikia.com

How can I test for a chest with items?

Arqade Asked by Cronut on November 15, 2020

I am trying to test for a coal block in slot 1 of a chest.

Here is a command that I tried:

/testforblock -673 57 -195 chest 2 {Items:[{id:"minecraft:coal_block",Damage:0s,Slot:1b,Count:1b}]}

However, this command returns an error: Syntax error: Unexpected "{": at "1 chest 2>>{<<Items:[{id

One Answer

NBT

You cannot read tile data or NBT data besides for basic damage values (i.e. prismarine:0 = Rough Prismarine, prismarine:1 = Dark Prismarine)

(See this post, if anyone hasn't seen this enough.)

Different Approach

From what I can see you are looking for 1 coal block in slot 1. Make a chest with a coal block in slot 1 and then use the testforblocks command, as this command allows to compare more data (i.e. items in droppers, chests etc.).

/testforblocks <Sx> <Sy> <Sz> <Sz> <Sy> <Sz> <Dx> <Dy> <Dz>

Command Broken Down

  • <Sx> <Sy> <Sz> = Source X, Source Y, Source Z - In this case the block the coal chest is in, this is our first corner of the testforblocks region
  • <Sx> <Sy> <Sz> = Source X, Source Y, Source Z - In this case the same block position we used before. This would be the second corner as this command's intent was to compare a set of blocks with 2 corners, but we will only be comparing one block for this instance
  • <Dx> <Dy> <Dz> = Destination X, Destination Y, Destination Z - Our destination spot. This will be the other spot that will be compared with our last set of coordinates. Notice there is only one corner specified here, this should always be the negative-most corner as whenever one corner is specified in Minecraft commands it always goes the positive direction. In this case you put the chest that would be normally empty, which you want to see if has a coal block in it.

Notes

  • Don't forget hoppers exist! This could be an easier approach for certain circumstances.
  • Remember the chests have to be EXACTLY the same. This means if you have a glass pane in slot 27, both chests have to have this same glass pane in the same spot.

This should work, please tell me if it doesn't.

Answered by Penguin on November 15, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP