Minecraft – See the items in a chest

minecraft-commandsminecraft-java-edition

I want to make a command that check how many and what type of items are in a chest and then it will give 12 end portal frames to the nearest player.
I have tried with redstone but it is too big.
The idea is that the player comes to the chest and put in some specific items in a specific order (see image below).
It will then empty the chest give the 12 end portal frames to the player.
This is for a chunk challenge map.

enter image description here

Best Answer

You can use /testforblock:

/testforblock X Y Z chest -1 <blockdata>

Is something you'll probably understand, depending on your command block experience. If you don't:

X Y Z should be replaced with the coordinates of the chest. "chest" means the command block only returns a success when it's a chest. -1 means it can be any data value, in a chest's case this means any rotation.

Now for the harder part, you should add the blockdata testing:

/testforblock X Y Z chest -1 {Items:[{Slot:*ID*,id:*ID*,Count:1}]}

The slot IDs are numbered from left to right, top to bottom, starting with 0. This means the top left is 0, top right is 8, bottom right is 26.

Item IDs can be found by pressing F3 and H at the same time (which reveals advanced tooltips) and hovering over the item in your inventory. An emerald, for example, would be "minecraft:emerald".

The count part can be anything you like, although I think you'll want it to stay at 1.

And then there's one last thing to do: add a comparator running out of the command block, into a command block that replaces the chest with an empty one, and one that gives the nearest player the frames.

To make filling in the blockdata easier, I recommend this. Just select the /blockdata command, fill in all the slots, then copy the part between curly brackets into your /testforblock command.