Traffic Lights - MisterJulsen/TrafficCraft GitHub Wiki
This section is all about Traffic Lights. You will learn how to set them up, get an overview about all the features and get some examples with a step by step tutorial so you can try it out in your own world. This page will of course not cover every possibility, but it should give a general overview on how to use Traffic Lights.
Blocks and Items
Traffic Light
If you want to use Traffic Lights or want to build a traffic light system (e.g. for road crossings) this is the main block you need. If you place down the block, it does nothing by default.
Traffic Light Controller
This block can be used to control multiple traffic lights of a traffic light system. Of course you can assign each traffic light its own schedule. However, it will be difficult to synchronize all the traffic lights correctly so that the entire system works properly. That's exactly what the controller block is designed for.
It is, so to speak, the central control unit of your system and controls all the linked traffic lights in the way you specified in the schedule. In addition, you can use redstone or traffic light request buttons to start and stop the execution of the traffic light schedule. In complex traffic light systems, where players have many options for influence using buttons and switches, multiple controller blocks can also be connected to each other with Redstone, as each controller block outputs a signal via a comparator when the schedule is executed.
Traffic Light Linker
This item is very important and can be used to link your traffic lights and traffic light request buttons to one or more traffic light controller(s). There are two modes which can be toggled with Shift + Scroll
.
- Link Mode: Create new links between different traffic light components.
- Unlink Mode: Remove existing links.
Before you can link your blocks you have to select a source block. The source block is the block which controls your traffic light system. Valid source blocks are:
- Traffic Light Controller
- Traffic Light
The selected source block is shown in the item's tooltip by name and coordinates.
After you selected a source block, click on any other target block you want to link with your source. For this the target block has to be in the same dimension as the source and the source must be loaded! Valid traget blocks are:
- Traffic Light (only if the source is the Traffic Light Controller)
- Traffic Light Request Button
[!CAUTION] To link traffic lights to a Traffic Light Controller you first have to select the controller as a source before clicking on your traffic lights. If your source is a traffic light you cannot link it to a controller!
If you want to clear your selected source, simply use Shift + Right Click
.
Traffic Light Request Button
If this block is linked to a traffic light with a custom schedule or to a traffic light controller and the mode is set to On Request
, then pressing this button will trigger the traffic light schedule.
This button is for players to manually trigger a traffic light, for example at pedestrian crossings where the traffic lights should not permanently block traffic (only if needed). If this block is not linked (correctly), it does nothing.
[!TIP] It is recommended to turn off the
loop
option in the schedule when using traffic light request buttons, as they cannot be used until the schedule has finished execution.
Customization
When placing down a traffic light you will notice that it is turned off by default and doesn't do anything. To bring it to life you first have to change some options.
Click on your traffic light with a wrench to open the config screen. The config screen is separated into two sections. On the top part you can customize your traffic light's appearance while on the bottom part you can change its behaviour.
Customize the appearance of your traffic light
To customize your traffic light select a part of it in the preview on the left side. When clicking on the whole traffic light you get options to change the type, the amount of lights and the icon. Currently there are the following traffic light types:
- Vehicular: Classic traffic light known from road crossings, that are mainly being used by cars or pedestrians.
- Tram: This type of traffic lights is used by public transportation services.
If you click on one of the signals you can change the colors it can display. By default the top signal shows red, the second yellow and the bottom one green. But you can change it as you like, for example you can change it that every signal shows red.
Change the behaviour of your traffic light
There are three different control types.
- Static: This mode will only show one ore more selected colors which cannot be changed. The traffic light will only show the signal colors you selected.
- Own Schedule: When this mode is selected you can create a traffic light schedule which only applies to the traffic light you are currently editing. This option is only recommended if you use one traffic light. If you use more traffic lights that should work together it is recommended to use a Traffic Light Controller.
- Remote: If this option is selected, the traffic light can be controlled by a Traffic Light Controller. The phase ID is very important in the traffic light schedule.
[!WARNING] Traffic lights can only be controlled by a Traffic Light Controller when the remote mode is selected.
Redstone output
The status of the traffic lights and the Traffic Light Controller block can be read using a Redstone Comparator.
- The Traffic Light Controller emits a Redstone signal of 0 blocks when it is deactivated and 15 when it is active (regardless of which traffic lights are controlled).
- Traffic lights emit a Redstone signal depending on the active signals (Red/Yellow/Green). The Redstone signal strength is as follows:
Active Signals | Redstone Strength (in blocks) |
---|---|
Off | 0 |
Red | 8 |
Yellow | 4 |
Green | 2 |
Red/Yellow | 12 |
Red/Green | 10 |
Yellow/Green | 6 |
All | 14 |
How to set up a Traffic Light Schedule
If you want to create a working traffic light system, for example for your road crossings, then you have to create a traffic light schedule.
[!TIP] If you want to use more than one traffic light in your system, it is recommended using a Traffic Light Controller.
In this section we assume that you are using a Traffic Light Controller that is linked to all your Traffic Lights. The creation of the schedule is always the same.
At first open the config screen by using a wrench. The you will find two buttons. One to edit the schedule, two others for copy/paste and one which can be used to manually turn your schedule on and off.
The schedule editor
On the top you will see two buttons. The left one can be used to set the trigger source which starts the traffic light schedule. By default it says None
. The following options are possible:
- None: The schedule is executed when the status is set to
ON
and cannot be influenced (e.g. by redstone or the traffic light request button) - On Request: The schedule will start when a player presses a Traffic Light Request Button that is linked to this block.
- Redstone: The schedule will be executed as long as there is a redstone signal. When there is no redstone signal the execution will be terminated.
The right button should be self-explanatory and determines whether the schedule is executed in a loop or not.
[!TIP] It is recommended to turn off the loop if you use the
On Request
mode as the schedule will never finish otherwise. Players won't be able to use Traffic Light request Buttons as long as the schedule is being executed.
"Programming" your traffic light
Don't worry, it sounds scarier than it is. If you look in the center of your screen you will find an empty space with two entries in it: Start
and End
.
You can compare a traffic light schedule to a list of events that are processed from top (Start
) to bottom (End
) in the specified order.
To add a new entry, press the +
button at the bottom of the screen.
Now you have something like this:
Two new entries have been added, which belongs together. One to define a delay, another to select a color and an empty ID input box.
A schedule with multiple entries will be executed as follows:
- Start
- Wait X seconds
- Set the selected colors on all linked traffic lights with ID Y
- Wait another X seconds
- Set the selected colors on all linked traffic lights with ID Z
- ...
- End
Example
Let's assume you set the delay to 3 seconds
, select the red
color, and set the phase ID
to 1
.
The schedule will start at the first entry on the top. Then it will await the defined delay of 3 seconds, as this entry is the next one.
Then the schedule will proceed with the next entry and sets all linked traffic lights with a Phase ID
of 1
to red
.
(If you have set the ID to 7
and the enabled colors are green
and yellow
, all traffic lights with the ID of 7
will show the colors green
and yellow
.)
[!NOTE] If you select one color (e.g. red), all other colors (e.g. yellow, green) will be turned off by default. This behaviour can be used to turn off the traffic light, as you simply have to select no color.
Examples
In this example we'll create a simple traffic light system for a basic crossing of two roads (Street A and Street B).
On every side of that crossing we place two traffic lights. Set the control type to Remote
for all traffic lights. The traffic lights on Street A will have ID 1, the traffic lights on Street B ID 2.
Now place down a traffic light controller and link it with all traffic lights. Therefore you first have to right-click
the controller and then click on all traffic lights you want to link with it (in this case 8 traffic lights).
For the next part we want to have the following states and timings for our traffic lights:
- Red (10 sec)
- Red/Yellow (2 Sec)
- Green (8 Sec)
- Yellow (3 Sec)
Edit the schedule of the controller by right-clicking
it using a wrench. Add 10 entries to it.
Configure the schedule by following the steps below. We start by initializing all traffic lights. This means that we first set all traffic lights to red.
Entry | Delay | ID | Colors | Explanation |
---|---|---|---|---|
1 | 0s | 1 | Red | Set all traffic lights with ID 1 to red immediately after the schedule has started. |
2 | 0s | 2 | Red | Set all traffic lights with ID 2 to red immediately after the previous entry. |
3 | 10s | 1 | Red/Yellow | After waiting for 10 seconds (time for red), set all traffic lights with ID 1 to red and yellow. |
4 | 2s | 1 | Green | After another 2 seconds, set all traffic lights with ID 1 to green. |
5 | 8s | 1 | Yellow | ... |
6 | 3s | 1 | Red | ... |
7 | 3s | 2 | Red/Yellow | For safety reasons, we wait three seconds after Street A's traffic lights turn red before turning Street B's traffic lights green. |
8 | 2s | 2 | Green | Set all traffic lights with ID 2 to green after waiting for 2 seconds. |
9 | 8s | 2 | Yellow | ... |
10 | 3s | 2 | Red | ... |