Redstone Comparator

A redstone comparator is a block used in redstone circuits to maintain, compare, or subtract signal strength, or to measure certain block states (primarily the fullness of containers).

Obtaining
A redstone comparator can be crafted from stone, redstone torches, and nether quartz.

Usage
A redstone comparator can be placed on the top of any opaque block with a solid full-height top surface (including upside-down slabs and upside-down stairs), as well as on hoppers. To place a redstone comparator, right-click on the top of a block with the redstone comparator selected in the hotbar.

The redstone comparator has a front and a back — the arrow on the top of the comparator points to the front. When placed, the comparator will face away from the player. The comparator has two miniature redstone torches at the back and one at the front. The back torches turn on when the comparator's output is greater than zero (the arrow on top also turns red). The front torch has two states which can be toggled by right-clicking the comparator: lowered and unpowered (indicating the comparator is in "comparison mode"), and elevated and powered (indicating the comparator is in "subtraction mode").

The redstone comparator can take a signal strength input from its rear as well as from both sides. Side inputs are only accepted from redstone dust, redstone repeaters, and other comparators (side inputs such as redstone torches, powered blocks, powered levers, etc. are ignored). The redstone comparator's front is its output.

It takes one redstone tick (two game ticks) for signals to move through a redstone comparator, either from the rear or from the sides. This applies to changing signal strengths as well as simply to turning on and off. Redstone comparators usually will not respond to 1- tick fluctuations of power or signal strength.

If the block underneath a redstone comparator is moved or destroyed, or if the comparator is moved by a piston, the comparator will be destroyed (dropping itself as an item).

The redstone comparator has four functions: maintain signal strength, compare signal strength, subtract signal strength, and measure certain block states (primarily the fullness of containers).

Maintain signal strength
A redstone comparator with no powered side inputs will simply output the same signal strength as its rear input.

Compare signal strength
A redstone comparator in comparison mode (front torch lowered and unpowered) will compare its rear input to its two side inputs. If either side input is greater than the rear input, the comparator output turns off. If neither side input is greater than the rear input, the comparator simply outputs the same signal strength as its rear input.

Subtract signal strength
A redstone comparator in subtraction mode (front torch elevated and powered) will subtract the signal strength of the highest side input from the signal strength of the rear input (minimum 0 signal strength).

For example, if the rear input signal strength is 7, the left side is 2, and the right side is 4, then the output will be a signal strength of 3 (7 minus the greater of 2 and 4 = 7 - 4 = 3).

Measure block state
A redstone comparator will treat certain blocks behind it as power sources and output a signal strength proportional to the block's state. The comparator may be separated from the measured block by a solid block, but if the solid block is powered then its signal strength will override the signal strength of the measured block (whether greater or lesser).

Containers
A redstone comparator used to measure the state of a container outputs a signal strength in proportion to how full the container is (0 for empty, 15 for full, etc.).

Containers which can be measured by a comparator include:
 * (or double chest)
 * (only when on top of a detector rail)
 * (only when on top of a detector rail)
 * (or trapped double chest)
 * (only when on top of a detector rail)
 * (only when on top of a detector rail)
 * (or trapped double chest)
 * (only when on top of a detector rail)
 * (or trapped double chest)

When a comparator measures a double chest or trapped double chest, it measures the entire double chest (54 slots), not just the half directly behind the comparator.

The Minimum Items for Container Signal Strength table (right) shows the minimum number of 64-stackable items required to produce specific signal strengths from various containers. A number followed by an "s" indicates the number of full item stacks required (not displayed if a full stack is not required), and a number followed by an "i" indicates the number of additional items required (not displayed if no items are required beyond some number of item stacks). For items which stack up to a maximum of 16 (snowballs, signs, ender pearls, etc.), divide the "i" number by 4 and round up. For non-stackable items, count any "i" number as one additional item.

