Example of the logic gate AND.
A Logic Gate is a mechanism used to provide logic to wiring setups. Input is provided using a stack of Logic Gate Lamps 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 Steampunker for 2 GC each.
Behavior
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:
Logic Gate |
Rule
|
Logic Gate (AND)Internal Item ID: 3603 |
Turns on when all lamps are active.
|
Logic Gate (NAND)Internal Item ID: 3605 |
Turns on unless all lamps are active.
|
Logic Gate (OR)Internal Item ID: 3604 |
Turns on when at least one lamp is active.
|
Logic Gate (NOR)Internal Item ID: 3606 |
Turns on when no lamp is active.
|
Logic Gate (XOR)Internal Item ID: 3607 |
Turns on when exactly one lamp is active.
|
Logic Gate (XNOR)Internal Item ID: 3608 |
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[1], 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.
Faulty lamps
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 the player triggers 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).
Inverted gates
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.)
Useful circuits
Toggle flip-flop (T flip-flop)
T flip-flop
A toggle flip-flop is a device with one input and changes state every other input. The device consists of a faulty logic gate lamp, a logic gate lamp, and a gate. It is particularly useful when utilizing sensors to toggle activations without having the sensor's ending pulse turn off the device.
Set/Reset flip-flop (SR flip-flop)
SR flip-flop
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 green are the inputs, and blue is the output.
Restricted storage circuit
Restricted Storage Circuit
A circuit which can store an intermediate value. It has three inputs (at the top), write, read, and input, from left to right, and one output. It also has an internal bit-state that is not accessible from outside. While read is off, the internal bit will never change; while read is on, the internal bit will copy input. Independent of that, while write is off, the output will never change; while write is on, the output will copy the internal bit. The bit is the "or" logic gate next to the junction box (hammering).
A more compact restricted storage circuit design.
Safety switch
Simple switch to turn traps on/off. Uses two logic gates: AND (3 lamps), and XOR. Switch and pressure plate connected to XOR gate to reset AND gate after each use, so the trap would be activated every time the plate is triggered as long as the switch is not active.
Notes
- 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.
- 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.
- In electronics and logic, an XOR gate with more than 2 inputs is commonly regarded as a cascade of 2-input XOR-gates, thus behaving as a parity-checker with the output being on if there is an odd number of inputs turned on. In terraria, however, an XOR-gate with multiple inputs only turns on when exactly one input is turned on.
History
- Desktop 1.3.2:
- Fixed XNOR being named NXOR.
- Added "Also often called NXOR" to XNOR's tooltip.
- ↑ A tick is a time unit countable by the software. Most of Terraria's updating logic happens every tick. A tick has the length of 1/60th of a second, hence there are 60 ticks in a second and 3600 ticks in a minute.
- Active/Inactive Stone Block
- Actuator
- Announcement Box(Desktop, Console and Mobile versions)
- Doors
- Trap Door(Desktop, Console and Mobile versions)
- Tall Gate(Desktop, Console and Mobile versions)
- Pumps
- Grate(Desktop, Console and Mobile versions)
- Teleporter
- Functional Statues
- Light sources
- Gemspark Blocks(Desktop, Console, Old-gen console and Mobile versions)
- Mini Volcano(Desktop, Console and Mobile versions)
- Large Volcano(Desktop, Console and Mobile versions)
- Pixel Box(Desktop, Console and Mobile versions)
- Junction Box(Desktop, Console and Mobile versions)
- Logic Gates(Desktop, Console and Mobile versions)
- Logic Gate Lamps(Desktop, Console and Mobile versions)
Themed(Desktop, Console, Old-gen console and Mobile versions)
- Bone Welder(Desktop, Console, Old-gen console and Mobile versions)
- Decay Chamber(Desktop, Console and Mobile versions)
- Flesh Cloning Vat(Desktop, Console, Old-gen console and Mobile versions)
- Glass Kiln(Desktop, Console, Old-gen console and Mobile versions)
- Honey Dispenser(Desktop, Console, Old-gen console and Mobile versions)
- Ice Machine(Desktop, Console, Old-gen console and Mobile versions)
- Lihzahrd Furnace(Desktop, Console, Old-gen console and Mobile versions)
- Living Loom(Desktop, Console, Old-gen console and Mobile versions)
- Sky Mill(Desktop, Console, Old-gen console and Mobile versions)
- Solidifier
- Steampunk Boiler(Desktop, Console, Old-gen console and Mobile versions)
- Ash Wood(Desktop, Console and Mobile versions)
- Bamboo(Desktop, Console and Mobile versions)
- Bone(Desktop, Console and Mobile versions)
- Boreal Wood(Desktop, Console, Old-gen console and Mobile versions)
- Cactus
- Crystal(Desktop, Console and Mobile versions)
- Dead Man's(Desktop, Console and Mobile versions)
- Dungeon
(
- Blue(Desktop, Console, Old-gen console and Mobile versions)
- Green(Desktop, Console, Old-gen console and Mobile versions)
- Pink(Desktop, Console, Old-gen console and Mobile versions)
)
- Dynasty(Desktop, Console and Mobile versions)
- Ebonwood
- Flesh(Desktop, Console and Mobile versions)
- Frozen
- Glass(Desktop, Console and Mobile versions)
- Granite(Desktop, Console and Mobile versions)
- Gold
(
- Golden(Desktop, Console and Mobile versions)
)
- Golf Chest(Desktop, Console and Mobile versions)
- Honey
- Ivy
- Lesion(Desktop, Console and Mobile versions)
- Lihzahrd
- Living Wood
- Marble(Desktop, Console and Mobile versions)
- Martian(Desktop, Console and Mobile versions)
- Mushroom
- Nebula(Desktop, Console and Mobile versions)
- Obsidian(Desktop, Console, Old-gen console and Mobile versions)
- Palm Wood(Desktop, Console and Mobile versions)
- Pearlwood
- Pumpkin(Desktop, Console and Mobile versions)
- Reef(Desktop, Console and Mobile versions)
- Rich Mahogany
- Sandstone(Desktop, Console and Mobile versions)
- Shadewood
- Shadow
- Slime
- Skyware
- Solar(Desktop, Console and Mobile versions)
- Spider(Desktop, Console and Mobile versions)
- Spooky(Desktop, Console, Old-gen console and Mobile versions)
- Stardust(Desktop, Console and Mobile versions)
- Steampunk(Desktop, Console and Mobile versions)
- Vortex(Desktop, Console and Mobile versions)
- Water
- Web Covered
Floor & Ceiling
- Pylons(Desktop, Console and Mobile versions)
- Bars
- Books
- Bottle
- Bowls
- Butterfly Jars
- Cages
- Coin Piles(Desktop, Console, Old-gen console and Mobile versions)
- Christmas Tree
- Coral
- Crates
- Crystal Shard
- Decorative Banners
- Decorative Statues
- Desert Spirit Lamp(Desktop, Console and Mobile versions)
- Dragonfly Jars(Desktop, Console and Mobile versions)
- Fairy Jars(Desktop, Console and Mobile versions)
- Fancy Dishes(Desktop, Console, Old-gen console and Mobile versions)
- Fish Bowls
- Gems
- Golf Trophies(Desktop, Console and Mobile versions)
- Hanging Pot(Desktop, Console and Mobile versions)
(
- Herbs(Desktop, Console and Mobile versions)
)
- Jellyfish Jars
- Lawn Flamingo(Desktop, Console and Mobile versions)
- Magic Droppers(Desktop, Console and Mobile versions)
- Minecart Track
- Mini Volcano(Desktop, Console and Mobile versions)
(
- Large(Desktop, Console and Mobile versions)
)
- Pin Flags(Desktop, Console and Mobile versions)
- Pin Wheel(Desktop, Console and Mobile versions)
- Plate(Desktop, Console and Mobile versions)
- Platforms
(
- Planter Box(Desktop, Console and Mobile versions)
- Team(Desktop, Console and Mobile versions)
)
- Potted Trees(Desktop, Console and Mobile versions)
- Presents
- Party Present(Desktop, Console and Mobile versions)
- Relics(Desktop, Console and Mobile versions)
- Rock Golem Head(Desktop, Console and Mobile versions)
- Seashells(Desktop, Console, Old-gen console and Mobile versions)
- Seaweed Planter
- Ship in a Bottle
- Silly Tied Balloons(Desktop, Console and Mobile versions)
- Silly Tied Bundle of Balloons(Desktop, Console and Mobile versions)
- Vases
- Animal skins(Desktop, Console, Old-gen console and Mobile versions)
- Catacomb
- Compass Rose
- Hanging Skeleton
- Holly(Desktop, Console, Old-gen console and Mobile versions)
- Life Preserver
- Living Fire Blocks(Desktop, Console, Old-gen console and Mobile versions)
- Paintings
- Racks(Desktop, Console, Old-gen console and Mobile versions)
(
- Weapon Rack(Desktop, Console, Old-gen console and Mobile versions)
- Item Frame(Desktop, Console and Mobile versions)
)
- Ropes
- Ship's Wheel
- Trophies
- Treasure Map
- Wall Anchor
- Wall Skeleton
- Wooden Beam
Functional
- Grandfather Clocks
- Sign
- Tombstone
- Target Dummy(Desktop, Console and Mobile versions)
- Ammo Box(Desktop, Console, Old-gen console and Mobile versions)
- Bewitching Table(Desktop, Console and Mobile versions)
- Crystal Ball
- Sharpening Station(Desktop, Console and Mobile versions)
- War Table(Desktop, Console and Mobile versions)
- Enemy Banners
- Sunflower
- Campfires
- Fireplace(Desktop, Console and Mobile versions)
- Clay Pot
- Enchanted Sundial(Desktop, Console and Mobile versions)
- Enchanted Moondial(Desktop, Console and Mobile versions)
- Lihzahrd Altar
- Eternia Crystal Stand(Desktop, Console and Mobile versions)
- Land Mine
- TNT Barrel(Desktop, Console and Mobile versions)
- Pigronata(Desktop, Console and Mobile versions)
- Snowball Launcher
- Cannon
- Bunny Cannon
- Confetti Cannon(Desktop, Console and Mobile versions)
- Portal Gun Station(Desktop, Console and Mobile versions)
- Boulder
(
- Bouncy(Desktop, Console and Mobile versions)
- Life Crystal(Desktop, Console and Mobile versions)
)
- Rolling Cactus(Desktop, Console and Mobile versions)
- Gem Locks(Desktop, Console and Mobile versions)
- Trapped Chests(Desktop, Console and Mobile versions)
- Arrow Signs(Desktop, Console and Mobile versions)
- Drum Set(Desktop, Console and Mobile versions)
- Golf Tee(Desktop, Console and Mobile versions)
- Weather Vane(Desktop, Console and Mobile versions)
Wiring
- Doors
- Tall Gate(Desktop, Console and Mobile versions)
- Trap Door(Desktop, Console and Mobile versions)
- Music Box(Desktop, Console, Old-gen console and Mobile versions)
- Monoliths(Desktop, Console and Mobile versions)
- Echo Chamber(Desktop, Console and Mobile versions)
- Water Fountains
- Chimney(Desktop, Console and Mobile versions)
- Bubble Machine
- Fireworks Box(Desktop, Console, Old-gen console and Mobile versions)
- Firework Fountain(Desktop, Console, Old-gen console and Mobile versions)
- Firework Rockets
- Fog Machine(Desktop, Console and Mobile versions)
- Party Center(Desktop, Console and Mobile versions)
- Silly Balloon Machine(Desktop, Console and Mobile versions)
- Functional Statues
- Lever
- Switch
- Detonator(Desktop, Console and Mobile versions)
- Pressure Plates
- Timers
- Actuator
- Wire Bulb(Desktop, Console and Mobile versions)
- Junction Box(Desktop, Console and Mobile versions)
- Explosives
- Pumps
- Teleporter
- Sensor(Desktop, Console and Mobile versions)
- Geyser(Desktop, Console and Mobile versions)
- Pixel Box(Desktop, Console and Mobile versions)