Handle an event with on. The events guide explains how handlers work; this page lists
every event.
Every program, on a computer or a drive, can handle these:
| Event | When it runs |
|---|
shutdown | Runs once when the program stops. |
startup | Runs once when the program starts. |
timer.every(ticks) | Runs every given number of ticks. 20 ticks is about one second. |
on timer.every(ticks) needs a whole number of ticks, at least 1. Ticks that pass while a program is paused by the
debugger are skipped.
Use a device constant: const gate = detectors.named("gate"), then on gate.entityEnter(entity) { … }. A drive
program handles its own device’s events as on device.entityEnter(entity) { … }.
| Event | When it runs |
|---|
entityEnter(entity) | Runs when an entity enters the detector's range. entity has name, type, category, hostile, player, x, y, z and distance. |
entityLeave(entity) | Runs when an entity leaves the detector's range. |
countChanged(count, previous) | Runs when the number of entities in range changes. |
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
programStarted | Runs when the device's own program starts. |
programStopped | Runs when the device's own program stops. |
programFailed(message) | Runs when the device's own program stops on an error. |
| Event | When it runs |
|---|
rainStart | Runs when it starts raining or snowing. |
rainStop | Runs when rain or snow stops. |
thunderStart | Runs when a thunderstorm starts. |
thunderStop | Runs when a thunderstorm ends. |
dayStart | Runs at sunrise. |
nightStart | Runs at nightfall. |
weatherChanged(weather, previous) | Runs when the weather changes between Weather.CLEAR, Weather.RAIN and Weather.THUNDER. |
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
programStarted | Runs when the device's own program starts. |
programStopped | Runs when the device's own program stops. |
programFailed(message) | Runs when the device's own program stops on an error. |
| Event | When it runs |
|---|
lightChanged(light, previous) | Runs when the light level above the sensor changes. |
skyLightChanged(light, previous) | Runs when the sky light above the sensor changes. |
darkened(light) | Runs when the light drops below the sensor's threshold. |
brightened(light) | Runs when the light reaches the sensor's threshold. |
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
programStarted | Runs when the device's own program starts. |
programStopped | Runs when the device's own program stops. |
programFailed(message) | Runs when the device's own program stops on an error. |
| Event | When it runs |
|---|
inputChanged(face, power, previous) | Runs when the redstone power arriving at an input face changes. face is a Direction. |
signalOn(face, power) | Runs when an input face turns on. |
signalOff(face) | Runs when an input face turns off. |
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
programStarted | Runs when the device's own program starts. |
programStopped | Runs when the device's own program stops. |
programFailed(message) | Runs when the device's own program stops on an error. |
| Event | When it runs |
|---|
contentsChanged(face) | Runs when the items in an approved inventory change. |
itemChanged(face, item, count, previous) | Runs when the total count of one item type changes, such as minecraft:iron_ingot. |
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
programStarted | Runs when the device's own program starts. |
programStopped | Runs when the device's own program stops. |
programFailed(message) | Runs when the device's own program stops on an error. |
| Event | When it runs |
|---|
activated | Runs when the alarm starts sounding. |
deactivated | Runs when the alarm is silenced. |
finished | Runs when the alarm stops after its configured duration. |
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
programStarted | Runs when the device's own program starts. |
programStopped | Runs when the device's own program stops. |
programFailed(message) | Runs when the device's own program stops on an error. |
| Event | When it runs |
|---|
accessAttempted(player) | Runs when a player uses the controller. player has name, uuid and result (Access.GRANTED or Access.DENIED). |
accessGranted(player) | Runs when a player is let in. |
accessDenied(player) | Runs when a player is refused. |
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
programStarted | Runs when the device's own program starts. |
programStopped | Runs when the device's own program stops. |
programFailed(message) | Runs when the device's own program stops on an error. |
| Event | When it runs |
|---|
buttonPressed(button) | Runs when a player presses a button. button has id (Button.ONE to Button.FOUR), number, label and player. |
buttonOne(player) | Runs when button 1 is pressed. player is the name of who pressed it. |
buttonTwo(player) | Runs when button 2 is pressed. |
buttonThree(player) | Runs when button 3 is pressed. |
buttonFour(player) | Runs when button 4 is pressed. |
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
programStarted | Runs when the device's own program starts. |
programStopped | Runs when the device's own program stops. |
programFailed(message) | Runs when the device's own program stops on an error. |
| Event | When it runs |
|---|
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
programStarted | Runs when the device's own program starts. |
programStopped | Runs when the device's own program stops. |
programFailed(message) | Runs when the device's own program stops on an error. |
These devices have only the connection events:
| Event | When it runs |
|---|
connected | Runs when the device becomes reachable, for example after its area loads. |
disconnected | Runs when the device stops being reachable: unloaded, unlinked or removed. |
The programStarted, programStopped and programFailed events belong to devices that can run drive programs. They run
when that device’s own program changes state.
A computer program can also handle these events, with a name as the filter. They come from named ports of a Network
Interface, named sides of a Redstone Controller (written "controller:side", such as "lamps:north"), older Sensors
and custom events:
| Event | When it runs |
|---|
events.custom("name", value, sender) | Runs when another program on the network sends this custom event. sender has name, kind and id. |
redstone.changed("name", strength) | Runs when a named input port, or a controller face such as "gate:north", changes. |
redstone.falling("name", strength) | Runs when a named input turns off. |
redstone.rising("name", strength) | Runs when a named input turns on. |
sensor.cleared("name", detected) | Runs when a named Sensor sees no player any more. |
sensor.detected("name", detected) | Runs when a named Sensor first sees a player. |
A drive program on a Redstone Controller can also use the older on redstone.rising("north"), redstone.falling and
redstone.changed for its own sides, and every drive program can handle events.custom.
| Rule |
Detail |
| Sampled |
Entity Detector every 10 ticks; Weather Station, Environment Sensor and Inventory Module every 20; only while listened to; at most 32 devices sampled per tick. |
| Immediate |
Redstone, Alarm, Access Controller and Control Panel events. |
| Baseline |
The first reading after a program starts sets the baseline; it raises no events. |
| Queue |
Each program queues at most 32 events. Extra events are dropped and counted. |
| Order |
One handler per program per tick, never while another handler of that program runs. |
| Reach |
Computers: loaded devices connected to the computer. Drive programs: loaded devices of the same network connected to them through loaded devices. |
| Values |
Copied for every handler. Lists, tuples and dictionaries at most 8 levels, 512 values, 16,384 characters. |