Advertisements

The ramblings of Minecraft addict VladTubaka

Tag Archives: comparators

The bottom light means there are less than 14 items in the lower chest, the middle light means there are exactly 14 items in the chest, and the top light means there is something in an overflow hopper.

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).

Here’s a simple setup to show how you can count whether there are 14 cobblestone in the chest or less than 14.

With 110 sticks and 13 cobblestone, the lamp is off.

When the number of cobblestone is greater than or equal to 14, the lamp comes on.

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.

Set up the hoppers like this. The top chest is where items are deposited. The bottom chest is what is being measured.

(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.

The destination chest at the top of the image has 110 sticks so that whenever it receives 14 of something else (e.g., cobblestone) the comparator strength increases from 1 to 2.

(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.

The Redstone on the cobblestone block powers a repeater that deactivates the lower hopper.

(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.

The increased comparator signal deactivates the bottom lamp and activates the middle lamp.

This is a better view of the line that activates the middle lamp.

And again with the middle lamp.

(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.

This comparator detects whether items are in the overflow hopper.

(7) Change the output signal again

The signal from the overflow comparator simultaneously activates the top lamp and deactivates the middle lamp.

By default, the Redstone torch sitting over the top lamp is disabled by another Redstone torch that sits in front of the overflow comparator.

When items are in the overflow hopper, the first torch is disabled, allowing the second torch to activate the top lamp.

It also activates the line of Redstone dust that sits over and deactivates the torch that powers the middle lamp. Notice that the repeater is on a slab. This is important. Otherwise the torch that powers the middle lamp would also power the top 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.

Advertisements

This is a minecart-based furnace array. It uses Redstone powered automatic loading and unloading systems that I’ll show you in this post.

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.

This is one simple way to keep a minecart in place over a hopper until it is empty …

… and this is another.

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.

Here we have a detector rail next to a powered rail.

Whenever a minecart is on top of a detector rail, period (regardless of fullness), it will emit a Redstone signal to adjacent blocks, including powered rail.

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:

This setup detects when a minecart is full then uses a sticky piston to push the minecart over one block. Then another sticky piston pulls back, letting the cart drop onto another set of tracks.

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).

Here’s a sample loading setup: a chest on a hopper loading into a chest cart.

And this is my somewhat messy falling edge circuit. It will pulse only when the hopper empties after having had something in it.

This is a cleaner falling edge loader.

This is the basic Redstone for this kind of falling edge circuit (there are others). The top left (according to the picture) repeater that leads into the side of the top right repeater blocks the signal from passing through that repeater. When the input turns back off, a residual Redstone signal will pulse if the last repeater is set to three or four ticks (three in this picture).

When the input (the lever) is on, the output (the Redstone lamp) remains off).

When the lever is turned off, the Redstone lamp will pulse on for just a moment then turn back off. This pulse is long enough to power a powered rail and send a cart away.

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.

Here’s a preview of a more full featured loader.


Last post I talked about how I rapidly breed and unethically slaughter hundreds of sheep and cows using magic and computers. This post should be a little less offensive … at least once I get past the chickens.

These chickens are actually very happy. Really.

Continue reading


VMixerFiller1

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



%d bloggers like this: