Several months ago, I came across a thread on minecraftforum.net where a player was trying to design a system that would detect if there were 14 and exactly 14 items in an inventory. In other words, he wanted one output or signal if the inventory had less than 14, a different signal if it had exactly 14, and yet another signal if it had more than 14. It is this three signal aspect that made the problem a tricky one to solve.
Now, if you know anything about comparators, detecting if there are 14 items in an inventory is not all that difficult. A comparator increases in strength as the inventory it is connected to increases in fullness. It will output a Redstone signal of power 1 as soon as anything enters the inventory, and this signal will increase in strength up to a full 15 when the inventory is full. Precisely what points it increases depends on the inventory and on the kind of items that are being placed therein. If your inventory is a chest and the items that are being placed in the chest are normal items that stack in groups of 64 (cobblestone, sticks, sand, rotten flesh, etc.), the comparator will output a signal strength of 1 up until the chest has 123 items. At the point that it receives its 124th item, the comparator signal will increase to 2.
So how do you detect only 14 items? Well, you use a filler item that is different from the item you want to count, such as sticks, to bring the standing total to 110 (= 124-14).
But this only really detects one of two conditions (i.e., a 0 or a 1), either <14 and >=14, or <=14 and >14. In other words, with just a comparator you can get the signal to change either when the total reaches 14 or when it goes over 14. But the original forum question was about a system that will essentially do both, with a separate signal for each condition <14, == 14, and >14.
This is possible, but the Redstone becomes a lot more complicated. Moreover, you cannot simply measure a single inventory. You must measure the main inventory (a chest, in my examples) and an overflow inventory (a hopper). Moreover, items must be entering the main inventory via hoppers. With these caveats, it is definitely possible to detect all three conditions (<14, ==14, and >14) distinctly. Here’s one way to do it.
(1) Setup three hoppers, two to send items to a destination chest and one as an overflow chest
The top chest is the deposit chest, the bottom chest is the chest being measured. The top right hopper is an overflow hopper. The top left hopper needs to point into the top right overflow hopper (which is disabled by a Redstone torch above it, so it won’t send items, but it can still receive items from a hopper pointed into it). As long as items are flowing into the top left hopper one at a time (e.g., being pulled from a chest), it will release those items downward rather than to the side (hopper pull requests trump hopper push requests, I think). So until there are 14 cobblestone in the bottom chest, items will flow through into the chest through the left two hoppers. Once there are 14 cobblestone in the chest, items will be redirected into the overflow hopper by a little Redstone.
(2) Measure the fullness of a chest
This is easy, accomplished through a simple comparator. Here I have divided the Redstone signal into two tracks, each with a different purpose.
(3) Shut off the flow of items when the desired number is reached
The piece of dust on the cobblestone block powers a repeater that shuts off the flow of items to the chest once the number of cobblestone reaches 14.
(4) Change the output signal
The second piece of Redstone dust extending backward from the chest to the repeater changes the output signal once the number of cobblestone reaches 14. By default the bottom Redstone lamp is lit while the middle lamp is deactivated. When this line is powered by the increased comparator signal (from 1 to 2), that bottom lamp is deactivated and the middle lamp is activated.
(5) Redirect subsequent items into an overflow hopper
When the bottom hopper is disabled by a Redstone signal, items will now go into the overflow hopper, because though it is also disabled by a Redstone signal (so it cannot pull or push), the top left hopper (the one beneath the deposit chest) can still push items. This is why it is important for the first hopper to point to the overflow hopper.
(6) Detect the presence of items in the overflow hopper
A new comparator now detects items in the overflow hopper and sends out a new signal to change the output lamps.
(7) Change the output signal again
The signal from the overflow comparator simultaneously activates the top lamp and deactivates the middle lamp.
Some final notes
This system, as it stands, needs to be manually reset (items must be manually removed from the chest and the overflow hopper). It also has one main quirk – if you place more than 14 items in the deposit chest at one time, it still works, but a single item gets trapped in the bottom left hopper. To make this not happen, there are several things you could do. You could use some Redstone to slow down the movement of items through the left hoppers. Otherwise, you could use another hopper and a vertical dropper chain to pull excess items from the bottom left hopper automatically. Finally, you could slow down the flow of items into the system by using droppers and a comparator clock to inject items more slowly into the top left hopper rather than having that hopper pull items directly from the deposit chest. I’ll leave you to design those fixes.
Bottom line, however: this system actually works. It measures an inventory, sends out one signal if there are less than a specific number of items in the inventory, another signal if there are exactly that specific number of items in the inventory, and a third signal if there are more items (meaning, items in a separate overflow inventory). So if you absolutely have to have exactly 14 items in a chest and no more, this is how you can do it.
While many mods add item transfer mechanics into the game (pipes, tubes, conduits, conveyor belts, etc.), vanilla Minecraft actually has had item transfer systems built in for a long time in the form of minecarts. Back in the day (classic Tekkit and some time afterwards), if people used minecarts to transfer items it was pretty much only via additions provided with the Railcraft mod. With the MC 1.5 Redstone update, all of a sudden it became possible to load items into and out of minecarts automatically using hoppers and comparators. Today, I want to cover two simple Redstone devices that you can use to unload and load minecarts automatically.
Unloading Minecarts (Then Sending Them Back When Empty)
Of the two functions of minecart-based item transfer (loading and unloading the minecart), unloading the minecart is by far the easier. The way this is done is by placing a powered rail at the end of a track over a hopper. A comparator reads if anything is in the hopper and, so long as there is, depowers the powered rail over the hopper (thereby keeping the minecart still until it is empty). Once the hopper finishes transferring items from the minecart into a nearby inventory, the powered rail is once again powered, sending the minecart back where it came from.
Loading Minecarts (i.e., Waiting to Send the Minecart Until Finished Loading)
Obviously, the easiest way to load items onto minecarts is manually: right click the minecart, put the items in, then activate the powered rail it sits on and send it away.
On the other hand, automatically loading the minecart – and specifically designing your Redstone setup so that the cart is sent once it is loaded – is more complicated. Part of the reason it is more complicated is that the only way you can measure the fullness of a minecart directly is by having the minecart sitting on a detector rail and placing a comparator next to that detector rail. The comparator will then read the fullness of the minecart. Unfortunately, there is no way to cause a stationary minecart sitting on a detector rail to start moving. That is what powered rails are for, and vanilla Minecraft just doesn’t have a rail that combines those two functions.
There actually is a solution using sticky pistons, but it doesn’t seem to be 100% reliable (sometimes the rail breaks, sometimes it doesn’t). But here’s a picture:
Maybe I’ll post about this in the future once I have some idea of how reliable it is.
So what we have to do is have our minecart sitting on a “depowered” powered rail (to keep it stationary) and detect the contents of a hopper that is loading items onto the minecart with a comparator. But obviously we don’t want the rail powered as soon as items enter into the loading hopper. Instead, we want the cart to go on its merry way once items have finished passing through the hopper. This requires a special Redstone circuit called a “falling edge” circuit. A falling edge circuit sends an output pulse when an input pulse ends. So if I am using a lever as the input for a falling edge circuit, the output will pulse only when I turn the lever off after having also turned it on. And it will only pulse, not stay on, as would happen with a NOT gate (i.e., a Redstone torch).
The main thing you have to make sure you don’t do is load more into the loading hopper than your minecart can hold. So, for example, if the minecart you’re using to transport items is a hopper cart versus a chest cart, you wouldn’t want to place six stacks of items into a chest above the loading hopper, since only five of those stacks will successfully load onto the hopper cart, leaving a stack of items inside the hopper. Because the input from the comparator next to the loading hopper will never turn off, the falling edge circuit will never pulse to send the minecart away.
In many situations where you have a system producing items (a reed farm, for example), this won’t be a problem. The system won’t produce at a time more items than your minecart can hold. If, on the other hand, you want to be able to dump tons of items into a chest and let the item transport system regulate itself, you’re going to need a somewhat more advanced setup. I’ll cover one such setup in next week’s post.
In my last post about my Factorization Building of Ore-Processing Awesomeness, I noted that I used Thermal Expansion Fluid Transposers to refill the water buckets that the Factorization Mixers need to do their mixing business. I did this for two reasons: 1) to save space and 2) because I’m not really a Vanilla MC Redstone stud. But something (conscience? curiosity? manic obsession with all things Minecraft?) wouldn’t let it slide. So I spent some time in my 1.6.4 modded test world and worked out a system that, if I do say so myself, is pretty sweet … if bulky. Continue reading