Terraria logic gates: how the lamps and wiring map to real gates
Terraria has six logic gate items, AND, NAND, OR, NOR, XOR and XNOR, which arrived in version 1.3.1 on desktop and are sold, with Logic Gate Lamps, by the Steampunker for 2 gold each. According to the Terraria Wiki, a gate's input is the stack of Logic Gate Lamps placed on top of it (more than two are allowed), each lamp's state is toggled by wire, and "whenever a logic gate is turned on or off it emits a signal" along its wire. A faulty lamp on top turns the gate blue and makes it pick one of the lamps below at random. The gates are real logic in a game, with a few twists worth knowing before you wire anything big.
What the gates do in Terraria
Per the wiki: AND turns on when all lamps are active, NAND unless all are active, OR when at least one is active, NOR when none is, XOR when exactly one is, and XNOR when the number of active lamps is not one. A lamp placed already on inverts its input, since every signal flips it. With timers, sensors and wires of four colors that build independent, overlapping circuits, that is enough for doors, traps and contraptions that react to the world. (digiwleea is an independent project, not affiliated with Re-Logic.)
How Terraria's gates differ from real ones
Three differences matter. First, in a chip a wire holds a level, 0 or 1, for as long as it is driven, and an output simply is a level; in Terraria the lamps hold the state, and a gate sends a signal along its wire each time its own state changes, so what it drives is toggled rather than set. Second, for two inputs Terraria's XOR and XNOR match the real gates, but with three or more lamps they do not: a real XOR (and a chain of XOR gates, as on the Minecraft Wiki) is on when an odd number of inputs are on, while Terraria's XOR is on only when exactly one is (see the table below). Third, the faulty lamp's randomness has no counterpart in ordinary logic. To see the real gates, every one of them is live on this site, built from transistors, and from there the course builds adders, memory and an 8-bit CPU.
| Terraria | digiwleea | |
|---|---|---|
| Inputs | Logic Gate Lamps stacked on the gate | Wires carrying 0 or 1 |
| Output | A signal sent when the gate's state changes | A level that follows the inputs |
| XOR, 3 inputs | On when exactly one lamp is on | On when an odd number are on |
| Randomness | Faulty lamps pick a lamp at random | None: logic is deterministic |
XOR and XNOR with three inputs
| Inputs on | Terraria XOR | Real XOR (odd parity) | Terraria XNOR | Real XNOR |
|---|---|---|---|---|
| 0 | off | 0 | on | 1 |
| 1 | on | 1 | off | 0 |
| 2 | off | 0 | on | 1 |
| 3 | off | 1 | on | 0 |
They agree except when all three are on. The real behavior is what a parity generator computes. Try each two-input gate live: AND, OR, NAND, NOR, XOR and XNOR, or see how Minecraft builds the same gates in redstone.
No sign-up is needed to start: open the lab and place your first transistor, or read the free theory course. The account (and the AI tutor) are optional.
See for yourself: build a logic gate from transistors in the simulator, then follow the path from sand to an 8-bit CPU.
Open the digiwleea lab →Frequently asked
How do logic gates work in Terraria?
Place Logic Gate Lamps on top of a Logic Gate. Wire signals toggle the lamps on and off, the gate turns on or off according to its type and the lamps' states, and each time the gate changes state it sends a signal along its wire.
Where do you get logic gates in Terraria?
The Steampunker sells the logic gates and Logic Gate Lamps, for 2 gold each, according to the Terraria Wiki.
Is Terraria's XOR gate the same as a real XOR?
For two lamps, yes. With three or more, Terraria's XOR is on only when exactly one lamp is on, while a real XOR is on when an odd number of inputs are on, so they differ when three are on.
What is a faulty logic gate lamp?
A lamp that, placed above a gate, turns it blue and overrides its normal behavior: when signalled it picks one of the lamps below at random and the gate signals if that lamp is on, which gives random outputs.