For example, to produce a signal strength of 10 from a hopper requires a minimum of 3 full stacks plus 14 more items (or 4 16-stackable items).


 * Calculating signal strength from items


 * When a container is empty, the output is off.


 * When it is not empty, the output signal strength is calculated as follows:






 * Example: 300 blocks in a dispenser (which has 9 slots), where each block stacks to a maximum of 64, produces output with a signal strength of 8:

1 + ((300 items / 64 items per slot) / 9 slots) * 14 = 8.292, truncated is 8


 * Note that a non-stackable item is counted as a full slot (1 item in a slot, with a max stack size of 1: 1 / 1 = 1.0), and items which stack up to 16 (such as ender pearls and snowballs and eggs) are similarly considered a full slot at 16.


 * Calculating items from signal strength


 * It can be useful in redstone circuits to use containers with comparators to create signals of a specific strength. The number of items required in a container to produce a signal of desired strength is calculated as follows:




 * Example: To use a furnace (which has 3 slots) to create a strength 9 signal, you need 110 items:

max(9, (3*64/14)*(9-1)) = 109.714, rounded up is 110

Miscellaneous
Some non-container blocks can also be measured by a redstone comparator:




 * A cauldron outputs different signal strengths depending on how much water is inside. From completely empty to completely full, the output values are 0, 1, 2, and 3.




 * A command block outputs a property called "Success Count", which represents the number of times the most recently used command of this command block succeeded. A "success" is defined by the command's success conditions: if a red error message is returned in the chat, the command was not successful.


 * Most commands can only succeed once per execution, but certain commands (such as those which accept players as arguments) can succeed multiple times, and the comparator will output the number of times it succeeded (of course, this is capped at a full signal of 15, so it will output 15 if there were 15 or more successes). Examples of such commands are and . Note that  will never output more than 1, as the command only outputs one message in chat regardless of the number of players who are referenced (their names are merely formatted as a list of the form "name1, name2, and name3").


 * Note that the comparator will output the Command Block's success count for the last command executed: it will be a constant signal (or lack thereof) and will only update when the command is next executed. Unfortunately many commands fail to pass on a failure, meaning once the redstone comparator is lit it will be permanently lit. The command can be used to reset such a "problem circuit".




 * An End Portal Frame outputs a full signal of 15 if it contains an Eye of Ender and zero otherwise.




 * A jukebox outputs a signal strength which indicates which record is currently playing. For which records produce which signal strengths, see the Minimum Items for Container Signal Strength table above.

Future
A comparator can measure the state of an item frame's contents. In order for a comparator to measure an item frame's contents, it must be placed behind the block the item frame is attached to, facing away from the item frame. An item frame comparator will output 0 if the item frame is empty, or 1 to 8 for any item depending on its rotation (1 at initial placement, plus 1 for each right-click rotation to a maximum of 8, then wrapping back to 1).

Trivia

 * The comparator does not re-strengthen a redstone signal. This means it can not be used for super-long instant circuits.
 * If placed every second block between redstone, they can endlessly carry a signal, at same speed than repeaters on first setting, without it losing power strength. Placing a non-transparent block at every corner allows it to bend without losing power. It is also possible to reduce the needed amount of comparators further (and thus improve the signal speed) by facing the comparators into solid blocks behind which redstone is placed
 * A redstone comparator can output signal through an opaque block, like a repeater.
 * If you join up the redstone torches, an arrow is created which points to the redstone output. This arrow can also be seen as a red triangle on the Comparator, if one looks hard enough.
 * If placed on a Barrier, you can see the bottoms of the torches.
 * An empty Minecart, an empty Minecart with Chest and a Minecart with a mob in it will all give no redstone output when passing over a Detector Rail with a comparator next to it.

Gallery
Redstone-Komparator Comparador de redstone Redstone (comparateur) Vöröskő-összehasonlító Comparatore di pietrarossa Komparator Компаратор 红石比较器