A 逻辑门 is a 机械 used to provide logic to wiring setups. Input is provided using a stack of 逻辑门灯s placed on top of it. The logic gate turns on and off depending on its inputs, and emits a signal every time its state changes.
The Logic Gates, along with the Logic Gate Lamps, are purchased from the 蒸汽朋克人 for 2 each.
All gates are turned off when they are first placed. Whenever a lamp is added or removed or one of its lamps changes state, the logic gate updates according to the following rules:
- AND: Turns on when all lamps are active.
- NAND: Turns on unless all lamps are active.
- OR: Turns on when at least one lamp is active.
- NOR: Turns on when no lamp is active.
- XOR: Turns on when exactly one lamp is active.
- XNOR: Turns on when the total active lamps is not one.
Whenever a logic gate is turned on or off it emits a signal. If this signal would cause a logic gate to change its own inputs and emit two signals on the same tick, instead a puff of smoke is shown at the gate and only one signal is emitted. Note that while only one signal is emitted, the state of the logic gate itself still changes.
Placing a faulty logic gate lamp above a logic gate turns it blue, overriding its normal functionality and changing its behavior entirely. The logic gates function as a randomizer instead, and can no longer turn on or off. The gate no longer emits signals when normal logic lamps above it change state. Instead, when the faulty lamp is triggered by a signal, it randomly selects one of the logic lamps below it. If that lamp is on, the logic gate emits a signal. So, if there are three lamps below the faulty lamp, two ON and one OFF, the gate has a 2/3 chance to emit a signal when the faulty lamp is triggered.
A faulty lamp can be triggered multiple times in one tick, effectively giving the gate multiple chances to emit a signal. Multiple signals cannot be emitted on the same tick this way, however, the gate will have a chance to emit a signal for every time a faulty lamp receives a signal. For example, if you trigger a faulty gate with one out of two of its logic gate lamps on twice in the same tick, it will have an 3/4 chance of emitting a signal.
Faulty lamps continue to work if only one logic gate lamp is under it. In this case, the logic gate as a whole acts as an "if" statement, only passing a signal through if the single lamp is on. If no logic gate lamps are attached, the logic gate never sends signals when the faulty lamp is triggered. A very practical use of this is a one-way wire: when a logic gate receives a signal it does nothing, but triggering the faulty lamp above it does send a signal. The logic gate lamp under the faulty lamps needs to be on. Also, this wire can be turned off by sending a signal to the logic gate lamp. Making two of these lets the player control all four possible states of a wire: Off, on (A->B), on (A<-B), on (A<-->B).
Since gates emit a signal whenever they either turn on or off, the "inverted" versions of each gate (those with an "N" prefix) behave identically to their normal counterparts in most situations. The only difference is when the first lamp is added to a new gate. (For example, both the NAND and AND gates start off when first placed. However, upon adding an off gate, the AND gate would stay off and emit no signal while the NAND gate would turn on, thus emitting a signal.)
A set/reset flip-flop is a device that has two inputs, and can be switched between the two. However, multiple activations on the same input will not change the state. It will output a pulse when the state changes. In the illustration, red and blue are the inputs, and green is the output.
- NOT gates are not in the game as they would simply emit a signal every time an input changes due to how logic gates work in Terraria. A NOT gate can be created with a NAND gate and wiring both inputs together.
- Multiple faulty lamps can be attached to a single logic gate, all of which will cause the gate to output a signal. However, only logic gate lamps below the lowest faulty lamp in the chain affect the chance of the logic gate emitting a signal. Any above it are ignored.
- 1.3.2：Fixed XNOR being named NXOR.