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.
Last post I talked about two simple Redstone devices that you can use to automatically load and unload minecarts if you want to use minecarts as an item transferral system. I briefly mentioned some of the limitations of the falling edge circuit as a loading system. In short, a simple falling edge circuit just isn’t smart enough to provide the versatility you might need if, say, you want to just dump a whole bunch of stuff into a chest and let the minecart system figure out how to get all those items from point A to point B. Today, I want to show you a more advanced loading and transferral system that works really well, never gets clogged, and actually gets a little faster and more efficient the more items you load into it.
Direction Affects Redstone
Exactly how you set up a system like this is going to depend on which direction your building it, because T-intersections with Minecraft’s rails work differently depending on which axis the straight track is on. If the straight track is going east-west (along the X axis), then an unpowered intersection from the north or south will curve to the east (which is positive X), while powering that intersection with Redstone will make it curve to the west (negative X). If the straight track is going north-south (along the Z axis), then an unpowered intersection from the east or west will curve to the south (positive Z), and a powered intersection will curve to the north (negative Z). All this means is that the Redstone might look a little different depending which direction everything is facing.
So the first thing I dislike about the simple falling edge loading system I showed last week is how slow it is. The problem is that it is bottlenecked by going through a single hopper.
Now, if you are loading items directly into the hopper and if it is loading items into a hopper cart, then items will flow out at a pretty good clip. But unless you are putting items directly into the loading hopper via the GUI (right-clicking to see the slots), you don’t want to use a hopper cart because items will flow through the hopper from another inventory too quickly for the comparator to register their presence, meaning the falling edge circuit won’t work, period.
The loading speed can be doubled by using a double chest, two hoppers, and a hopper cart. One hopper points into the hopper cart while the other hopper points into the first hopper. This not only unloads the chest twice as quickly, it loads the hopper cart (but not a chest cart) just as quickly as it can empty the chest, making for a double speed falling edge minecart loading system.
But you still have to be careful not to put more into your double chest than your hopper cart can hold. Otherwise the Redstone signal from the comparator will never turn off allowing the falling edge circuit to pulse and send the minecart away. So you are limited to putting in only five stacks of items (or five different kinds of items) at a time. This kind of loader also doesn’t deal with a single item very well (you need to make sure that comparator sits behind the hopper that is either to the south or to the east, because a single item will go south or east, given an option). It works great if you place five or fewer stacks of items into the chest, but it isn’t smart enough to handle other kinds of situations.
If we want a more intelligent loader that can manage an indefinite number of items, we have to do something different. I have built a system that works really well, but it certainly isn’t the only solution, and it most likely isn’t the most elegant solution. But it works and it was fun to build. So there.
(1) A Double Chest Evenly Distributes Items Among Six Hoppers
The first task is getting items out of the deposit chest and into a hopper cart as quickly as possible. As we saw above, double chest over two hoppers will empty at double speed. I have those two hoppers send items out into two 3-long hoppers chains going in opposite directions (to create a line of six hoppers). Using a little Redstone trick I’ve seen in a number of really impressive furnace arrays on YouTube recently, those items get distributed evenly amongst six other hoppers where they await pickup from a hopper cart.
Remember that the comparator that triggers the drop of items into the lower level of hoppers needs to be next to the hopper that is farthest to the east or the south (positive X or Z).
(2) The Hopper Cart is Released and Begins a Loading Circuit
As soon as there is an item in the south or east-most hopper on the lower level, another comparator sends out a Redstone signal that both releases the delivery hopper cart and closes a loop of rail to keep the cart loading until either it is full or everything from the chest has been picked up by the minecart.
(3) When the Cart Returns It Checks to See if There is Anything Left to Pick Up
The presence of items in the east or south-most hopper not only initiates the minecart’s collection circuit, it acts as a check for a minecart that is returning from its destination after having dropped off its load. Here I use a dropping one-way entry to make sure the cart goes in only one direction. The cart drops from a track two blocks above to land on its starting point.
I don’t pretend that this is the most compact or most elegant way to do any of this. Actually, making it a little bigger than it needed to be helps make all the parts of this intelligent loading system more obvious. What I like about this system is that it is self-resetting, it works with any number of items deposited into it, it cannot be clogged up by too many items, and it only works so long as items need to be sent. Systems designed to have minecarts constantly moving not only hog server resources but also are subject to failure whenever the game shuts down.
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.
I’ve been doing some experimenting with horizontal dropper chains recently. Vertical dropper chains used as an item elevator are commonplace. The idea behind the vertical dropper chain is to use a comparator clock to send repeated redstone signals to a column of redstone torches adjacent to the dropper chain so long as there are items in the bottom dropper.
However, so far I haven’t seen that horizontal dropper chains are as commonly used as vertical ones, which seems to me to be a shame, since droppers are super cheap to make and a chain of droppers can transport items very quickly. Furthermore, they can be combined with well-known vanilla sorting mechanics (using hoppers) to make sophisticated item sorting systems without the need for mods. In this post, I’m going to showcase some different styles of horizontal dropper chains and a couple of examples of sorting systems built on horizontal dropper chains. Continue reading
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