-
Notifications
You must be signed in to change notification settings - Fork 8
Advanced Circuits Basic Guide
Welcome to the Advanced Circuits plugin guide. This plugin was created for TShock using the TShockAPI and the TerrariaServerAPI. This guide will demonstrate the fundamental concepts in realizing circuitry more advanced than the current Terraria standard and will pass on the basic concepts of the plugin along with usage examples.
In Vanilla Terraria all objects that can be wired together and that are useful in circuits must have wires and other components wired directly to them. To toggle a timer one must place a wire directly on said timer and connect this timer directly to a switch. In other words, wires must directly touch circuit components.
In Advanced Circuits, this is not the case. Advanced Circuits introduces the concept of the "Port". A Port is one of the four adjacent tiles near your circuit component. These tiles are the tiles in the four cardinal directions directly next to your component tile. If any of these ports receive a signal, they will forward this signal to the component.
![Ports Picture](img/ports demo.png)
Circuitry components act on signals. A signal can either be a 0 or 1. Think of it as "toggle on" and "toggle off". Some components can give off both signals, and some can only give off one. Components can accept one, both, or none of the signals for use.
A switch or lever can give off both signals, depending on its state. All pressure plates send the 1 signal, except for red pressure plates. Red pressure plates will always send a 0 signal.
These to signals can cause different things to happen. For example, a door will open when it receives a 1 signal, and then close when it receives a 0 signal. So, placing any non-red pressure plate on one side, and then a red one on another can create a one-way door, wiring-wise.
A Component is any object or tile that can be connected to a circuit and provide a use or function within that circuit. A component can be wired directly (like a torch) or via port (like a timer). Examples of components are statues, switches, or torches. There is a special subclass of components called Port Defining Components. These components are the only ones to define ports and thus be able to accept input through input ports and provide output. Examples of Port Defining Components are switches, levers, and logic gates.
Switches and levers are some of the most important components. You might think "How can these things benefit me if I have to be there flipping them on and off when I need to?" Well, you really don't need to do that with Advanced Circuits! The beauty of these components is that they will switch states upon receiving a signal.
Since AC 1.1, switches and levers may now forward signals. These signals, by default, will only be sent forward if they actually changed the lever or switch's state. This restriction may be bypassed with the placement of one modifier block. (Modifiers explained in Advanced Concepts.)
![Switch Toggle Demo](img/switch toggle demo.png)
Before we get into logic gates, you must know about the input filter. The input filter is a glass block. When placed on a component's port, it will turn that port into an input port. Input ports may only receive input signals, that is signals coming from another component. A signal sent by the component with the input port will never go through the input port.
Which brings us to logic gates. Advanced Circuits introduces, using the Ports concept, logic gates. Logic gates take in input, perform a basic calculation or check, and then give an output signal. The logic gates in Advanced Circuits are the NOT gate, the AND gate, the OR gate, and the XOR gate. Input to logic gates is offered via an input port. Logic gates are the only components that require input ports to function. Logic gates must be initialized before use, via simply using them. The first input you send will do nothing, but it will then be initialized, if constructed correctly. Logic gates work with one to three input ports.
The NOT gate is the most basic logic gate. The NOT gate takes the form of an obsidian block. It will perform the basic action of sending the opposite signal than it has received. To simplify this, imagine a NOT gate with one input port and one output port in use. When the input port receives a 1 signal, the output port will send a 0 signal. Keep in mind that all input ports will affect all output ports. Meaning that if you send a 1 signal into one input port, all three other output ports will send a 0 signal.
![NOT Gate Pic](img/not gate demo.png)
A NOT gate can be placed on another port defining component's output ports to automatically invert that port's output. This useful technique can be used to preserve space whilst combining two logic gates at once.
The AND gate takes the form of silver ore. The AND gate requires all of its input ports to be in the 1 state before it will output a 1.
![AND Gate Pic](img/and gate demo.png)
The OR gate takes the form of copper ore. The OR gate will output 1 through all output ports upon receiving a 1 signal in any input port. Inversely, the OR gate will output 0 when receiving a 0 signal in all of its ports.
![OR Gate Pic](img/or gate demo.png)
The XOR gate takes the form of gold ore. The XOR gate is slightly different than the OR gate. The XOR gate will only output 1 through all output ports when the input ports are not all matching. To clarify, a XOR gate will not send output if it receives 1 signal in all three input ports. However, it will send output if one of those input ports switches to 0.
![XOR Gate Pic](img/xor gate demo.png)
The Swapper takes the form of iron ore. The swapper does nothing when receiving a 0 signal. However, it will output a signal and then swap its output when it receives a 1 signal. In other words, when you first place a swapper and send it a 1 signal, the swapper will send a 0. When you send it a 1 signal again, the swapper will send a 1. When you send it another 1 signal, the swapper will send a 0. This continues on.
![Swapper Pic](img/swapper demo.png)
The cross-over bridge takes the form of the spike block. What this component does is simply allow for wire crossings. In other words, any input from the left will be output to the right, and any input from the top will be output to the bottom. And vice versa. Input ports are not required.
A cross-over bridge may have input ports designated for it. This would allow signal to only flow through the bridge in one direction. This effect mimics a diode. A diode only allows current to flow through it in one direction and are used in many applications such as monitor screens and to convert alternating current to direct current.
![Crossover Bridge Pic](img/crossover bridge demo.png)
Timers can be used within an advanced circuit just as they may be used in a vanilla one. Timers will activate upon receipt of a 1 signal. They will then send 1 signals at every interval that the timer is designed for. The timer will deactivate upon receipt of a 0 signal. Timers are Port Defining and may operate via ports and input ports.
The Grandfather Clock is a special component. The clock is Port Defining and defines ports all around itself. The clock will send a 1 signal at night and a 0 signal in the day, upon transition from one to the other. Example usage may be to automatically activate and deactivate city or home lighting upon day-night cycle change.
Statues may be integrated very well into circuitry. Statues may be configured within the Advanced Circuits configuration options to spawn or move certain NPCS. Statues with no vanilla function may be given an Advanced Circuits function. Statues can be given one of three functions: Move NPC, Spawn NPC, or Spawn Item. The type of NPC to move or spawn may be specified. The type of item to spawn may be specified.
Dart Traps are also configurable within the Advanced Circuits config. They may have their projectile type, projectile damage, projectile speed, their own fire rate, and even the projectile offset.
Boulders may be triggered to roll with a 1 signal. They will always roll left unless that pathway is blocked. In that case they will roll right. They will not work in Vanilla Circuits.
Signs will state their content to the player that triggered the circuit if they receive a 1 signal. They will not work in Vanilla Circuits.