Skip to content

Creating Events

ContronThePanda edited this page Dec 15, 2019 · 1 revision

Each event is represented by a Java class. Event classes must implement the org.terasology.entitySystem.event.Event interface, or inherit from another class that does. This is what marks them as events and allows them to be sent and received. It is also standard to give events names ending in Event (e.g., ActivateEvent) for clarity.

The classes themselves may contain anything necessary for the event. Events are sent as instances of this class, and they can carry important information about what happened during the event. Alternatively, some events are self-explanatory and don't need any additional information to be handled properly. These classes can be left completely blank. Events are allowed to create variables, constructors, and methods. Methods, however, should be restricted to basic data processing, since the main purpose of events is to send information, not perform actions. Event methods can be used to perform basic things like null checks, but should not be used for anything heavy.

Consumable Events

Some events can also be canceled by "consuming" them. These events must extend the abstract class org.terasology.entitySystem.event.AbstractConsumableEvent to add this behavior. Calling the method consume on one of these events will mark it as consumed, indicating that it has been sufficiently dealt with and should not be handled any further. This can be used to prevent events from being handled under certain conditions.