This can be done rather easily by matching part of the Items
data tag of the chest block entity in a testforblock command:
testforblock <x> <y> <z> minecraft:chest -1 {Items:[{id:minecraft:snowball,Slot:2s}]}
Replace <x> <y> <z>
with the coordinates of the chest. The -1
allows all data values of the chest (i.e. all orientations) to match.
As usual, data tag matching is partial, meaning that everything not specified is not considered by the command, such as the Count
of snowballs in the above command. I.e. any number of snowballs works, as but they need to be in the third slot from the top left, which is slot 2 because of 0-indexing. Any other items in the chest are also ignored.
You can add more item tags to the Items
tag (comma separated, between the []
) to match more items.
You can use CommandBlocks to make a VIRTUAL chest, therefore you won't have items physically in game. The princip would be :
You have input and output chests (or hoppers etc, but less slots, better....furnace has only 3 easily distinguishable slots (you input in only one by one-side hopper) - but not all things can be inserted AFAIK).
Then you need something to test if there are items in that slot, if there is expected thing, delete those things, add count to scoreboard. Then similar setup on output side.
Example:
Onetime command:
/scoreboard objectives add CobbleStorage dummy CobbleStorage
Setup:
Furnace with hopper inserting into upper slot - so there will be maximum of 64 items at once.
Commandblocks (if 1.9+, use chain ones, with "always running" as the first one (or clock for it)), replace x,y,z by real coords:
/testforblock x y z minecraft:furnace -1 {Items:[{Slot:0,id:cobblestone,Count:64}]}
--> if true (comparator or conditional chain)
/blockdata x y z {Items:[{Slot:0,id:cobblestone,Count:32}]}
-->comparator/conditional chain
/scoreboard players add <playername> CobbleStorage 32
Do notice that this setup can be done simultaneously for any number of players, if they all have their own input chest (or do it on @p basis in commands).
Then...we have stored our cobblestone in virtual manner. All you need is to do reverse technique to get it back.
For this you don't even need the storage block, you can do it on command basis. So commandblock with a button (or autocommand with /trigger so you can execute it from anywhere, even with ppl without OP)
/give @p[score_CobbleStorage_min=64,r=3] minecraft:cobblestone 64
-->Comparator/conditional chain
/scoreboard players remove @p[score_CobbleStorage_min=64,r=3] CobbleStorage 64
Resume:
You need 1 hopper (possibly not), 1 Furnace, At least 5 commandblocks. And you are limited only by the maximum of scoreboard objective, which is diametrically higher than your needs. So unlimited storage for ~10 blocks.
PS: You always can have full inventory and just delete it and add that count by a command for faster insterting....but well, one slot is SAFER for number errors.
Best Answer
You can use
Note the extra
{}
in theItems
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 theItems
tag limits the scope for us.