Hoppers in Minecraft Redstone are unique and can take some patience to get the hang of. The hopper is one of only a few ways to transport items, to automate many redstone contraptions.
An available hopper has open inventory slots, which can indicate either an empty inventory slot or not enough items within the occupied slots, which can be filled with as many as 64 of the same item per slot. When you place a Hopper on top of another Hopper, it checks to see if the Hopper underneath has empty inventory slots.
If there’s an available hopper, the item being stored within the hopper goes straight into the one beneath it.
Adding a comparator next to a hopper sends a signal (which can be used to power redstone and other redstone contraptions) depending on how many items are in the hopper. One item sends out a signal strength of 1, 23 items sends out a signal strength of 2, 46 sends out three, and so on.
You then can use this combination of hoppers, available inventory, and comparators to construct a sorting system that sorts the items from a chest of random items (such as pumpkins and apples) into their own chests, as shown.
You can see in the figure the chest of random items on the top, and the 6 chests that each individual item goes into on the bottom left.
To make this work, inside each of the second row of hoppers, put exactly 19 of the same block (such as an apple) in one inventory slot (to see the inventory of the hopper, just right-click on the hopper) and 1 of the same block in all the other inventory slots inside the hopper.
In addition to the hopper configuration, a series of repeaters is used, connected to redstone dust, followed by a row of comparators — this is what makes the items move from the chest to one hopper to another hopper, and so on, until all items are sorted.
For this to work, the bottom row of hoppers remain closed from sending items from the hoppers to the chests next to them because of the redstone torches supplying power to the hoppers. (Refer to the blocks next to them in the figure.) When that power is turned off briefly, the hopper opens, allowing a single item through to the chest next to it, and the power then turns back on.
The comparators you see on the right detect that there are more than 22 items (sending a constant signal of 2 to the comparators until the number of items is fewer than 23, changing the signal of the comparator back to 1) inside the second row of hoppers, signal to repeaters and redstone torches next to the bottom row of hoppers to turn off briefly, allowing a single item through to the chest next to them.
This process continues until the chest at the top is empty.